pub struct Memo<T> { /* private fields */ }Expand description
A value derived from signals and other memos.
Create one with Owner::memo. It computes nothing
until something reads it. When a value it read changes, it only becomes
stale, and recomputes the next time something reads it. If the new value
equals the old one, the memos and effects that read it don’t rerun.
If its closure panics, the memo is logged and disabled. It keeps its last
value, and try_get() returns None if it never had one. A memo must not
write signals or call Runtime::flush: either
panics, which disables it the same way.
Implementations§
Source§impl<T: 'static> Memo<T>
impl<T: 'static> Memo<T>
Sourcepub fn get(&self) -> Twhere
T: Clone,
pub fn get(&self) -> Twhere
T: Clone,
Returns a clone of the value, recomputing it first if it is stale. Inside a memo or effect, this makes it depend on this memo.
§Panics
If the memo’s owner was disposed, if it has no value because its
closure panicked on the first run, or if the memo reads itself.
try_get returns None in the first two cases.
Sourcepub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
Calls f with a reference to the value. Otherwise like
get.
Sourcepub fn get_untracked(&self) -> Twhere
T: Clone,
pub fn get_untracked(&self) -> Twhere
T: Clone,
Like get, but records no dependency.
Sourcepub fn with_untracked<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn with_untracked<R>(&self, f: impl FnOnce(&T) -> R) -> R
Like with, but records no dependency.
Sourcepub fn try_get(&self) -> Option<T>where
T: Clone,
pub fn try_get(&self) -> Option<T>where
T: Clone,
Like get, but returns None if the owner was disposed
or the memo has no value.