|
62 | 62 | //! }
|
63 | 63 | //! ```
|
64 | 64 | //!
|
65 |
| -//! See the documentation for each trait for a minimum implementation that |
66 |
| -//! prints something to the screen. |
| 65 | +//! See the documentation for each trait for an example implementation. |
67 | 66 |
|
68 | 67 | #![stable(feature = "rust1", since = "1.0.0")]
|
69 | 68 |
|
@@ -166,25 +165,38 @@ macro_rules! forward_ref_binop {
|
166 | 165 | ///
|
167 | 166 | /// # Examples
|
168 | 167 | ///
|
169 |
| -/// A trivial implementation of `Add`. When `Foo + Foo` happens, it ends up |
170 |
| -/// calling `add`, and therefore, `main` prints `Adding!`. |
| 168 | +/// This example creates a `Point` struct that implements the `Add` trait, and |
| 169 | +/// then demonstrates adding two `Point`s. |
171 | 170 | ///
|
172 | 171 | /// ```
|
173 | 172 | /// use std::ops::Add;
|
174 | 173 | ///
|
175 |
| -/// struct Foo; |
| 174 | +/// #[derive(Debug)] |
| 175 | +/// struct Point { |
| 176 | +/// x: i32, |
| 177 | +/// y: i32, |
| 178 | +/// } |
176 | 179 | ///
|
177 |
| -/// impl Add for Foo { |
178 |
| -/// type Output = Foo; |
| 180 | +/// impl Add for Point { |
| 181 | +/// type Output = Point; |
179 | 182 | ///
|
180 |
| -/// fn add(self, _rhs: Foo) -> Foo { |
181 |
| -/// println!("Adding!"); |
182 |
| -/// self |
| 183 | +/// fn add(self, other: Point) -> Point { |
| 184 | +/// Point { |
| 185 | +/// x: self.x + other.x, |
| 186 | +/// y: self.y + other.y, |
| 187 | +/// } |
| 188 | +/// } |
| 189 | +/// } |
| 190 | +/// |
| 191 | +/// impl PartialEq for Point { |
| 192 | +/// fn eq(&self, other: &Self) -> bool { |
| 193 | +/// self.x == other.x && self.y == other.y |
183 | 194 | /// }
|
184 | 195 | /// }
|
185 | 196 | ///
|
186 | 197 | /// fn main() {
|
187 |
| -/// Foo + Foo; |
| 198 | +/// assert_eq!(Point { x: 1, y: 0 } + Point { x: 2, y: 3 }, |
| 199 | +/// Point { x: 3, y: 3 }); |
188 | 200 | /// }
|
189 | 201 | /// ```
|
190 | 202 | #[lang = "add"]
|
|
0 commit comments