#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

#41 in #iteration

Download history 36/week @ 2024-07-22 3/week @ 2024-07-29 10/week @ 2024-08-05 9/week @ 2024-08-12 8/week @ 2024-08-19 3/week @ 2024-09-09 8/week @ 2024-09-16 31/week @ 2024-09-23 15/week @ 2024-09-30 7/week @ 2024-10-07 18/week @ 2024-10-14 4/week @ 2024-10-21 16/week @ 2024-10-28 26/week @ 2024-11-04

64 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