Expand description
ForEach trait and for_each! macro allow you to use iterator inside iteration loop, which is not posible when using for-in loop.
§Examples
let mut iter = 0..999;
iter.foreach(|item, iter| {
println!("item: {}", item);
println!("next: {:?}", iter.next());
});
use foreach::Continue::*;
let mut iter = 0..999;
iter.foreach(|item, iter| {
println!("item: {}", item);
println!("next: {:?}", iter.next());
if item > 10 {
return Break;
} else {
return ().into();
}
});
let mut iter = 0..999;
for_each!(item in iter {
println!("item: {}", item);
println!("next: {:?}", iter.next());
if item > 10 {
break;
}
});
Macros§
- for_
each - This macro allows you to use iterator inside iteration loop, which is not posible when using for-in loop. See crate-level docs for examples
Enums§
Traits§
- ForEach
- Trait to simplify usage of iterator inside iteration loop.