let data: vec![0u8; 1024];
foo(data.as_ref()); // Passes an immutable slice
fn foo(data: &[u8]) {
...
}
let mut data: vec![0u8; 1024];
bar(data.as_mut_slice());
//! Takes an mutable slice. The contents can be changed but its size cannot.
fn bar(data: &mut [u8]) {
...
}
foobar(data);
//! Vector contents and size can be changed.
fn foobar(data: &mut Vec<u8>) {
...
}
let x = [0u8; 10]; // 10 element array filled with zeros
let x = vec![0i32; 10]; // 10 element array of i32s filled with zeros