Skip to content

Commit

Permalink
Adding notes about non-PartialEq types
Browse files Browse the repository at this point in the history
Refs #171
  • Loading branch information
ecton committed Oct 3, 2024
1 parent 2045d5f commit a73dd0f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,18 @@ pub trait Destination<T> {
/// 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()`](Self::map_mut) does not require `PartialEq`, and can be
/// used along with [`std::mem::replace()`] to perform the same operation
/// without checking for equality.
fn replace(&self, new_value: T) -> Option<T>
where
T: PartialEq,
Expand All @@ -471,6 +483,17 @@ pub trait Destination<T> {
/// 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()`](Self::map_mut) does not require `PartialEq`, and will
/// invoke change callbacks after accessing exclusively.
fn set(&self, new_value: T)
where
T: PartialEq,
Expand Down

0 comments on commit a73dd0f

Please sign in to comment.