[][src]Function moxie::memo::memo_with

pub fn memo_with<Arg, Stored, Ret>(
    arg: Arg,
    init: impl FnOnce(&Arg) -> Stored,
    with: impl FnOnce(&Stored) -> Ret
) -> Ret where
    Arg: PartialEq + 'static,
    Stored: 'static,
    Ret: 'static, 

Memoizes the provided function, caching the intermediate Stored value in memoization storage and only re-initializing it if Arg has changed since the cached value was created. Regardless of prior cached results, with is then called in to produce a return value.

Marks the memoized value as Live in the current Revision, preventing the value from being garbage collected during at the end of the current Revision.

If a previous value was cached for this callsite but the argument has changed and it must be re-initialized, the previous value will be dropped before the new one is initialized.

It is currently possible to nest calls to memo_with and other functions in this module, but the values they store won't be correctly retained across Revisions until we track dependency information. As a result, it's not recommended to nest calls to memo_with!.

init takes a reference to Arg so that the memoization store can compare future calls' arguments against the one used to produce the stored value.