Skip to main content

Memo

Struct Memo 

Source
pub struct Memo<T> { /* private fields */ }
Expand description

Equality/comparator-aware computed node.

Like Thunk, but a recomputation that produces an unchanged value (under PartialEq for memo, or a custom comparator for memo_by) does not invalidate downstream observers. Effects depending only on unchanged memos skip their re-runs entirely.

Clones share the same underlying node.

If the compute closure panics, the panic propagates to the reader and the node stays dirty, so the next read retries the computation.

§Panics

Reading a memo whose computation (transitively) reads itself panics with a crate::ReactCycleError message describing the cycle path. To fold the memo’s own previous value into the next one, use memo_with_prev.

Implementations§

Source§

impl<T: 'static> Memo<T>

Source

pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R

Runs f with a shared reference to the current computed value.

§Panics

Panics with a crate::ReactCycleError message when this memo’s computation (transitively) reads itself (use memo_with_prev for access to the previous value). A shared borrow of the cached value is held while f runs, so invalidating this memo and reading it again from inside f also panics.

Source§

impl<T: 'static> Memo<T>

Source

pub fn reactor(&self) -> Reactor

Returns the reactor this memo’s node belongs to.

Source

pub fn id(&self) -> NodeId

Returns this memo’s node id, for use with the graph queries on Reactor — observer_count, dependencies_of, node_origin and friends. Ids are unique within one reactor, so aggregate on (Reactor::id, id).

Source

pub fn with_peek<R>(&self, f: impl FnOnce(&T) -> R) -> R

Runs f with a shared reference to the current computed value without recording a dependency. The memo is still brought up to date before f runs.

§Panics

Panics under the same conditions as with.

Source§

impl<T: Clone + 'static> Memo<T>

Source

pub fn get(&self) -> T

Clones and returns the current computed value.

Source

pub fn peek(&self) -> T

Clones and returns the current computed value without recording a dependency.

Trait Implementations§

Source§

impl<T> Clone for Memo<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Memo<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: 'static> Observable for Memo<T>

Source§

type Item = T

The type of value this observable holds.
Source§

fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R

Runs f with a shared reference to the current value, recording a dependency for the currently running observer.
Source§

fn with_peek<R>(&self, f: impl FnOnce(&T) -> R) -> R

Runs f with a shared reference to the current value without recording a dependency.
Source§

fn reactor(&self) -> Option<Reactor>

Returns the reactor this observable’s node belongs to, when it has one. Read more
Source§

fn get(&self) -> Self::Item
where Self::Item: Clone,

Clones and returns the current value, recording a dependency.
Source§

fn peek(&self) -> Self::Item
where Self::Item: Clone,

Clones and returns the current value without recording a dependency.
Source§

fn map<U, F>(&self, f: F) -> Memo<U>
where Self: Clone + Sized + 'static, U: PartialEq + 'static, F: Fn(&Self::Item) -> U + 'static,

Derives a memo from this observable, cloning the receiver’s handle internally. Read more
Source§

fn into_dyn(self) -> DynObservable<Self::Item>
where Self: Sized + 'static,

Erases this observable’s concrete type behind a cheaply-cloneable handle.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Memo<T>

§

impl<T> !Send for Memo<T>

§

impl<T> !Sync for Memo<T>

§

impl<T> !UnwindSafe for Memo<T>

§

impl<T> Freeze for Memo<T>
where Rc<MemoInner<T>>: Freeze,

§

impl<T> Unpin for Memo<T>
where Rc<MemoInner<T>>: Unpin,

§

impl<T> UnsafeUnpin for Memo<T>
where Rc<MemoInner<T>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more