//! returns: 0 //! Test returning a slice from a function and iterating over it. //! Exercises the same code path as createBlock's vars initialization. //! The slice is returned through a return buffer (> 8 bytes). fn makeSlice(buf: *mut [u8], count: u32) -> *mut [u8] { if count == 0 { return &mut []; } return @sliceOf(&mut buf[0], count); } fn initSlice(buf: *mut [u8], count: u32) -> i32 { let s = makeSlice(buf, count); // This loop pattern matches createBlock's vars initialization. for i in 0..s.len { s[i] = 0; } return s.len as i32; } @default fn main() -> i32 { let mut buf: [u8; 64] = undefined; let n = initSlice(&mut buf[..], 5); assert n == 5; let n2 = initSlice(&mut buf[..], 0); assert n2 == 0; return 0; }