4 releases (2 breaking)
Uses old Rust 2015
0.3.0 | Sep 10, 2017 |
---|---|
0.2.0 | Apr 9, 2017 |
0.1.1 | Apr 9, 2017 |
0.1.0 | Apr 9, 2017 |
#37 in #loop
49 downloads per month
Used in zflow
5KB
65 lines
ForEach trait and for_each! macro
ForEach trait and for_each! macro allow you to use iterator inside iteration loop, which is not posible when using for-in loop.
lib.rs
:
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;
}
});