pub trait Eq: PartialEq {
}Expand description
Trait for comparing type instances corresponding to equivalence relations.
The difference between [Eq] and [PartialEq] is the additional requirement for reflexivity.
[PartialEq] guarantees symmetry and transitivity, but not reflexivity.
E.g., a type that implements [PartialEq] guarantees that for all a, b, and c:
a == bimpliesb == a(symmetry)a == bandb == cimpliesa == c(transitivity)
[Eq], additionally implies:
a == afor everya(reflexivity)
Reflexivity property cannot be checked by the compiler, and therefore Eq
does not have any methods, but only [PartialEq] as a supertrait.
Implementing [Eq] for a type that does not have reflexivity property is a logic error.