I would like to take a mutable slice and copy the contents into two new mutable slices. Each slice being one half of the original.
My attempt #1:
let
You can build vectors from slices directly by cloning the elements using multiple methods:
fn main() {
let my_list: &mut [u8] = &mut [0, 1, 2, 3, 4, 5];
let mut vec1 = my_list[0..2].to_vec();
let mut vec2: Vec = my_list[2..4].into();
let mut vec3 = my_list[2..6].to_owned();
println!("{:?}", vec1);
println!("{:?}", vec2);
}
Your original problem was caused because all of these return a Vec
but you were attempting to claim that it was a slice, equivalent to:
let thing: &mut [u8] = Vec::new();