mirror of https://github.com/rust-lang/book
Snapshot of chapter 10
This commit is contained in:
parent
1b87460130
commit
3c2ca8528c
File diff suppressed because it is too large
Load Diff
|
@ -411,11 +411,11 @@ 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 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.
|
||||
[”Defining Methods”][methods]<!-- ignore --> 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.
|
||||
|
||||
<span class="filename">Filename: src/lib.rs</span>
|
||||
|
||||
|
|
Loading…
Reference in New Issue