Simple Memoization Library
core_memo
is a simple, straightforward, zero-cost Rust library for lazy
evaluation and memoization. It does not do memory allocations or dynamic
dispatch and it is #![no_std]
-compatible. It has no dependencies.
Example
use ;
// for assert_eq! later
;
// The `Memo` type holds ownership over the parameter for the calculation
// There are also the `MemoExt` and `MemoOnce` types with different semantics
let mut memo: = new;
// Our `memoize` method is called the first time we call `memo.get()`
assert_eq!;
// Further calls to `memo.get()` return the cached value without reevaluating
assert_eq!;
// We can mutate the parameter held inside the `Memo`:
// via a mutable reference
memo.param_mut.push;
// via a closure
memo.update_param;
// either way, the `Memo` forgets any cached value and it will be
// reevaluated on the next call to `memo.get()`
assert_eq!; // the vec is now `[1, 2, 3, 4]`