Skip to content

Commit 814ff9f

Browse files
committed
---
yaml --- r: 223173 b: refs/heads/auto c: 4277369 h: refs/heads/master i: 223171: 0bf5d23 v: v3
1 parent 83d0b2c commit 814ff9f

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 556b0815d779a50a151c44032febf3ce253e621e
11+
refs/heads/auto: 427736931bb1cd34c97e4e1f79a5a84430415207
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/doc/trpl/generics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Generics are called ‘parametric polymorphism’ in type theory,
66
which means that they are types or functions that have multiple forms (‘poly’
77
is multiple, ‘morph’ is form) over a given parameter (‘parametric’).
88

9-
Anyway, enough with type theory, let’s check out some generic code. Rust’s
9+
Anyway, enough type theory, let’s check out some generic code. Rust’s
1010
standard library provides a type, `Option<T>`, that’s generic:
1111

1212
```rust
@@ -27,7 +27,7 @@ let x: Option<i32> = Some(5);
2727

2828
In the type declaration, we say `Option<i32>`. Note how similar this looks to
2929
`Option<T>`. So, in this particular `Option`, `T` has the value of `i32`. On
30-
the right-hand side of the binding, we do make a `Some(T)`, where `T` is `5`.
30+
the right-hand side of the binding, we make a `Some(T)`, where `T` is `5`.
3131
Since that’s an `i32`, the two sides match, and Rust is happy. If they didn’t
3232
match, we’d get an error:
3333

branches/auto/src/doc/trpl/traits.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ As you can see, the `trait` block looks very similar to the `impl` block,
4747
but we don’t define a body, just a type signature. When we `impl` a trait,
4848
we use `impl Trait for Item`, rather than just `impl Item`.
4949

50-
We can use traits to constrain our generics. Consider this function, which
51-
does not compile:
50+
## Traits bounds for generic functions
51+
52+
Traits are useful because they allow a type to make certain promises about its
53+
behavior. Generic functions can exploit this to constrain the types they
54+
accept. Consider this function, which does not compile:
5255

5356
```rust,ignore
5457
fn print_area<T>(shape: T) {
@@ -75,7 +78,7 @@ fn print_area<T: HasArea>(shape: T) {
7578
}
7679
```
7780

78-
The syntax `<T: HasArea>` means `any type that implements the HasArea trait`.
81+
The syntax `<T: HasArea>` means any type that implements the `HasArea` trait.”
7982
Because traits define function type signatures, we can be sure that any type
8083
which implements `HasArea` will have an `.area()` method.
8184

@@ -154,8 +157,8 @@ error: the trait `HasArea` is not implemented for the type `_` [E0277]
154157

155158
## Traits bounds for generic structs
156159

157-
Trait constraints also can apply to implementations for generic structs. Just
158-
append the constraint when you declare type parameters. Here is a new type
160+
Your generic structs can also benefit from trait constraints. All you need to
161+
do is append the constraint when you declare type parameters. Here is a new
159162
type `Rectangle<T>` and its operation `is_square()`:
160163

161164
```rust
@@ -232,7 +235,7 @@ impl HasArea for i32 {
232235
It is considered poor style to implement methods on such primitive types, even
233236
though it is possible.
234237

235-
This may seem like the Wild West, but there are two other restrictions around
238+
This may seem like the Wild West, but there are two restrictions around
236239
implementing traits that prevent this from getting out of hand. The first is
237240
that if the trait isn’t defined in your scope, it doesn’t apply. Here’s an
238241
example: the standard library provides a [`Write`][write] trait which adds
@@ -397,10 +400,10 @@ This shows off the additional feature of `where` clauses: they allow bounds
397400
where the left-hand side is an arbitrary type (`i32` in this case), not just a
398401
plain type parameter (like `T`).
399402

400-
## Default methods
403+
# Default methods
401404

402-
There’s one last feature of traits we should cover: default methods. It’s
403-
easiest just to show an example:
405+
If you already know how a typical implementor will define a method, you can
406+
let your trait supply a default:
404407

405408
```rust
406409
trait Foo {

0 commit comments

Comments
 (0)