#traits #iterator #iteration #loops #macro #posible #for-in

foreach

ForEach trait and for_each! macro allow you to use iterator inside iteration loop, which is not posible when using for-in loop

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

#40 in #iteration

Download history 21/week @ 2024-01-08 16/week @ 2024-01-15 15/week @ 2024-01-22 68/week @ 2024-01-29 17/week @ 2024-02-19 19/week @ 2024-02-26 24/week @ 2024-03-04 14/week @ 2024-03-11 19/week @ 2024-03-18 83/week @ 2024-04-01

119 downloads per month
Used in zflow

MIT license

5KB
65 lines

Build Status

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;
    }
});

No runtime deps