Struct core_memo::Memo[][src]

pub struct Memo<T: Memoize, P: Borrow<T::Param> = <T as Memoize>::Param> { /* fields omitted */ }

Memoized value which holds ownership over the parameter for its computation

See the crate-level documentation for information how to use the library.

This type holds ownership over the input parameter to your computation. It keeps everything nicely together and is the safest to use. If this is too restrictive for you, consider using MemoExt instead.

You can modify the parameter using param_mut() or update_param(). Any cached value will be cleared and will be recomputed on the next access.

Example

See the crate-level documentation for an example.

Methods

impl<T: Memoize, P: Borrow<T::Param>> Memo<T, P>
[src]

Creates a new Memo instance

You must pass in the object which will be used as the parameter for your computation. The Memo will take ownership over it.

Clears any cached value

The value will be reevaluated the next time it is needed.

Check if there is a cached value

If this method returns true, the next call to get() will return a stored memoized value.

If this method returns false, the next call to get() will recompute the value.

If the value is not ready, compute it and cache it

Call this method if you want to make sure that future get() calls can return instantly without computing the value.

Force the value to be recomputed

This discards any stored value and computes a new one immediately.

It is probably better to call clear() instead, to compute the value lazily when it is next needed.

Get the value

If the value has already been computed, this function returns the cached value. If not, it is computed and cached for future use.

If you need to make sure this method always returns quickly, call ready() beforehand or use try_get().

Get the value if it is available

If there is a cached value, returns it. If the value needs to be computed, returns None.

Get a reference to the parameter used for the computation

Get a mutable reference to the parameter used for the computation

This clears any cached value.

Modify the parameter used for the computation

Takes a closure and applies it to the parameter.

This clears any cached value.

Trait Implementations

impl<T: Debug + Memoize, P: Debug + Borrow<T::Param>> Debug for Memo<T, P>
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<T, P> Send for Memo<T, P> where
    P: Send,
    T: Send

impl<T, P> Sync for Memo<T, P> where
    P: Sync,
    T: Sync