File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -126,9 +126,32 @@ pub trait PartialEq<Rhs: ?Sized = Self> {
126
126
/// This property cannot be checked by the compiler, and therefore `Eq` implies
127
127
/// `PartialEq`, and has no extra methods.
128
128
///
129
+ /// ## Derivable
130
+ ///
129
131
/// This trait can be used with `#[derive]`. When `derive`d, because `Eq` has
130
132
/// no extra methods, it is only informing the compiler that this is an
131
- /// equivalence relation rather than a partial equivalence relation.
133
+ /// equivalence relation rather than a partial equivalence relation. Note that
134
+ /// the `derive` strategy requires all fields are `PartialEq`, which isn't
135
+ /// always desired.
136
+ ///
137
+ /// ## How can I implement `Eq`?
138
+ ///
139
+ /// If you cannot use the `derive` strategy, specify that your type implements
140
+ /// `Eq`, which has no methods:
141
+ ///
142
+ /// ```
143
+ /// enum BookFormat { Paperback, Hardback, Ebook }
144
+ /// struct Book {
145
+ /// isbn: i32,
146
+ /// format: BookFormat,
147
+ /// }
148
+ /// impl PartialEq for Book {
149
+ /// fn eq(&self, other: &Self) -> bool {
150
+ /// self.isbn == other.isbn
151
+ /// }
152
+ /// }
153
+ /// impl Eq for Book {}
154
+ /// ```
132
155
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
133
156
pub trait Eq : PartialEq < Self > {
134
157
// FIXME #13101: this method is used solely by #[deriving] to
You can’t perform that action at this time.
0 commit comments