Expand description

This crate is intended for easy creation of iterators without exposing that they’re actually Genawaiter generators. Generators have more overhead than iterators (in this implementation), but it’s much easier to write them so it’s worth the overhead, I think.

Use genawaiter_iterator! to create the iterator struct, then use gen! to create a generator and automatically coerce it to the output type (implied that you invoke gen! in an iter(&self) -> IterStructName method (might have another receiver type)).

Usage example:

use genawaiter_iterator::{genawaiter_iterator, gen};
use genawaiter::yield_;

genawaiter_iterator!(struct Iter yields usize);

fn iter() -> Iter {
    gen!({
        yield_!(1);
        yield_!(2);
        yield_!(3);
    })
}

let mut iterator_instance = iter();
assert_eq!(iterator_instance.next(), Some(1));
assert_eq!(iterator_instance.next(), Some(2));
assert_eq!(iterator_instance.next(), Some(3));
assert_eq!(iterator_instance.next(), None);

Macros§