Dedenne

Cute little generators!

Dedenne implements generators, a la the unstable language feature, over async/await in completely stable Rust.

Simple Usage

```rust use dedenne::*;

let mut generator = Generator::new(|y, init| async move { for x in 0..init { y.ield(x).await; } for x in (0..init).rev() { y.ield(x).await; }

"All done!" });

asserteq!( generator.start(3), GeneratorResponse::Yielding(0) ); asserteq!( generator.resume(), GeneratorResponse::Yielding(1) ); asserteq!( generator.resume(), GeneratorResponse::Yielding(2) ); asserteq!( generator.resume(), GeneratorResponse::Yielding(2) ); asserteq!( generator.resume(), GeneratorResponse::Yielding(1) ); asserteq!( generator.resume(), GeneratorResponse::Yielding(0) ); assert_eq!( generator.resume(), GeneratorResponse::Done("All done!") ); ```

For a larger example, check out this simple TUI interface.

panic! vs unreachable!

If something in Dedenne panic!s, then it's a user error. Make sure to await your y.ields, and don't call resume after a generator's exhausted.

If something in Dedenne panics with an unreachable! message, then it's a problem with Dedenne. Please file a bug report if it does.

Prior Art

I am not the first person to have this idea. However, I think Dedenne is the only crate that supports mapping over iterators.