pub trait SoftEqwhere
Self: Sized,{
type Uid: Eq + Clone;
// Required method
fn uid(&self) -> Self::Uid;
// Provided methods
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§
Required Methods§
Provided Methods§
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.