#proc-macro #recursion #iterator

macro reciter

Macro that allows converting a recursive function into an Iterator, which uses a cache

3 releases

✓ Uses Rust 2018 edition

0.1.2 Nov 10, 2018
0.1.1 Nov 10, 2018
0.1.0 Nov 10, 2018

#5 in #recursion

Download history 25/week @ 2018-11-06 19/week @ 2018-11-13 6/week @ 2018-11-20 3/week @ 2018-11-27 12/week @ 2018-12-04 6/week @ 2018-12-11 16/week @ 2018-12-18 2/week @ 2018-12-25 4/week @ 2019-01-01 5/week @ 2019-01-08 8/week @ 2019-01-15 1/week @ 2019-01-22 2/week @ 2019-01-29

6 downloads per month

MIT license

13KB
262 lines

The #[reciter] attribute macro allows converting a recursive function into an Iterator, which uses a cache.

Example

#[reciter(cache = "auto", start = 1)]
fn factorial(n: usize) -> BigInt {
    if n == 1 {
        BigInt::from(1)
    } else {
        n * factorial(n - 1)
    }
}

fn main() {
    let fi = FactorialIterator::new();
    for (i, fac) in fi.enumerate().take(512) {
        println!("{}! = {}", i + 1, fac);
    }
}    

For more information look into the documentation or at the tests in the repository.

Dependencies

~1MB
~21K SLoC