mincache-impl

Crates.iomincache-impl
lib.rsmincache-impl
version0.1.0
sourcesrc
created_at2022-04-24 02:18:30.656174
updated_at2022-04-24 02:18:30.656174
descriptionProcedural macro implementation for mincache
homepage
repositoryhttps://github.com/Vurv78/mincache
max_upload_size
id572902
size6,777
Vurv (Vurv78)

documentation

README

mincache

Minimal crate to cache return values of your function returns.

Currently only supports a timer / cooldown cache.

Example

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);
	}
}
Commit count: 4

cargo fmt