Caveat: I'm new to Rust, so pardon any ignorance.
I have a function that accepts a reference to a vector. It then creates an iterator from that vector and does processing on its values.
Code:
fn new(args: &Vec<String>) -> Result<Config, &str> {
let mut args_iter = args.iter(); //create iterator
args_iter.next(); //skip the 0th item
let query = match args_iter.next() {
Some(arg) => *arg, //BREAKS
None => return Err("no query"),
};
let file = match args_iter.next() {
Some(arg) => arg.clone(), //WORKS
None => return Err("no file"),
};
//more stuff
}
Now I'm getting this error:
move occurs because `*arg` has type `String`, which does not implement the `Copy` trait
Which gets solved if I change *arg
to arg.clone()
.
Can someone help me understand why? I thought that by creating an iterator inside the function, the function owns the iterator and should be able to mutate/move its values as it pleases?