Vergleich
These traits support comparisons between values. All traits can be derived for types containing fields that implement these traits.
PartialEq
and Eq
PartialEq
is a partial equivalence relation, with required method eq
and provided method ne
. The ==
and !=
operators will call these methods.
Eq
is a full equivalence relation (reflexive, symmetric, and transitive) and implies PartialEq
. Functions that require full equivalence will use Eq
as a trait bound.
PartialOrd
and Ord
PartialOrd
defines a partial ordering, with a partial_cmp
method. It is used to implement the <
, <=
, >=
, and >
operators.
Ord
is a total ordering, with cmp
returning Ordering
.
Speaker Notes
This slide should take about 5 minutes.
PartialEq
can be implemented between different types, but Eq
cannot, because it is reflexive:
In practice, it's common to derive these traits, but uncommon to implement them.