cushy::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 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. Before returning from this function, all observers will be notified that the contents have been updated.

Provided Methods§

source

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

Maps the contents with exclusive access. Before returning from this function, all observers will be notified that the contents have been updated.

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

Before returning from this function, all observers will be notified that the contents have been updated.

§Errors
source

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

Replaces the contents with new_value, returning the previous contents. Before returning from this function, all observers will be notified that the contents have been updated.

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. Before returning from this function, all observers will be notified that the contents have been updated.

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. map_mut() does not require PartialEq, and will invoke change callbacks after accessing exclusively.

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.

Object Safety§

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,