jaemk / cached

Rust cache structures and easy function memoization
MIT License
1.57k stars 95 forks source link

`key` argument name collision #230

Open publicqi opened 1 month ago

publicqi commented 1 month ago

Example:

#[cached]
fn foo(key: u64, b: u64) -> u64 {
    key + b
}

This will expand to

        ///This is a cached function that uses the [`FOO`] cached static.
        fn foo(key: u64, b: u64) -> u64 {
            use cached::Cached;
            use cached::CloneCached;
            let key = (key.clone(), b.clone());
            {
                let mut cache = FOO.lock().unwrap();
                if let Some(result) = cache.cache_get(&key) {
                    return result.to_owned();
                }
            }
            let result = foo_no_cache(key, b);
            let mut cache = FOO.lock().unwrap();
            cache.cache_set(key, result.clone());
            result
        }

Change the proc macro variable name to something else?