Skip to content

Commit 00c1419

Browse files
committed
Define bounds in glossary.md
1 parent 509bec8 commit 00c1419

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/doc/trpl/glossary.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ let z = (8, 2, 6);
3838

3939
In the example above `x` and `y` have arity 2. `z` has arity 3.
4040

41+
### Bounds
42+
43+
Bounds are constraints on a type or [trait][traits]. For example, if a bound
44+
is placed on the argument a function takes, types passed to that function
45+
must abide by that constraint.
46+
47+
[traits]: traits.html
48+
4149
### DST (Dynamically Sized Type)
4250

4351
A type without a statically known size or alignment. ([more info][link])

src/doc/trpl/traits.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ 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-
## Trait constraints on generic functions
50+
## Trait bounds on generic functions
5151

5252
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
53+
behavior. Generic functions can exploit this to constrain, or [bound][bounds], the types they
5454
accept. Consider this function, which does not compile:
5555

56+
[bounds]: glossary.html#bounds
57+
5658
```rust,ignore
5759
fn print_area<T>(shape: T) {
5860
println!("This shape has an area of {}", shape.area());
@@ -66,7 +68,7 @@ error: no method named `area` found for type `T` in the current scope
6668
```
6769

6870
Because `T` can be any type, we can’t be sure that it implements the `area`
69-
method. But we can add a trait constraint’ to our generic `T`, ensuring
71+
method. But we can add a trait bound to our generic `T`, ensuring
7072
that it does:
7173

7274
```rust
@@ -155,10 +157,10 @@ We get a compile-time error:
155157
error: the trait `HasArea` is not implemented for the type `_` [E0277]
156158
```
157159

158-
## Trait constraints on generic structs
160+
## Trait bounds on generic structs
159161

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
162+
Your generic structs can also benefit from trait bounds. All you need to
163+
do is append the bound when you declare type parameters. Here is a new
162164
type `Rectangle<T>` and its operation `is_square()`:
163165

164166
```rust

0 commit comments

Comments
 (0)