pub trait SoftEq where
    Self: Sized
{ type Uid: Eq; fn uid(&self) -> Self::Uid; fn se(&self, other: &Self) -> bool { ... } fn nse(&self, other: &Self) -> bool { ... } }
Expand description

Define soft (partial) equality

Two elements are “softly equals” if they can be considered as two different stages of the same element, i.e. their hard parts are equals (c.f. below) This is mainly used by the Vec implementation of Mutable, to determine when an item as mutated

We can distinguish two parts of a SoftEq element:

  • the hard part, which is unique for each element (a uid String, for example)
  • the soft part, which may variate for the same element (like a charge attribute for an electrical item)
#[derive(SoftEq)]
struct Item {
    #[softeq(uid)]
    id: String,
    charge: usize,
}

let i0 = Item { id: "tear".to_string(), charge: 32 };
let i1 = Item { id: "tear".to_string(), charge: 12 };
let i2 = Item { id: "draktaar".to_string(), charge: 32 };

assert!(i0.se(&i1));
assert!(i0.nse(&i2));
assert!(i1.nse(&i2));

Required Associated Types

The type of the hard part

Required Methods

The hard part of self

Provided Methods

Whether self and other are softly equals (their hard part is identical)

Whether self and other are softly different (their hard part differs)

Implementors