cache-macro-stable-rust 0.4.1

A procedural macro for automatically caching the output of functions.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use cache_macro::cache;
use lru_cache::LruCache;

#[test]
fn multiple_caches() {
    use std::f64;
    #[cache(LruCache : LruCache::new(20))]
    fn cached_sqrt(x: u64) -> f64 {
        f64::sqrt(x as f64)
    }
    #[cache(LruCache : LruCache::new(20))]
    fn cached_log(x: u64) -> f64 {
        f64::ln(x as f64)
    }

    assert_eq!(cached_sqrt(9), f64::sqrt(9.0));
    assert_eq!(cached_log(9), f64::ln(9.0));
}