cushy::reactive::value

Trait Destination

Source
pub trait Destination<T> {
    // Required method
    fn try_map_mut<R>(
        &self,
        map: impl FnOnce(Mutable<'_, T>) -> R,
    ) -> Result<R, DeadlockError>;

    // Provided methods
    fn map_mut<R>(&self, map: impl FnOnce(Mutable<'_, T>) -> R) -> R { ... }
    fn try_replace(&self, new_value: T) -> Result<T, ReplaceError<T>>
       where T: PartialEq { ... }
    fn replace(&self, new_value: T) -> Option<T>
       where T: PartialEq { ... }
    fn set(&self, new_value: T)
       where T: PartialEq { ... }
    fn force_set(&self, new_value: T) { ... }
    fn try_compare_swap(
        &self,
        expected_current: &T,
        new_value: T,
    ) -> Result<T, TryCompareSwapError<T>>
       where T: Clone + PartialEq { ... }
    fn compare_swap(&self, expected_current: &T, new_value: T) -> Result<T, T>
       where T: Clone + PartialEq { ... }
    fn toggle(&self) -> T
       where T: Not<Output = T> + Clone { ... }
    fn take(&self) -> T
       where Self: Source<T>,
             T: Default { ... }
    fn take_if_not_default(&self) -> Option<T>
       where T: Default + PartialEq { ... }
}
Expand description

A destination for values of type T.

Required Methods§

Source

fn try_map_mut<R>( &self, map: impl FnOnce(Mutable<'_, T>) -> R, ) -> Result<R, DeadlockError>

Maps the contents with exclusive access. All observers will be notified at some point in the future if the value has been changed.

Provided Methods§

Source

fn map_mut<R>(&self, map: impl FnOnce(Mutable<'_, T>) -> R) -> R

Maps the contents with exclusive access. All observers will be notified at some point in the future if the value has been changed.

§Panics

This function panics if this value is already locked by the current thread.

Source

fn try_replace(&self, new_value: T) -> Result<T, ReplaceError<T>>
where T: PartialEq,

Replaces the contents with new_value if new_value is different than the currently stored value. If the value is updated, the previous contents are returned.

All observers will be notified at some point in the future if the value has been changed.

§Errors
Source

fn replace(&self, new_value: T) -> Option<T>
where T: PartialEq,

Replaces the contents with new_value, returning the previous contents. All observers will be notified at some point in the future if the value has been changed.

If the calling thread has exclusive access to the contents of this dynamic, this call will return None and the value will not be updated. If detecting this is important, use Self::try_replace().

§Replacing a new value without PartialEq

This function requires that the contained type implements PartialEq. One common problem with reactive data graphs is that they can be very “noisy”. Cushy attempts to minimize noise by only invoking callbacks when the value has changed, and it detects this by using PartialEq.

However, not all types implement PartialEq. map_mut() does not require PartialEq, and can be used along with std::mem::replace() to perform the same operation without checking for equality.

Source

fn set(&self, new_value: T)
where T: PartialEq,

Stores new_value in this dynamic. All observers will be notified at some point in the future if the value has been changed.

If the calling thread has exclusive access to the contents of this dynamic, this call will return None and the value will not be updated. If detecting this is important, use Self::try_replace().

§Setting a new value without PartialEq

This function requires that the contained type implements PartialEq. One common problem with reactive data graphs is that they can be very “noisy”. Cushy attempts to minimize noise by only invoking callbacks when the value has changed, and it detects this by using PartialEq.

However, not all types implement PartialEq. See force_set().

Source

fn force_set(&self, new_value: T)

Stores new_value in this dynamic without checking for equality.

All observers will be notified at some point that this dynamic’s contents have been changed.

Source

fn try_compare_swap( &self, expected_current: &T, new_value: T, ) -> Result<T, TryCompareSwapError<T>>
where T: Clone + PartialEq,

Replaces the current value with new_value if the current value is equal to expected_current.

Returns Ok with the overwritten value upon success.

§Errors
Source

fn compare_swap(&self, expected_current: &T, new_value: T) -> Result<T, T>
where T: Clone + PartialEq,

Replaces the current value with new_value if the current value is equal to expected_current.

Returns Ok with the overwritten value upon success.

§Errors

Returns Err with the currently stored value when expected_current does not match the currently stored value.

Source

fn toggle(&self) -> T
where T: Not<Output = T> + Clone,

Updates the value to the result of invoking Not on the current value. This function returns the new value.

Source

fn take(&self) -> T
where Self: Source<T>, T: Default,

Returns the currently stored value, replacing the current contents with T::default().

§Panics

This function panics if this value is already locked by the current thread.

Source

fn take_if_not_default(&self) -> Option<T>
where T: Default + PartialEq,

Checks if the currently stored value is different than T::default(), and if so, returns Some(self.take()).

§Panics

This function panics if this value is already locked by the current thread.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<S> Destination<<S as TrackedSource>::Value> for Tracked<S>
where S: TrackedSource + Destination<S::Value>,

Source§

impl<T> Destination<T> for Dynamic<T>

Source§

impl<T> Destination<T> for Owned<T>
where T: 'static,