Skip to content
Stackless generators on stable Rust.
Rust
Branch: master
Clone or download
Latest commit 106eea7 Nov 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Get rid of redundant test run Nov 8, 2019
src Add a test for `stack::Gen::drop` Nov 11, 2019
tests Update the docs Nov 11, 2019
.editorconfig first blood Nov 3, 2019
.gitignore first blood Nov 3, 2019
.pre-commit-config.yaml Switch CI to GitHub Actions, and upgrade Rust Nov 8, 2019
CHANGELOG.md Release v0.2.1 Nov 11, 2019
Cargo.lock Release v0.2.1 Nov 11, 2019
Cargo.toml Release v0.2.1 Nov 11, 2019
README-crates-io.md Update the docs Nov 11, 2019
README.md Update the docs Nov 11, 2019
rustfmt.toml first blood Nov 3, 2019

README.md

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:

  • safe
  • allocation-free
  • supports resume arguments
  • no dependencies

Example:

let generator = Gen::new(|co| async move {
    let mut n = 1;
    while n < 10 {
        // Suspend a function at any point with a value.
        co.yield_(n).await;
        n += 2;
    }
});

// Generators can be used as ordinary iterators.
for num in generator {
    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
You can’t perform that action at this time.