We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1d5ef75 + 371ba00 commit 6ebb6e6Copy full SHA for 6ebb6e6
src/doc/trpl/traits.md
@@ -277,6 +277,29 @@ One last thing about traits: generic functions with a trait bound use
277
dispatched. What's that mean? Check out the chapter on [static and dynamic
278
dispatch](static-and-dynamic-dispatch.html) for more.
279
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
293
+use std::fmt::Debug;
294
295
+fn foo<T: Clone + Debug>(x: T) {
296
297
+ println!("{:?}", x);
298
299
300
301
+`T` now needs to be both `Clone` as well as `Debug`.
302
303
## Where clause
304
305
Writing functions with only a few generic types and a small number of trait
0 commit comments