[][src]Function moxie::cache_with

pub fn cache_with<Arg: ?Sized, Input, Output, Ret>(
    arg: &Arg,
    init: impl FnOnce(&Input) -> Output,
    with: impl FnOnce(&Output) -> Ret
) -> Ret where
    Arg: PartialEq<Input> + ToOwned<Owned = Input>,
    Input: Borrow<Arg> + 'static,
    Output: 'static,
    Ret: 'static, 

Cache the return of the init function.

If the cache has a stored (Input, Output) for the current topo::CallId and if arg is equal to the stored Input, marks the value as alive in the cache and returns the result of calling with on the stored Output.

Otherwise, calls arg.to_owned() to get an Input and calls init to get an Output. It calls with on the Output to get a Ret value, stores the (Input, Output) in the cache afresh, and returns the Ret.

It is technically possible to nest calls to cache_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.

Environment Expectations

This function requires the following types to be visible to illicit::get and will panic otherwise: