Skip to main content

WeakVar

Struct WeakVar 

Source
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>

Source

pub fn is_alive(&self) -> bool

Checks if the associated Var has been dropped.

Source

pub fn get_version(&self) -> Option<u64>

Returns the current version of the variable.

Source

pub fn read<'a>(&'a self) -> Option<VarReadGuard<'a, T>>

Returns a read guard to the value if the Var is alive, marking it as read from.

Returns None if the Var has been destroyed.

Source

pub fn write<'a>(&'a self) -> Option<VarWriteGuard<'a, T>>

Returns a write guard to the value if the Var is alive.

The guard handles marking the Var as written to and read from when it is dropped.

Returns None if the Var has been destroyed.

Source

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.

Source

pub fn get_or(&self, default: T) -> T
where 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.

Source

pub fn get_or_else(&self, default: impl FnOnce() -> T) -> T
where 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.

Source

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.

Source

pub fn replace(&self, new: T) -> Option<T>

Replaces the value in the registry and returns the old value.

Source

pub fn take(&self) -> Option<T>
where T: Default,

Takes the current value, leaving Default::default() in its place.

Source

pub fn mark_read(&self)

Marks a Var as if it had been read from.

This is a no-op if the Var has been destroyed.

Trait Implementations§

Source§

impl<T: Send + Sync + 'static> Clone for WeakVar<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: Send + Sync + 'static> Copy for WeakVar<T>

Source§

impl<T: Debug + Send + Sync + 'static> Debug for WeakVar<T>

Source§

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

Debug formatting is side-effect free, so viewports won’t register the value as having been read from.

Source§

impl<T: Send + Sync + 'static> Eq for WeakVar<T>

Source§

impl From<WeakVar<&'static str>> for UIString

Source§

fn from(value: WeakVar<&'static str>) -> Self

Converts to this type from the input type.
Source§

impl From<WeakVar<String>> for UIString

Source§

fn from(value: WeakVar<String>) -> Self

Converts to this type from the input type.
Source§

impl From<WeakVar<String>> for LocalizedArg

Source§

fn from(v: WeakVar<String>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<WeakVar<T>> for UIString
where 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.

Source§

fn from(var: WeakVar<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Send + Sync + 'static> From<WeakVar<T>> for UIParam<T>

Source§

fn from(var: WeakVar<T>) -> Self

Converts to this type from the input type.
Source§

impl From<WeakVar<f64>> for LocalizedArg

Source§

fn from(v: WeakVar<f64>) -> Self

Converts to this type from the input type.
Source§

impl<T: Send + Sync + 'static> PartialEq for WeakVar<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyEq for T
where T: Any + PartialEq,

Source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

fn as_any(&self) -> &(dyn Any + 'static)

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,