[][src]Macro core_extensions::iter_cloner

macro_rules! iter_cloner {
    (let $ident:ident = $expr:expr) => { ... };
}

Use this macro to create an IterCloner from an Iterator value.

This macro takes an iterator by value,and then allows iterating multiple times with the same iterator,so long as it is Clone.

Closures can be Copy and/or Clone since Rust 1.26 ,this affects iterators since most iterator methods take closures.

Example

This example only runs from Rust 1.26 onwards,


#[macro_use]
extern crate core_extensions;


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()));
for _ in 0..2{
    assert_eq!(iter.into_iter().collect::<Vec<_>>(),lengths);
}