|
20 | 20 | /// }
|
21 | 21 | ///
|
22 | 22 | /// impl Add for Point {
|
23 |
| -/// type Output = Point; |
| 23 | +/// type Output = Self; |
24 | 24 | ///
|
25 |
| -/// fn add(self, other: Point) -> Point { |
26 |
| -/// Point { |
| 25 | +/// fn add(self, other: Self) -> Self { |
| 26 | +/// Self { |
27 | 27 | /// x: self.x + other.x,
|
28 | 28 | /// y: self.y + other.y,
|
29 | 29 | /// }
|
|
50 | 50 | ///
|
51 | 51 | /// // Notice that the implementation uses the associated type `Output`.
|
52 | 52 | /// impl<T: Add<Output = T>> Add for Point<T> {
|
53 |
| -/// type Output = Point<T>; |
| 53 | +/// type Output = Self; |
54 | 54 | ///
|
55 |
| -/// fn add(self, other: Point<T>) -> Point<T> { |
56 |
| -/// Point { |
| 55 | +/// fn add(self, other: Self) -> Self::Output { |
| 56 | +/// Self { |
57 | 57 | /// x: self.x + other.x,
|
58 | 58 | /// y: self.y + other.y,
|
59 | 59 | /// }
|
@@ -158,9 +158,9 @@ add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
158 | 158 | ///
|
159 | 159 | /// // Notice that the implementation uses the associated type `Output`.
|
160 | 160 | /// impl<T: Sub<Output = T>> Sub for Point<T> {
|
161 |
| -/// type Output = Point<T>; |
| 161 | +/// type Output = Self; |
162 | 162 | ///
|
163 |
| -/// fn sub(self, other: Point<T>) -> Point<T> { |
| 163 | +/// fn sub(self, other: Self) -> Self::Output { |
164 | 164 | /// Point {
|
165 | 165 | /// x: self.x - other.x,
|
166 | 166 | /// y: self.y - other.y,
|
@@ -280,9 +280,9 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
280 | 280 | /// struct Vector { value: Vec<usize> }
|
281 | 281 | ///
|
282 | 282 | /// impl Mul<Scalar> for Vector {
|
283 |
| -/// type Output = Vector; |
| 283 | +/// type Output = Self; |
284 | 284 | ///
|
285 |
| -/// fn mul(self, rhs: Scalar) -> Vector { |
| 285 | +/// fn mul(self, rhs: Scalar) -> Self::Output { |
286 | 286 | /// Vector { value: self.value.iter().map(|v| v * rhs.value).collect() }
|
287 | 287 | /// }
|
288 | 288 | /// }
|
@@ -364,7 +364,7 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
364 | 364 | /// // The division of rational numbers is a closed operation.
|
365 | 365 | /// type Output = Self;
|
366 | 366 | ///
|
367 |
| -/// fn div(self, rhs: Self) -> Self { |
| 367 | +/// fn div(self, rhs: Self) -> Self::Output { |
368 | 368 | /// if rhs.nominator == 0 {
|
369 | 369 | /// panic!("Cannot divide by zero-valued `Rational`!");
|
370 | 370 | /// }
|
@@ -404,9 +404,9 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
404 | 404 | /// struct Vector { value: Vec<f32> }
|
405 | 405 | ///
|
406 | 406 | /// impl Div<Scalar> for Vector {
|
407 |
| -/// type Output = Vector; |
| 407 | +/// type Output = Self; |
408 | 408 | ///
|
409 |
| -/// fn div(self, rhs: Scalar) -> Vector { |
| 409 | +/// fn div(self, rhs: Scalar) -> Self::Output { |
410 | 410 | /// Vector { value: self.value.iter().map(|v| v / rhs.value).collect() }
|
411 | 411 | /// }
|
412 | 412 | /// }
|
@@ -485,9 +485,9 @@ div_impl_float! { f32 f64 }
|
485 | 485 | /// }
|
486 | 486 | ///
|
487 | 487 | /// impl<'a, T> Rem<usize> for SplitSlice<'a, T> {
|
488 |
| -/// type Output = SplitSlice<'a, T>; |
| 488 | +/// type Output = Self; |
489 | 489 | ///
|
490 |
| -/// fn rem(self, modulus: usize) -> Self { |
| 490 | +/// fn rem(self, modulus: usize) -> Self::Output { |
491 | 491 | /// let len = self.slice.len();
|
492 | 492 | /// let rem = len % modulus;
|
493 | 493 | /// let start = len - rem;
|
@@ -571,7 +571,7 @@ rem_impl_float! { f32 f64 }
|
571 | 571 | /// impl Neg for Sign {
|
572 | 572 | /// type Output = Sign;
|
573 | 573 | ///
|
574 |
| -/// fn neg(self) -> Sign { |
| 574 | +/// fn neg(self) -> Self::Output { |
575 | 575 | /// match self {
|
576 | 576 | /// Sign::Negative => Sign::Positive,
|
577 | 577 | /// Sign::Zero => Sign::Zero,
|
@@ -650,8 +650,8 @@ neg_impl_numeric! { isize i8 i16 i32 i64 i128 f32 f64 }
|
650 | 650 | /// }
|
651 | 651 | ///
|
652 | 652 | /// impl AddAssign for Point {
|
653 |
| -/// fn add_assign(&mut self, other: Point) { |
654 |
| -/// *self = Point { |
| 653 | +/// fn add_assign(&mut self, other: Self) { |
| 654 | +/// *self = Self { |
655 | 655 | /// x: self.x + other.x,
|
656 | 656 | /// y: self.y + other.y,
|
657 | 657 | /// };
|
@@ -706,8 +706,8 @@ add_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
706 | 706 | /// }
|
707 | 707 | ///
|
708 | 708 | /// impl SubAssign for Point {
|
709 |
| -/// fn sub_assign(&mut self, other: Point) { |
710 |
| -/// *self = Point { |
| 709 | +/// fn sub_assign(&mut self, other: Self) { |
| 710 | +/// *self = Self { |
711 | 711 | /// x: self.x - other.x,
|
712 | 712 | /// y: self.y - other.y,
|
713 | 713 | /// };
|
|
0 commit comments