I'm trying to figure out what is the cost of cloning iterators that originate from into_iter()
in Rust, but can't find anything meaningful.
Consider the code like this:
let v = vec![1,2,3,4,...]; // Some large vector
let iter = v.into_iter().map(...some closure...);
let another_iter = iter.clone(); // What is copied here??
Since I've moved the vector into an iterator, iter
now owns the internal buffer with vector values. This is exactly what I want to achieve to abstract the container type.
However, what happens when I call iter.clone()
? Does it copy the whole internal buffer with data (could be very expensive) or just copy the iterator state while referring to the same buffer (cheap)?
Is there an idiomatic way of storing and cheaply cloning such iterators originating from into_iter()
?