@@ -47,12 +47,14 @@ As you can see, the `trait` block looks very similar to the `impl` block,
4747but we don’t define a body, just a type signature. When we ` impl ` a trait,
4848we use ` impl Trait for Item ` , rather than just ` impl Item ` .
4949
50- ## Trait constraints on generic functions
50+ ## Trait bounds on generic functions
5151
5252Traits 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
5454accept. Consider this function, which does not compile:
5555
56+ [ bounds ] : glossary.html#bounds
57+
5658``` rust,ignore
5759fn 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
6870Because ` 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
7072that it does:
7173
7274``` rust
@@ -155,10 +157,10 @@ We get a compile-time error:
155157error: 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
162164type ` Rectangle<T> ` and its operation ` is_square() ` :
163165
164166``` rust
0 commit comments