Var

Struct Var 

Source
pub struct Var<'c, T>(/* private fields */);
Expand description

Index into the RxDAG which will give you a variable.

To actually get or set the value you need a shared reference to the RxDAG.

Implementations§

Source§

impl<'c, T> Var<'c, T>

Source

pub fn get<'a>(self, c: impl RxContext<'a, 'c>) -> &'a T
where 'c: 'a,

Read the variable

Source

pub fn set<'a>(self, c: impl MutRxContext<'a, 'c>, value: T)
where 'c: 'a,

Write a new value to the variable. The changes will be applied on recompute.

Source

pub fn modify<'a, F: FnOnce(&T) -> T>( self, c: impl MutRxContext<'a, 'c>, modify: F, )
where 'c: 'a,

Apply a transformation to the latest value. If Var::set this will apply to the recently-set value. This must be used instead of chaining Var::set and Var::get, since setting a value doesn’t make it returned by Var::get until the graph is recomputed.

Like set the changes only actually reflect in Var::get on recompute.

Source

pub fn derive<U, GetFn: Fn(&T) -> &U, SetFn: Fn(&T, U) -> T>( self, get: GetFn, set: SetFn, ) -> DVar<'c, T, U, GetFn, SetFn>

Create a view of part of the variable.

Do know that SetFn will take the most recently-set value even if the graph hasn’t been recomputed. This means you can create multiple derives and set them all before recompute, and you don’t have to worry about the later derived values setting their part on the stale whole.

Source

pub fn derive_using_clone<U, GetFn: Fn(&T) -> &U, SetFn: Fn(&mut T, U)>( self, get: GetFn, set: SetFn, ) -> DVar<'c, T, U, GetFn, CloneSetFn<T, U, SetFn>>
where T: Clone,

Create a view of part of the variable, which clones the value on set.

Do know that SetFn will take the most recently-set value even if the graph hasn’t been recomputed. This means you can create multiple derives and set them all before recompute, and you don’t have to worry about the later derived values setting their part on the stale whole.

Trait Implementations§

Source§

impl<'c, T> Clone for Var<'c, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'c, T: Debug> Debug for Var<'c, T>

Source§

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

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

impl<'c, T> Copy for Var<'c, T>

Auto Trait Implementations§

§

impl<'c, T> Freeze for Var<'c, T>

§

impl<'c, T> RefUnwindSafe for Var<'c, T>
where T: RefUnwindSafe,

§

impl<'c, T> Send for Var<'c, T>
where T: Send,

§

impl<'c, T> Sync for Var<'c, T>
where T: Sync,

§

impl<'c, T> Unpin for Var<'c, T>
where T: Unpin,

§

impl<'c, T> UnwindSafe for Var<'c, T>
where T: UnwindSafe,

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, 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.