They're not at all equal. If anything, it should be v.iter().cloned()
vs. v.clone().into_iter()
, both produce an iterator over owned T
while v.clone().iter()
produces an iterator over &T
.
v.clone().into_iter()
clones the Vec
, allocating a Vec
with the same size and cloning all elements into it, then converts this newly created Vec
into an iterator. v.iter().cloned()
, OTOH, creates a borrowed iterator over the Vec
that yields &T
, then applies the cloned()
iterator adapter to it, which on-the-fly clones the &T
produced by Iterator::next()
to produce an owned T
. Thus it doesn't need to allocate a new vector.
Because of that, you should always prefer v.iter().cloned()
when possible (usually it is, but Vec
's IntoIter
has additional capabilities, like getting the underlying slice that may be required).