| Crates.io | simple_generators |
| lib.rs | simple_generators |
| version | 0.2.1 |
| created_at | 2023-01-23 23:08:57.917599+00 |
| updated_at | 2026-01-11 12:00:56.488984+00 |
| description | making work with generators simpler |
| homepage | |
| repository | |
| max_upload_size | |
| id | 766297 |
| size | 7,631 |
A library that contains a macro for a simpler generator->iterator creation
Use latest nightly
cargo add simple_generators
or:
[dependencies]
simple_generators = { version="0.2.1" }
example:
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
use simple_generators::*;
fn main() {
println!("{}", test_macro(10).sum::<u64>());
let foo = Foo {
vec: vec![10, 20, 30],
};
for e in foo.test_macro() {
println!("{}", e);
}
}
#[generator]
fn test_macro(n: u64) -> impl Iterator<Item = u64> {
let mut num = 0;
while num < n {
yield num;
num += 1;
}
}
struct Foo {
vec: Vec<u64>,
}
impl Foo {
#[generator]
fn test_macro(&self) -> impl Iterator<Item = u64> {
for item in &self.vec {
yield *item;
}
}
}