38 releases

0.8.5 May 14, 2025
0.8.4 Dec 5, 2024
0.8.3 Sep 1, 2024
0.8.2 Jul 25, 2024
0.2.0 Nov 12, 2015

#24 in Data structures

Download history 195351/week @ 2025-01-31 347397/week @ 2025-02-07 430393/week @ 2025-02-14 462780/week @ 2025-02-21 754888/week @ 2025-02-28 793413/week @ 2025-03-07 771670/week @ 2025-03-14 1376010/week @ 2025-03-21 556905/week @ 2025-03-28 626150/week @ 2025-04-04 517005/week @ 2025-04-11 496845/week @ 2025-04-18 474969/week @ 2025-04-25 545357/week @ 2025-05-02 548178/week @ 2025-05-09 454527/week @ 2025-05-16

2,126,994 downloads per month
Used in 1,760 crates (14 directly)

MIT/Apache

110KB
2.5K SLoC

Rust 2K SLoC // 0.2% comments GNU Style Assembly 654 SLoC // 0.1% comments

Build Status Current Crates.io Version Document

Generator-rs

rust stackful generator library

[dependencies]
generator = "0.8"

Usage

use generator::{done, Gn};

fn main() {
    let g = Gn::new_scoped(|mut s| {
        let (mut a, mut b) = (0, 1);
        while b < 200 {
            std::mem::swap(&mut a, &mut b);
            b = a + b;
            s.yield_(b);
        }
        done!();
    });

    for i in g {
        println!("{}", i);
    }
}

Output

1
2
3
5
8
13
21
34
55
89
144
233

Goals

  • basic send/yield with message support
  • generator cancel support
  • yield_from support
  • panic inside generator support
  • stack size tune support
  • scoped static type support
  • basic coroutine interface support
  • stable rust support

based on this basic library

  • we can easily port python library based on generator into rust
  • coroutine framework running on multi thread

Notices

  • This crate supports below platforms, welcome to contribute with other arch and platforms

    • x86_64 Linux
    • x86_64 macOS
    • x86_64 Windows
    • x86_64 Fuchsia
    • x86_64 Android
    • aarch64 Linux
    • aarch64 macOS
    • aarch64 Fuchsia
    • aarch64 Android
    • loongarch64 Linux
    • armv7 Linux
    • riscv64 Linux
    • powerpc64le Linux

License

This project is licensed under either of the following, at your option:

Dependencies

~0–29MB
~467K SLoC