2 releases

0.99.1 Mar 9, 2020
0.99.0 Feb 16, 2020

#1945 in Asynchronous

Download history 7991/week @ 2023-12-19 4982/week @ 2023-12-26 9726/week @ 2024-01-02 10813/week @ 2024-01-09 14368/week @ 2024-01-16 15310/week @ 2024-01-23 15902/week @ 2024-01-30 11613/week @ 2024-02-06 11545/week @ 2024-02-13 13071/week @ 2024-02-20 17673/week @ 2024-02-27 18905/week @ 2024-03-05 16349/week @ 2024-03-12 18132/week @ 2024-03-19 15901/week @ 2024-03-26 15136/week @ 2024-04-02

68,022 downloads per month
Used in 68 crates (via genawaiter)

MIT/Apache

4KB

genawaiter

crate-badge docs-badge ci-badge

This crate implements stackless generators (aka coroutines) in stable Rust. Instead of using yield, which won't be stabilized anytime soon, you use async/await, which is stable today.

Features:

  • supports resume arguments and completion values
  • allocation-free
  • no runtime dependencies
    • no compile-time dependencies either, with default-features = []
  • built on top of standard language constructs, which means there are no platform-specific shenanigans

Example:

let odd_numbers_less_than_ten = gen!({
    let mut n = 1;
    while n < 10 {
        yield_!(n); // Suspend a function at any point with a value.
        n += 2;
    }
});

// Generators can be used as ordinary iterators.
for num in odd_numbers_less_than_ten {
    println!("{}", num);
}

Result:

1
3
5
7
9

See the docs for more.

Development

Install prerequisites

Install the pre-commit hook

pre-commit install

This installs a Git hook that runs a quick sanity check before every commit.

Run the app

cargo run

Run the tests

cargo test

No runtime deps

Features