Skip to content

Commit

Permalink
Add more explanation of Self in chapter 10. Fixes #2222.
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed Nov 15, 2021
1 parent cb1eb1d commit ce926c0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ch10-02-traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@ lifetimes aren’t required to solve these challenges.
By using a trait bound with an `impl` block that uses generic type parameters,
we can implement methods conditionally for types that implement the specified
traits. For example, the type `Pair<T>` in Listing 10-16 always implements the
`new` function. But `Pair<T>` only implements the `cmp_display` method if its
`new` function to return a new instance of `Pair<T>` (recall from the
["Defining Methods"][methods] section of Chapter 5 that `Self` is a type alias
for the type of the `impl` block, which in this case is `Pair<T>`). But in the
next `impl` block, `Pair<T>` only implements the `cmp_display` method if its
inner type `T` implements the `PartialOrd` trait that enables comparison *and*
the `Display` trait that enables printing.

Expand Down Expand Up @@ -469,3 +472,4 @@ lifetimes do that.
ch04-01-what-is-ownership.html#stack-only-data-copy
[using-trait-objects-that-allow-for-values-of-different-types]:
ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types
[methods]: ch05-03-method-syntax.html#defining-methods

0 comments on commit ce926c0

Please sign in to comment.