memoize 0.6.0

Attribute macro for auto-memoizing functions with somewhat-simple signatures
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use memoize::memoize;

#[memoize]
fn hello(arg: String, arg2: usize) -> std::io::Result<bool> {
    println!("{} => {}", arg, arg2);
    Ok(arg.len() % 2 == arg2)
}

fn main() {
    // `hello` is only called once here.
    assert!(hello("World2".to_string(), 0).unwrap());
    assert!(hello("World2".to_string(), 0).unwrap());
    // Sometimes one might need the original function.
    assert!(memoized_original_hello("World2".to_string(), 0).unwrap());
    memoized_flush_hello();
}