[][src]Trait classific::EqClass

pub trait EqClass<T: ?Sized> {
    fn eq(&self, left: &T, right: &T) -> bool;

    fn and<N>(self, next: N) -> BothEq<T, Self, N>
    where
        Self: Sized,
        N: EqClass<T>
, { ... } }

Implementations define an equivalence class over the type T, which can be semantically different from PartialEq::eq.

By convention, the equivalence class should fulfill the following properties (for all a, b and c):

  • reflexive: a == a
  • symmetric: if a == b then b == a
  • transitive: if a == b and b == c then a == c

Examples

use classific::{EqClass, eq_by};

assert!(eq_by(|t: &(i8, i8)| t.1).eq(&(1, 2), &(2, 2)));

Required methods

fn eq(&self, left: &T, right: &T) -> bool

This method tests for left and right values to be equal.

Examples

use classific::{EqClass, natural_eq};

assert!(natural_eq().eq(&1, &1));
Loading content...

Provided methods

fn and<N>(self, next: N) -> BothEq<T, Self, N> where
    Self: Sized,
    N: EqClass<T>, 

This method returns an EqClass which is further refining the semantics of self.

Both self::eq and next::eq is called and the result is true if and only if both returned true.

Examples

use classific::{EqClass, eq_by};

assert!(eq_by(|t: &(i8, i8, i8)| t.0).and(eq_by(|t: &(i8, i8, i8)| t.1)).eq(&(1, 2, 3), &(1, 2, 1)));
Loading content...

Implementors

impl<S, T, F> EqClass<S> for EqBy<S, T, F> where
    S: ?Sized,
    T: PartialEq<T>,
    F: Fn(&S) -> T, 
[src]

impl<S, T, F, C> EqClass<S> for EqByWith<S, T, F, C> where
    S: ?Sized,
    T: PartialEq<T>,
    F: Fn(&S) -> T,
    C: EqClass<T>, 
[src]

impl<S, T: ?Sized, F> EqClass<S> for EqByRef<S, T, F> where
    S: ?Sized,
    T: PartialEq<T>,
    F: Fn(&S) -> &T, 
[src]

impl<S, T: ?Sized, F, C> EqClass<S> for EqByRefWith<S, T, F, C> where
    S: ?Sized,
    T: PartialEq<T>,
    F: Fn(&S) -> &T,
    C: EqClass<T>, 
[src]

impl<T, C> EqClass<T> for EqByCmp<T, C> where
    T: ?Sized,
    C: Comparator<T>, 
[src]

impl<T, C, N> EqClass<T> for BothEq<T, C, N> where
    T: ?Sized,
    C: EqClass<T>,
    N: EqClass<T>, 
[src]

impl<T, F> EqClass<T> for F where
    T: ?Sized,
    F: Fn(&T, &T) -> bool
[src]

impl<T: ?Sized> EqClass<T> for EqByHash<T> where
    T: Hash
[src]

impl<T: ?Sized> EqClass<T> for NaturalEq<T> where
    T: PartialEq<T>, 
[src]

impl<T: ?Sized> EqClass<T> for PartialEqClass<T> where
    T: PartialEq<T>, 
[src]

Loading content...