How do I create a Vec from a range and shuffle it?
I have the following code: extern crate rand; use rand::{thread_rng, Rng}; fn main() { let mut vec: Vec<u32> = (0..10).collect(); let mut slice: &[u32] = vec.as_mut_slice(); thread_rng().shuffle(slice); } and get the following error: error[E0308]: mismatched types --> src/main.rs:9:26 | 9 | thread_rng().shuffle(slice); | ^^^^^ types differ in mutability | = note: expected type `&mut [_]` found type `&[u32]` I think I understand that the content of vectors and slices is immutable and that causes the error here, but I'm unsure. The signature of as_mut_slice is pub fn as_mut_slice<'a>(&'a mut