macro_rules! static_cache {
($K:ty, $V:ty, $size:expr) => { ... };
($K:ty, $V:ty, $size:expr, $hasher:expr) => { ... };
}Expand description
Declares a static cache with the given name, key type, value type, and size.
The size must be a power of two.
ยงExample
use fixed_cache::{Cache, static_cache};
type BuildHasher = std::hash::BuildHasherDefault<rapidhash::fast::RapidHasher<'static>>;
static MY_CACHE: Cache<u64, &'static str, BuildHasher> =
static_cache!(u64, &'static str, 1024, BuildHasher::new());
let value = MY_CACHE.get_or_insert_with(42, |_k| "hi");
assert_eq!(value, "hi");
let new_value = MY_CACHE.get_or_insert_with(42, |_k| "not hi");
assert_eq!(new_value, "hi");