SoftEq

Trait SoftEq 

Source
pub trait SoftEq
where 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§

Source

type Uid: Eq + Clone

The type of the hard part

Required Methods§

Source

fn uid(&self) -> Self::Uid

The hard part of self

Provided Methods§

Source

fn se(&self, other: &Self) -> bool

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

Source

fn nse(&self, other: &Self) -> bool

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

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.

Implementations on Foreign Types§

Source§

impl SoftEq for bool

Source§

type Uid = bool

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for i8

Source§

type Uid = i8

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for i16

Source§

type Uid = i16

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for i32

Source§

type Uid = i32

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for i64

Source§

type Uid = i64

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for i128

Source§

type Uid = i128

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for isize

Source§

type Uid = isize

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for u8

Source§

type Uid = u8

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for u16

Source§

type Uid = u16

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for u32

Source§

type Uid = u32

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for u64

Source§

type Uid = u64

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for u128

Source§

type Uid = u128

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for ()

Source§

type Uid = ()

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for usize

Source§

type Uid = usize

Source§

fn uid(&self) -> Self::Uid

Source§

impl SoftEq for String

Source§

type Uid = String

Source§

fn uid(&self) -> Self::Uid

Implementors§