[−][src]Trait yewtil::NeqAssignBy
Blanket trait to provide a convenience method for assigning props in changed
or updating values in update
.
Like neq_assign
, but for cases where self
doesn't impl PartialEq
or a nonstandard equality comparison is needed.
Useful for Result<T, E: !PartialEq>
.
Required methods
fn neq_assign_by<F>(&mut self, new: NEW, eq: F) -> ShouldRender where
F: FnOnce(&NEW, &NEW) -> bool,
F: FnOnce(&NEW, &NEW) -> bool,
#[derive(Clone, Debug)] struct NonComparableError; fn eq_by_ok<T, E>(a: &Result<T, E>, b: &Result<T, E>) -> bool where T: PartialEq, { match (a, b) { (Ok(_), Err(_)) | (Err(_), Ok(_)) | (Err(_), Err(_)) => false, (Ok(a), Ok(b)) => a == b, } } let mut foo: Result<u32, NonComparableError> = Ok(1); // Won't compile // assert_eq!(foo.neq_assign(Ok(42)), true) assert_eq!(foo.neq_assign_by(Ok(42), eq_by_ok), true); assert_eq!(foo.clone().unwrap(), 42); assert_eq!(foo.neq_assign_by(Err(NonComparableError), eq_by_ok), true); assert!(foo.is_err()); // The tradeoff: all assignments of an `Err` value will count as updates, even if they are // "the same" for all practical intents and purposes. assert_eq!(foo.neq_assign_by(Err(NonComparableError), eq_by_ok), true); assert_eq!(foo.neq_assign_by(Err(NonComparableError), eq_by_ok), true); assert_eq!(foo.neq_assign_by(Err(NonComparableError), eq_by_ok), true);
Implementors
impl<T: BorrowMut<U>, U> NeqAssignBy<U> for T
[src]
fn neq_assign_by<F>(&mut self, new: U, eq: F) -> ShouldRender where
F: FnOnce(&U, &U) -> bool,
[src]
F: FnOnce(&U, &U) -> bool,