Macro core_extensions::iter_cloner
source · macro_rules! iter_cloner { (let $ident:ident = $expr:expr) => { ... }; }
Expand description
Use this macro to create an
IterCloner
from an IntoIterator
(this includes all Iterator
s).
The resulting variable clones the iterator (that $expr
was converted into)
every time that you call .into_iter()
or iterate over it with a for
loop.
§Example
§Mapping
use core_extensions::iter_cloner;
let list = vec!["this", "is", "not", "really", "great"];
let lengths = vec![4, 2, 3, 6, 5];
iter_cloner!(let iter = list.iter().map(|v|v.len()));
assert_eq!(iter.into_iter().collect::<Vec<_>>(), lengths);
assert_eq!(iter.into_iter().collect::<Vec<_>>(), lengths);
assert_eq!(iter.into_iter().collect::<Vec<_>>(), lengths);
§Vector
use core_extensions::iter_cloner;
iter_cloner!(let iter = vec![0, 1, 2, 3]);
assert_eq!(iter.into_iter().collect::<Vec<_>>(), [0, 1, 2, 3]);
assert_eq!(iter.into_iter().collect::<Vec<_>>(), [0, 1, 2, 3]);
assert_eq!(iter.into_iter().collect::<Vec<_>>(), [0, 1, 2, 3]);