4 ms·
Rust does have these abstractions. The corresponding rust traits are `IntoIterator<Item=T>` and `Iterator<Item=T>`. For example: - Vec<T> implements IntoIter
by marcianx 8y ago
Rust does have these abstractions. The corresponding rust traits are `IntoIterator<Item=T>` and `Iterator<Item=T>`. For example:
- Vec<T> implements IntoIterator<Item=T>
- &Vec<T> implements IntoIterator<Item=&T>
- &mut Vec<T> implements IntoIterator<Item=&mut T>
and consequently,
- vec.into_iter() implements Iterator<Item=T>
- (&vec).into_iter() (or vec.iter()) implements Iterator<Item=&T>
- (&mut vec).into_iter() (or vec.iter_mut()) implements Iterator<Item=&mut T>
- lostmsu 8y agoGood, but how do you create something, that is IntoIterator, which holds an immutable description of how to generate members to iterate over? And I mean some potentially infinite sequence.
- heinrich5991 8y agoFor example like this: https://doc.rust-lang.org/std/iter/fn.repeat.html https://doc.rust-lang.org/std/iter/fn.repeat.html