No description, website, or topics provided.
Clone or download
Latest commit 030bdf6 Feb 1, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
adapter removed unsafe and support latest nightly Feb 1, 2019
macros initial commit Jan 28, 2019
src initial commit Jan 28, 2019
tests fixed tests Jan 28, 2019
.gitignore Initial commit Jan 28, 2019
Cargo.toml updated ver Feb 1, 2019
LICENSE Initial commit Jan 28, 2019
README.md updated ver Feb 1, 2019

README.md

simple_generators

A library that contains a macro for a simpler generator->iterator creation

Usage

Use latest nightly Didn't yet publish to crates.io so

Add this to your Cargo.toml:

[dependencies]
simple_generators = {version="0.1.1", git = "https://github.com/vova616/simple_generators"}

example:

#![feature(generators, generator_trait)]

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<'a>(&'a self) -> impl Iterator<Item = u64> + 'a {
        for item in &self.vec {
            yield *item;
        }
    }
}