Skip to main content

use_memo

Function use_memo 

Source
pub fn use_memo<'s, D: Hash, T: 'static>(
    cx: &mut Cx<'s, '_>,
    deps: D,
    f: impl FnOnce() -> T,
) -> &'s T
Expand description

Compute f on the first visit and whenever the hash of deps changes.

Returns a reference that lives as long as the store borrow, not as long as the &mut Cx, so a memo can be read next to a State guard. Superseded values are only dropped between passes, because a reference handed out earlier in the same pass may still point at one.