I'm trying to move a value from an iterator, created from a vector:
#[derive(Debug)]
enum E {
A,
B(String)
}
fn f(mut items : Iter<E>) -> String {
match items.next() {
Option::None => "nothing".to_string(),
Option::Some(e) => match e {
E::A => "A".to_string(),
E::B(s) => s
},
}
}
fn main() {
let mut t = vec![E::B("string".to_string())];
let v = f(t.iter());
}
But this doesn't work since t.iter()
created an iterator over the references of elements of t
. How do I create an iterator from which values can be moved out of the vector? The creation of iterator should consume the ownership of original vector.