#cache #memoization #function #minimal

mincache-impl

mincache 的过程宏实现

1 个不稳定版本

0.1.0 2022年4月24日

#5#memoize


mincache 中使用

自定义许可证

6KB
101

mincache

最小的用于缓存函数返回值的crate。

目前仅支持定时/冷却缓存。

示例

pub use mincache::timecache;

// "fmt" is what you'd put after core::time::Duration::from_<>. E.g. "secs", "millis", "nanos", etc.
#[timecache(time = 5000, fmt = "secs")]
pub fn xyz(x: i32) -> std::time::Instant {
	println!("This will print once {x}");

	// This value will be cloned each time this is called before the cooldown is over
	// If you want to instead pass a reference, look into mincache/tests/ref.rs
	// (just add ``reference = true`` to the attribute params)
	std::time::Instant::now()
}

#[test]
fn main() {
	// Will call the function a single time.
	for _ in 0..1000000 {
		let xyz = xyz(55);
	}
}

依赖项

~2MB
~42K SLoC