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 socks5 proxies
     24837 | Never
free anonymous http proxies
     23288 | Never
maze traversal
     2626 | Never
hello, world
     2228 | Never
difference between iter and into_iter in rust
     1769 | Never
DEVISIB All-in-One Coffee Machine Espresso Coffee Maker with Grinder Automatic coffee makers
     453 | 2022-12-04
leetcode 739 Daily Temperatures python
     271 | Never
presentation on friendly interactive shell, fish
     227 | Never
leetcode 621 task scheduler python
     181 | Never
new
     127 | 2021-12-27