[−][src]Struct moxie::state::Key
A Key
offers access to a state variable. The key allows reads of the state variable through
a snapshot taken when the Key
was created. Writes are supported with Key::update and
Key::set.
They are created with the memo_state
and state
macros.
Methods
impl<State> Key<State>
[src]
pub fn id(&self) -> Id
[src]
Returns the topo::Id
at which the state variable is bound.
pub fn update(&self, updater: impl FnOnce(&State) -> Option<State>)
[src]
Runs updater
with a reference to the state variable's latest value, and enqueues a commit
to the variable if updater
returns Some
. Returns the Revision
at which the state
variable was last rooted if the variable is live, otherwise returns None
.
Enqueuing the commit invokes the state change waker registered with the Runtime (if any) to ensure that the code embedding the runtime schedules another call of run_once.
This should be called during event handlers or other code which executes outside of a
Revision
's execution, otherwise unpredictable waker behavior may be obtained.
impl<State> Key<State> where
State: PartialEq,
[src]
State: PartialEq,
pub fn set(&self, new: State)
[src]
Commits a new state value if it is unequal to the current value and the state variable is still live. Has the same properties as update regarding waking the runtime.
Trait Implementations
impl<State> Clone for Key<State>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<State> Debug for Key<State> where
State: Debug,
[src]
State: Debug,
impl<State> Deref for Key<State>
[src]
impl<State> Display for Key<State> where
State: Display,
[src]
State: Display,
impl<State> PartialEq<Key<State>> for Key<State>
[src]
fn eq(&self, other: &Self) -> bool
[src]
Keys are considered equal if they point to the same state variable. Importantly, they will compare as equal even if they contain different snapshots of the state variable due to having been initialized in different revisions.
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
Auto Trait Implementations
impl<State> !RefUnwindSafe for Key<State>
impl<State> Send for Key<State> where
State: Send + Sync,
State: Send + Sync,
impl<State> Sync for Key<State> where
State: Send + Sync,
State: Send + Sync,
impl<State> Unpin for Key<State>
impl<State> !UnwindSafe for Key<State>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Erased for T
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,