Trait for equality comparisons which are equivalence relations.
This means, that in addition to a == b
and a != b
being strict inverses, the equality must
be (for all a
, b
and c
):
- reflexive:
a == a
;
- symmetric:
a == b
implies b == a
; and
- transitive:
a == b
and b == c
implies a == c
.
This property cannot be checked by the compiler, and therefore Eq
implies
PartialEq
, and has no extra methods.
This trait can be used with #[derive]
. When derive
d, because Eq
has
no extra methods, it is only informing the compiler that this is an
equivalence relation rather than a partial equivalence relation. Note that
the derive
strategy requires all fields are Eq
, which isn't
always desired.
If you cannot use the derive
strategy, specify that your type implements
Eq
, which has no methods:
enum BookFormat { Paperback, Hardback, Ebook }
struct Book {
isbn: i32,
format: BookFormat,
}
impl PartialEq for Book {
fn eq(&self, other: &Book) -> bool {
self.isbn == other.isbn
}
}
impl Eq for Book {}
impl<Ret, A, B, C, D, E, F> Eq for extern "C" fn(A, B, C, D, E, F) -> Ret | |
impl<T> Eq for [T; 22] where T: Eq, | |
impl<Ret, A, B, C> Eq for unsafe extern "C" fn(A, B, C, ...) -> Ret | |
impl<T> Eq for [T; 14] where T: Eq, | |
impl<T> Eq for [T; 18] where T: Eq, | |
impl<T> Eq for [T; 1] where T: Eq, | |
impl<Ret, A, B, C, D> Eq for fn(A, B, C, D) -> Ret | |
impl<'a, A> Eq for &'a mut A where A: Eq + ?Sized, | |
impl<Ret, A, B, C, D, E, F, G> Eq for fn(A, B, C, D, E, F, G) -> Ret | |
impl<Ret, A> Eq for extern "C" fn(A) -> Ret | |
impl<Ret, A, B, C, D, E> Eq for extern "C" fn(A, B, C, D, E) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for fn(A, B, C, D, E, F, G, H, I, J) -> Ret | |
impl<Ret, A, B> Eq for unsafe extern "C" fn(A, B) -> Ret | |
impl<'a, A> Eq for &'a A where A: Eq + ?Sized, | |
impl<Ret, A, B, C, D, E, F, G> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G, ...) -> Ret | |
impl<A, B, C, D> Eq for (A, B, C, D) where A: Eq, B: Eq, C: Eq, D: Eq + ?Sized, | |
impl<Ret, A, B, C, D, E> Eq for unsafe fn(A, B, C, D, E) -> Ret | |
impl<T> Eq for [T; 30] where T: Eq, | |
impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G, H, I, J) -> Ret | |
impl<T> Eq for [T; 16] where T: Eq, | |
impl<Ret, A, B, C, D, E, F> Eq for unsafe extern "C" fn(A, B, C, D, E, F) -> Ret | |
impl<A, B, C, D, E, F, G, H, I, J, K> Eq for (A, B, C, D, E, F, G, H, I, J, K) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq, J: Eq, K: Eq + ?Sized, | |
impl<T> Eq for [T; 20] where T: Eq, | |
impl<Ret, A, B, C, D> Eq for extern "C" fn(A, B, C, D) -> Ret | |
impl<Ret, A, B> Eq for unsafe fn(A, B) -> Ret | |
impl<T> Eq for Bound<T> where T: Eq, | |
impl<A, B, C> Eq for (A, B, C) where A: Eq, B: Eq, C: Eq + ?Sized, | |
impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for extern "C" fn(A, B, C, D, E, F, G, H, I, J, K, L, ...) -> Ret | |
impl<T> Eq for [T; 29] where T: Eq, | |
impl<Ret, A, B, C, D, E, F, G, H> Eq for fn(A, B, C, D, E, F, G, H) -> Ret | |
impl<A, B, C, D, E, F, G, H, I, J> Eq for (A, B, C, D, E, F, G, H, I, J) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq, J: Eq + ?Sized, | |
impl<A> Eq for (A,) where A: Eq + ?Sized, | |
impl<T> Eq for [T; 5] where T: Eq, | |
impl<T> Eq for [T; 2] where T: Eq, | |
impl<T> Eq for [T; 12] where T: Eq, | |
impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for fn(A, B, C, D, E, F, G, H, I, J, K) -> Ret | |
impl<A, B> Eq for (A, B) where A: Eq, B: Eq + ?Sized, | |
impl<T, E> Eq for Result<T, E> where E: Eq, T: Eq, | |
impl<T> Eq for [T; 8] where T: Eq, | |
impl<T> Eq for [T; 3] where T: Eq, | |
impl<Ret, A, B, C, D, E> Eq for extern "C" fn(A, B, C, D, E, ...) -> Ret | |
impl<Ret, A, B, C> Eq for unsafe extern "C" fn(A, B, C) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G, H, I, J, ...) -> Ret | |
impl<T> Eq for [T; 4] where T: Eq, | |
impl<Ret, A, B, C, D, E, F, G> Eq for unsafe fn(A, B, C, D, E, F, G) -> Ret | |
impl<T> Eq for [T; 0] where T: Eq, | |
impl<Ret, A, B, C, D, E, F, G, H, I> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G, H, I, ...) -> Ret | |
impl<T> Eq for [T; 32] where T: Eq, | |
impl<Ret, A, B, C, D, E, F, G> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G) -> Ret | |
impl<Idx> Eq for Range<Idx> where Idx: Eq, | |
impl<Ret, A, B, C, D, E, F, G, H, I> Eq for unsafe fn(A, B, C, D, E, F, G, H, I) -> Ret | |
impl<T> Eq for [T; 19] where T: Eq, | |
impl<Ret, A> Eq for extern "C" fn(A, ...) -> Ret | |
impl<T> Eq for [T] where T: Eq, | |
impl<Ret, A, B, C, D, E> Eq for unsafe extern "C" fn(A, B, C, D, E) -> Ret | |
impl<Ret, A, B, C, D> Eq for unsafe extern "C" fn(A, B, C, D) -> Ret | |
impl<T> Eq for [T; 9] where T: Eq, | |
impl<Ret> Eq for fn() -> Ret | |
impl<Ret> Eq for unsafe extern "C" fn() -> Ret | |
impl<Ret, A> Eq for fn(A) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G, H) -> Ret | |
impl<Ret, A, B, C, D> Eq for unsafe extern "C" fn(A, B, C, D, ...) -> Ret | |
impl<Ret, A, B, C> Eq for unsafe fn(A, B, C) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I> Eq for extern "C" fn(A, B, C, D, E, F, G, H, I, ...) -> Ret | |
impl<T> Eq for [T; 31] where T: Eq, | |
impl<T> Eq for [T; 15] where T: Eq, | |
impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for extern "C" fn(A, B, C, D, E, F, G, H, I, J) -> Ret | |
impl<Ret> Eq for extern "C" fn() -> Ret | |
impl<Ret, A, B, C> Eq for fn(A, B, C) -> Ret | |
impl<Ret, A> Eq for unsafe fn(A) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for extern "C" fn(A, B, C, D, E, F, G, H, I, J, K, ...) -> Ret | |
impl<T> Eq for [T; 27] where T: Eq, | |
impl<Ret, A, B, C, D, E, F, G, H, I> Eq for extern "C" fn(A, B, C, D, E, F, G, H, I) -> Ret | |
impl<Ret, A, B> Eq for unsafe extern "C" fn(A, B, ...) -> Ret | |
impl<T> Eq for [T; 7] where T: Eq, | |
impl<Ret, A, B, C, D, E, F, G, H> Eq for extern "C" fn(A, B, C, D, E, F, G, H, ...) -> Ret | |
impl<Ret, A> Eq for unsafe extern "C" fn(A) -> Ret | |
impl<Ret, A, B, C, D, E, F, G> Eq for extern "C" fn(A, B, C, D, E, F, G, ...) -> Ret | |
impl<Ret, A, B> Eq for extern "C" fn(A, B) -> Ret | |
impl<Ret, A, B, C> Eq for extern "C" fn(A, B, C, ...) -> Ret | |
impl<A, B, C, D, E, F> Eq for (A, B, C, D, E, F) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq + ?Sized, | |
impl<Ret, A, B, C> Eq for extern "C" fn(A, B, C) -> Ret | |
impl<A, B, C, D, E> Eq for (A, B, C, D, E) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq + ?Sized, | |
impl<T> Eq for [T; 25] where T: Eq, | |
impl<T> Eq for [T; 21] where T: Eq, | |
impl<Ret, A, B, C, D, E, F> Eq for fn(A, B, C, D, E, F) -> Ret | |
impl<T> Eq for [T; 23] where T: Eq, | |
impl<T> Eq for [T; 13] where T: Eq, | |
impl<T> Eq for [T; 28] where T: Eq, | |
impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for extern "C" fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Ret | |
impl<Ret, A, B> Eq for extern "C" fn(A, B, ...) -> Ret | |
impl<A, B, C, D, E, F, G, H> Eq for (A, B, C, D, E, F, G, H) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq + ?Sized, | |
impl<T> Eq for [T; 24] where T: Eq, | |
impl<A, B, C, D, E, F, G> Eq for (A, B, C, D, E, F, G) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq + ?Sized, | |
impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Ret | |
impl<T> Eq for *mut T where T: ?Sized, | |
impl<Ret, A, B, C, D, E> Eq for unsafe extern "C" fn(A, B, C, D, E, ...) -> Ret | |
impl<Ret, A, B, C, D> Eq for unsafe fn(A, B, C, D) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G, H, ...) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G, H, I, J, K, ...) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H> Eq for extern "C" fn(A, B, C, D, E, F, G, H) -> Ret | |
impl<Ret, A, B, C, D, E, F> Eq for unsafe extern "C" fn(A, B, C, D, E, F, ...) -> Ret | |
impl<T> Eq for *const T where T: ?Sized, | |
impl<Ret> Eq for unsafe fn() -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Ret | |
impl<A, B, C, D, E, F, G, H, I, J, K, L> Eq for (A, B, C, D, E, F, G, H, I, J, K, L) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq, J: Eq, K: Eq, L: Eq + ?Sized, | |
impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G, H, I, J, K) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G, H, I) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for extern "C" fn(A, B, C, D, E, F, G, H, I, J, ...) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for extern "C" fn(A, B, C, D, E, F, G, H, I, J, K) -> Ret | |
impl<A, B, C, D, E, F, G, H, I> Eq for (A, B, C, D, E, F, G, H, I) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq + ?Sized, | |
impl<Ret, A, B, C, D> Eq for extern "C" fn(A, B, C, D, ...) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for unsafe fn(A, B, C, D, E, F, G, H, I, J, K) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I> Eq for fn(A, B, C, D, E, F, G, H, I) -> Ret | |
impl<Ret, A, B, C, D, E> Eq for fn(A, B, C, D, E) -> Ret | |
impl<Ret, A, B, C, D, E, F, G> Eq for extern "C" fn(A, B, C, D, E, F, G) -> Ret | |
impl<Ret, A, B, C, D, E, F> Eq for unsafe fn(A, B, C, D, E, F) -> Ret | |
impl<Ret, A> Eq for unsafe extern "C" fn(A, ...) -> Ret | |
impl<T> Eq for [T; 6] where T: Eq, | |
impl<T> Eq for [T; 11] where T: Eq, | |
impl<Ret, A, B, C, D, E, F, G, H> Eq for unsafe fn(A, B, C, D, E, F, G, H) -> Ret | |
impl<Ret, A, B> Eq for fn(A, B) -> Ret | |
impl<T> Eq for [T; 10] where T: Eq, | |
impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G, H, I, J, K, L, ...) -> Ret | |
impl<T> Eq for [T; 17] where T: Eq, | |
impl<Ret, A, B, C, D, E, F> Eq for extern "C" fn(A, B, C, D, E, F, ...) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for unsafe fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Ret | |
impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for unsafe fn(A, B, C, D, E, F, G, H, I, J) -> Ret | |
impl<T> Eq for [T; 26] where T: Eq, | |
impl<T> Eq for Vec<T> where T: Eq, | |