I have some problems with my Rust program. I'm trying to create a vector with the numbers 48 to 57 and then randomly shuffle it. I'm running into the following errors
src/main.rs:7:26: 7:51 error: the type of this value must be known in this context
src/main.rs:7 let &mut slice = secret_num.as_mut_slice();
^~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:9:13: 9:20 error: no method named `shuffle` found for type `rand::ThreadRng` in the current scope
src/main.rs:9 rng.shuffle(&mut slice);
^~~~~~~
Here's the code:
extern crate rand;
fn main() {
//Main game loop
loop{
let mut secret_num = (48..58).collect();
let &mut slice = secret_num.as_mut_slice();
let mut rng = rand::thread_rng();
rng.shuffle(&mut slice);
println!("{:?}", secret_num);
break;
}
println!("Hello, world!");
}
Aucun commentaire:
Enregistrer un commentaire