WatchedCore

Struct WatchedCore 

Source
pub struct WatchedCore<'ctx, T: ?Sized, O: ?Sized = DefaultOwner> { /* private fields */ }
Expand description

This represents some value which will be interesting to watch. Watcher functions that reference this value will be re-run when this value changes.

Implementations§

Source§

impl<'ctx, T, O: ?Sized> WatchedCore<'ctx, T, O>

Source

pub fn new(value: T) -> Self

Create a new watched value.

Source

pub fn into_inner(self) -> T

Consumes the WatchedCore, returning the wrapped value

Source

pub fn replace(&mut self, value: T, ctx: WatchArg<'_, 'ctx, O>) -> T

Takes the wrapped value, with a new one, returning the old value, without deinitializing either one, and notifies watchers that the value has changed.

Source

pub fn replace_external(&mut self, value: T) -> T

Source

pub fn take(&mut self, ctx: WatchArg<'_, 'ctx, O>) -> T
where T: Default,

Takes the wrapped value, leaving Default::default() in its place, and notifies watchers that the value has changed.

Source

pub fn take_external(&mut self) -> T
where T: Default,

Source

pub fn set_if_neq(&mut self, value: T, ctx: WatchArg<'_, 'ctx, O>)
where T: PartialEq,

This function provides a way to set a value for a watched value only if is has changed. This is useful for cases where setting a value would otherwise cause an infinite loop.

Source

pub fn set_if_neq_external(&mut self, value: T)
where T: PartialEq,

Source§

impl<'ctx, T: ?Sized, O: ?Sized> WatchedCore<'ctx, T, O>

Source

pub fn get(&self, ctx: WatchArg<'_, 'ctx, O>) -> &T

Get a referenced to the wrapped value, binding a watch closure.

Source

pub fn get_mut(&mut self, ctx: WatchArg<'_, 'ctx, O>) -> &mut T

Get a mutable referenced to the wrapped value, notifying watchers that the value has changed.

Source

pub fn get_mut_external(&mut self) -> &mut T

Source

pub fn get_unwatched(&self) -> &T

Get a referenced to the wrapped value, without binding any watch closure.

Source§

impl<T: ?Sized> WatchedCore<'static, T, DefaultOwner>

Source

pub fn get_auto(&self) -> &T

Source

pub fn get_mut_auto(&mut self) -> &mut T

Source

pub fn replace_auto(&mut self, value: T) -> T
where T: Sized,

Source

pub fn take_auto(&mut self) -> T
where T: Default,

Source

pub fn set_if_neq_auto(&mut self, value: T)
where T: PartialEq + Sized,

This function provides a way to set a value for a watched value only if is has changed. This is useful for cases where setting a value would otherwise cause an infinite loop.

Trait Implementations§

Source§

impl<'ctx, T: Default, O: ?Sized> Default for WatchedCore<'ctx, T, O>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'ctx, T, O: ?Sized> From<T> for WatchedCore<'ctx, T, O>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<'a, 'ctx, O, T> WatchedValueCore<'ctx, O> for &'a WatchedCore<'ctx, T, O>
where O: ?Sized, T: ?Sized,

Source§

type Value = &'a T

Source§

fn get(self, ctx: WatchArg<'_, 'ctx, O>) -> Self::Value

Source§

fn get_unwatched(self) -> Self::Value

Source§

fn map<F, U>(self, map_fn: F) -> impl WatchedValueCore<'ctx, O, Value = U>
where Self: Sized, F: FnOnce(Self::Value) -> U,

Auto Trait Implementations§

§

impl<'ctx, T, O = DefaultOwner> !Freeze for WatchedCore<'ctx, T, O>

§

impl<'ctx, T, O = DefaultOwner> !RefUnwindSafe for WatchedCore<'ctx, T, O>

§

impl<'ctx, T, O = DefaultOwner> !Send for WatchedCore<'ctx, T, O>

§

impl<'ctx, T, O = DefaultOwner> !Sync for WatchedCore<'ctx, T, O>

§

impl<'ctx, T, O> Unpin for WatchedCore<'ctx, T, O>
where T: Unpin + ?Sized, O: ?Sized,

§

impl<'ctx, T, O = DefaultOwner> !UnwindSafe for WatchedCore<'ctx, T, O>

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> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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, 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.