Trait std::cmp::Eq 1.0.0[−][src]
pub trait Eq: PartialEq<Self> { }
Expand description
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
impliesb == a
; and - transitive:
a == b
andb == c
impliesa == c
.
This property cannot be checked by the compiler, and therefore Eq
implies
PartialEq
, and has no extra methods.
Derivable
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.
How can I implement Eq
?
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: &Self) -> bool {
self.isbn == other.isbn
}
}
impl Eq for Book {}
RunImplementations on Foreign Types
impl<K, V, S, A> Eq for HashMap<K, V, S, A> where
K: Eq + Hash,
V: Eq,
S: BuildHasher,
A: Allocator + Clone,
impl Eq for TryReserveError
Implementors
impl<A, B, C, D, E, F> Eq for (A, B, C, D, E, F) where
C: Eq,
F: Eq + ?Sized,
E: Eq,
B: Eq,
A: Eq,
D: Eq,
impl<A, B, C, D, E, F, G> Eq for (A, B, C, D, E, F, G) where
C: Eq,
F: Eq,
E: Eq,
B: Eq,
A: Eq,
G: Eq + ?Sized,
D: Eq,
impl<A, B, C, D, E, F, G, H> Eq for (A, B, C, D, E, F, G, H) where
C: Eq,
F: Eq,
E: Eq,
H: Eq + ?Sized,
B: Eq,
A: Eq,
G: Eq,
D: Eq,
impl<A, B, C, D, E, F, G, H, I> Eq for (A, B, C, D, E, F, G, H, I) where
C: Eq,
F: Eq,
I: Eq + ?Sized,
E: Eq,
H: Eq,
B: Eq,
A: Eq,
G: Eq,
D: Eq,
impl<A, B, C, D, E, F, G, H, I, J> Eq for (A, B, C, D, E, F, G, H, I, J) where
C: Eq,
F: Eq,
I: Eq,
E: Eq,
H: Eq,
B: Eq,
A: Eq,
J: Eq + ?Sized,
G: Eq,
D: Eq,
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
C: Eq,
F: Eq,
K: Eq + ?Sized,
I: Eq,
E: Eq,
H: Eq,
B: Eq,
A: Eq,
J: Eq,
G: Eq,
D: Eq,
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
C: Eq,
F: Eq,
K: Eq,
I: Eq,
E: Eq,
H: Eq,
B: Eq,
A: Eq,
J: Eq,
G: Eq,
D: Eq,
L: Eq + ?Sized,
impl<K, V, S> Eq for std::collections::hash_map::HashMap<K, V, S> where
K: Eq + Hash,
V: Eq,
S: BuildHasher,
1.4.0[src]
impl<Ret, A, B, C, D, E, F, G> Eq for unsafe extern "C" fn(A, B, C, D, E, F, G, ...) -> Ret
1.4.0[src]
impl<Ret, A, B, C, D, E, F, G, H> Eq for extern "C" fn(A, B, C, D, E, F, G, H, ...) -> Ret
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]
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
1.4.0[src]