pub struct WeakVar<T: Send + Sync + 'static> { /* private fields */ }Expand description
A handle to a Var that implements Copy.
Intended to be stored in callbacks.
Implementations§
Source§impl<T: Send + Sync + 'static> WeakVar<T>
impl<T: Send + Sync + 'static> WeakVar<T>
Sourcepub fn get_version(&self) -> Option<u64>
pub fn get_version(&self) -> Option<u64>
Returns the current version of the variable.
Sourcepub fn read<'a>(&'a self) -> Option<VarReadGuard<'a, T>>
pub fn read<'a>(&'a self) -> Option<VarReadGuard<'a, T>>
Sourcepub fn write<'a>(&'a self) -> Option<VarWriteGuard<'a, T>>
pub fn write<'a>(&'a self) -> Option<VarWriteGuard<'a, T>>
Sourcepub fn get(&self) -> Option<T>where
T: Clone,
pub fn get(&self) -> Option<T>where
T: Clone,
Returns a clone of the stored value if it is still alive, marking it as read from. Returns None otherwise.
Sourcepub fn get_or(&self, default: T) -> Twhere
T: Clone,
pub fn get_or(&self, default: T) -> Twhere
T: Clone,
Returns the value if the Var is alive, or default if it has been dropped.
This method evaluates default eagerly, even if the value is alive.
Use WeakVar::get_or_else to evaluate the default lazily.
Sourcepub fn get_or_else(&self, default: impl FnOnce() -> T) -> Twhere
T: Clone,
pub fn get_or_else(&self, default: impl FnOnce() -> T) -> Twhere
T: Clone,
Returns a clone of the value if alive, or computes a default from the given closure.
Unlike WeakVar::get_or, this only evaluates default if the Var is dead.
Sourcepub fn set(&self, new: T) -> Option<()>where
T: PartialEq,
pub fn set(&self, new: T) -> Option<()>where
T: PartialEq,
Sets the value of the variable, but only bumps the version if the value actually changed.
Returns None if the Var has been destroyed, Some(()) otherwise.
Sourcepub fn replace(&self, new: T) -> Option<T>
pub fn replace(&self, new: T) -> Option<T>
Replaces the value in the registry and returns the old value.
Sourcepub fn take(&self) -> Option<T>where
T: Default,
pub fn take(&self) -> Option<T>where
T: Default,
Takes the current value, leaving Default::default() in its place.
Trait Implementations§
impl<T: Send + Sync + 'static> Copy for WeakVar<T>
impl<T: Send + Sync + 'static> Eq for WeakVar<T>
Source§impl<T> From<WeakVar<T>> for UIStringwhere
T: UIVarDisplay,
Any WeakVar<T> where T is in UIVarDisplay becomes a fast deferred formatter.
impl<T> From<WeakVar<T>> for UIStringwhere
T: UIVarDisplay,
Any WeakVar<T> where T is in UIVarDisplay becomes a fast deferred formatter.
This does one heap alloc when constructing the UIString, and no heap alloc on resolve in
the common case because SmallString stays inline for short strings.
Auto Trait Implementations§
impl<T> !RefUnwindSafe for WeakVar<T>
impl<T> !UnwindSafe for WeakVar<T>
impl<T> Freeze for WeakVar<T>
impl<T> Send for WeakVar<T>
impl<T> Sync for WeakVar<T>
impl<T> Unpin for WeakVar<T>where
T: Unpin,
impl<T> UnsafeUnpin for WeakVar<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.