Skip to content

Commit 6ebb6e6

Browse files
committed
rollup merge of rust-lang#23923: steveklabnik/gh23688
Fixes rust-lang#23688 r? @alexcrichton
2 parents 1d5ef75 + 371ba00 commit 6ebb6e6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/doc/trpl/traits.md

+23
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,29 @@ One last thing about traits: generic functions with a trait bound use
277277
dispatched. What's that mean? Check out the chapter on [static and dynamic
278278
dispatch](static-and-dynamic-dispatch.html) for more.
279279

280+
## Multiple trait bounds
281+
282+
You’ve seen that you can bound a generic type parameter with a trait:
283+
284+
```rust
285+
fn foo<T: Clone>(x: T) {
286+
x.clone();
287+
}
288+
```
289+
290+
If you need more than one bound, you can use `+`:
291+
292+
```rust
293+
use std::fmt::Debug;
294+
295+
fn foo<T: Clone + Debug>(x: T) {
296+
x.clone();
297+
println!("{:?}", x);
298+
}
299+
```
300+
301+
`T` now needs to be both `Clone` as well as `Debug`.
302+
280303
## Where clause
281304

282305
Writing functions with only a few generic types and a small number of trait

0 commit comments

Comments
 (0)