difference between iter and into_iter in rust

- The iterator returned by into_iter may yield any of T, &T or &mut T, depending on the context.
- The iterator returned by iter will yield &T, by convention.
- The iterator returned by iter_mut will yield &mut T, by convention.

into_iter is a generic method to obtain an iterator, whether this iterator yields values, immutable references or mutable references is context dependent and can sometimes be surprising.

iter and iter_mut are ad-hoc methods. Their return type is therefore independent of the context, and will conventionally be iterators yielding immutable references and mutable references, respectively.

Hot pastes

free anonymous http proxies
     22779 | Never
free anonymous socks5 proxies
     17264 | Never
maze traversal
     2480 | Never
windows license keys
     2086 | 2022-10-07
hello, world
     2043 | Never
python extract emails from text
     1847 | Never
Deep Copy vs Shallow Copy in C#
     1818 | Never
difference between iter and into_iter in rust
     1604 | Never
bitwise operations
     1424 | Never
flips a line of text so that it appears to be upside-down and mirrored
     1370 | Never