https://github.com/lbfalvy/memorize
Versatile and fast caching utility for Rust
https://github.com/lbfalvy/memorize
closures memoization rust
Last synced: 14 days ago
JSON representation
Versatile and fast caching utility for Rust
- Host: GitHub
- URL: https://github.com/lbfalvy/memorize
- Owner: lbfalvy
- Created: 2023-10-30T22:39:23.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-07T11:12:52.000Z (over 2 years ago)
- Last Synced: 2026-05-03T04:09:50.390Z (about 1 month ago)
- Topics: closures, memoization, rust
- Language: Rust
- Homepage: https://docs.rs/memorize
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
Cache the return values of an effectless closure in a hashmap. Inspired by the [closure_cacher](https://docs.rs/closure_cacher) crate, but attempts to provide a more versatile implementation.
```rs
use memorize::{cached, Cache};
let demo = cached(|arg, _| arg * 2);
assert_eq!(demo.find(&7), 14);
```
The second argument is a callback, it can be used for recursion.
```rs
use memorize::{cached, Cache};
let demo = cached(|arg, r| match arg {
1 | 2 => 1,
n => r(&(n - 1)) + r(&(n - 2)),
});
assert_eq!(demo.find(&15), 610)
```