From 1f8e2ec392b1d261acebda3fa9d81ea3f18c7e40 Mon Sep 17 00:00:00 2001 From: Sadika Sumanapala Date: Sat, 13 Jun 2020 22:20:21 +0530 Subject: [PATCH] Use same naming for Rhs as libcore/ops Use same naming scheme as libcore/ops --- src/ch19-03-advanced-traits.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ch19-03-advanced-traits.md b/src/ch19-03-advanced-traits.md index 3a0bfb12cc..d527bb67a5 100644 --- a/src/ch19-03-advanced-traits.md +++ b/src/ch19-03-advanced-traits.md @@ -116,30 +116,30 @@ The default generic type in this code is within the `Add` trait. Here is its definition: ```rust -trait Add { +trait Add { type Output; - fn add(self, rhs: RHS) -> Self::Output; + fn add(self, rhs: Rhs) -> Self::Output; } ``` This code should look generally familiar: a trait with one method and an -associated type. The new part is `RHS=Self`: this syntax is called *default -type parameters*. The `RHS` generic type parameter (short for “right hand +associated type. The new part is `Rhs=Self`: this syntax is called *default +type parameters*. The `Rhs` generic type parameter (short for “right hand side”) defines the type of the `rhs` parameter in the `add` method. If we don’t -specify a concrete type for `RHS` when we implement the `Add` trait, the type -of `RHS` will default to `Self`, which will be the type we’re implementing +specify a concrete type for `Rhs` when we implement the `Add` trait, the type +of `Rhs` will default to `Self`, which will be the type we’re implementing `Add` on. -When we implemented `Add` for `Point`, we used the default for `RHS` because we +When we implemented `Add` for `Point`, we used the default for `Rhs` because we wanted to add two `Point` instances. Let’s look at an example of implementing -the `Add` trait where we want to customize the `RHS` type rather than using the +the `Add` trait where we want to customize the `Rhs` type rather than using the default. We have two structs, `Millimeters` and `Meters`, holding values in different units. We want to add values in millimeters to values in meters and have the implementation of `Add` do the conversion correctly. We can implement `Add` for -`Millimeters` with `Meters` as the `RHS`, as shown in Listing 19-15. +`Millimeters` with `Meters` as the `Rhs`, as shown in Listing 19-15. Filename: src/lib.rs @@ -151,7 +151,7 @@ implementation of `Add` do the conversion correctly. We can implement `Add` for `Millimeters` to add `Millimeters` to `Meters` To add `Millimeters` and `Meters`, we specify `impl Add` to set the -value of the `RHS` type parameter instead of using the default of `Self`. +value of the `Rhs` type parameter instead of using the default of `Self`. You’ll use default type parameters in two main ways: