Expand description
等价关系 等式比较的 Trait。
这意味着,除了 a == b
和 a != b
是严格的逆之外,相等必须是 (对于所有 a
,b
和 c
) :
- reflexive:
a == a
;
- 对称:
a == b
表示 b == a
; and
- 可传递的:
a == b
和 b == c
表示 a == c
。
编译器无法检查此属性,因此 Eq
表示 PartialEq
,并且没有其他方法。
该 trait 可以与 #[derive]
一起使用。
当 derived' 时,由于
Eq` 没有额外的方法,它只是通知编译器这是一个等价关系,而不是部分等价关系。
请注意,derive
策略要求所有字段均为 Eq
,这并不总是需要的。
如果您不能使用 derive
策略,请指定您的类型实现 Eq
,它没有方法:
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 {}
Run
impl<A, B, C, D> Eq for (A, B, C, D) where
C: Eq,
B: Eq,
A: Eq,
D: Eq + ?Sized,
[src]impl<A, B, C, D, E> Eq for (A, B, C, D, E) where
C: Eq,
E: Eq + ?Sized,
B: Eq,
A: Eq,
D: Eq,
[src]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,
[src]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,
[src]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,
[src]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,
[src]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,
[src]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,
[src]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,
[src]impl<Ret> Eq for extern "C" fn() -> Ret
1.4.0[src]impl<Ret> Eq for unsafe fn() -> Ret
1.4.0[src]impl<Ret> Eq for unsafe extern "C" fn() -> Ret
1.4.0[src]impl<Ret, A> Eq for extern "C" fn(A) -> Ret
1.4.0[src]impl<Ret, A> Eq for extern "C" fn(A, ...) -> Ret
1.4.0[src]impl<Ret, A> Eq for unsafe fn(A) -> Ret
1.4.0[src]impl<Ret, A> Eq for unsafe extern "C" fn(A) -> Ret
1.4.0[src]impl<Ret, A> Eq for unsafe extern "C" fn(A, ...) -> Ret
1.4.0[src]impl<Ret, A, B> Eq for fn(A, B) -> Ret
1.4.0[src]impl<Ret, A, B> Eq for extern "C" fn(A, B) -> Ret
1.4.0[src]impl<Ret, A, B> Eq for extern "C" fn(A, B, ...) -> Ret
1.4.0[src]impl<Ret, A, B> Eq for unsafe fn(A, B) -> Ret
1.4.0[src]impl<Ret, A, B> Eq for unsafe extern "C" fn(A, B) -> Ret
1.4.0[src]impl<Ret, A, B> Eq for unsafe extern "C" fn(A, B, ...) -> Ret
1.4.0[src]impl<Ret, A, B, C> Eq for fn(A, B, C) -> Ret
1.4.0[src]impl<Ret, A, B, C> Eq for extern "C" fn(A, B, C) -> Ret
1.4.0[src]impl<Ret, A, B, C> Eq for extern "C" fn(A, B, C, ...) -> Ret
1.4.0[src]impl<Ret, A, B, C> Eq for unsafe fn(A, B, C) -> Ret
1.4.0[src]impl<Ret, A, B, C> Eq for unsafe extern "C" fn(A, B, C) -> Ret
1.4.0[src]impl<Ret, A, B, C> Eq for unsafe extern "C" fn(A, B, C, ...) -> Ret
1.4.0[src]impl<Ret, A, B, C, D> Eq for fn(A, B, C, D) -> Ret
1.4.0[src]impl<Ret, A, B, C, D> Eq for extern "C" fn(A, B, C, D) -> Ret
1.4.0[src]impl<Ret, A, B, C, D> Eq for extern "C" fn(A, B, C, D, ...) -> Ret
1.4.0[src]impl<Ret, A, B, C, D> Eq for unsafe fn(A, B, C, D) -> Ret
1.4.0[src]impl<Ret, A, B, C, D> Eq for unsafe extern "C" fn(A, B, C, D) -> Ret
1.4.0[src]impl<Ret, A, B, C, D> Eq for unsafe extern "C" fn(A, B, C, D, ...) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E> Eq for fn(A, B, C, D, E) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E> Eq for extern "C" fn(A, B, C, D, E) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E> Eq for extern "C" fn(A, B, C, D, E, ...) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E> Eq for unsafe fn(A, B, C, D, E) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E> Eq for unsafe extern "C" fn(A, B, C, D, E) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E> Eq for unsafe extern "C" fn(A, B, C, D, E, ...) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E, F> Eq for fn(A, B, C, D, E, F) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E, F> Eq for extern "C" fn(A, B, C, D, E, F) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E, F> Eq for extern "C" fn(A, B, C, D, E, F, ...) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E, F> Eq for unsafe fn(A, B, C, D, E, F) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E, F> Eq for unsafe extern "C" fn(A, B, C, D, E, F) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E, F> Eq for unsafe extern "C" fn(A, B, C, D, E, F, ...) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E, F, G> Eq for fn(A, B, C, D, E, F, G) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E, F, G> Eq for extern "C" fn(A, B, C, D, E, F, G) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E, F, G> Eq for extern "C" fn(A, B, C, D, E, F, G, ...) -> Ret
1.4.0[src]impl<Ret, A, B, C, D, E, F, G> Eq for unsafe fn(A, B, C, D, E, F, G) -> Ret
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> 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 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 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 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 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 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 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 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 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 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]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]