macro_rules! cached {
(fn $name:ident ($($arg:ident: $arg_type:ty), *) -> $ret:ty = $body:expr) => { ... };
}
Expand description
Macro for defining functions whose result needs to be cached.
ยงExample
use once_cell::sync::Lazy;
use std::sync::Mutex;
use memory_cache::{MemoryCache, cached};
cached! {
fn factorial(x: u128) -> u128 = {
if x <= 1 {
1
} else {
x * factorial(x - 1)
}
}
}
assert_eq!(factorial(21), 51090942171709440000);