From 371ba00da2183a9763f1145c5e711e3278a785dd Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 31 Mar 2015 19:45:09 -0400 Subject: [PATCH] Add description of + for multiple trait bounds Fixes #23688 --- src/doc/trpl/traits.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/doc/trpl/traits.md b/src/doc/trpl/traits.md index 1e44076a4305f..341c90a70877e 100644 --- a/src/doc/trpl/traits.md +++ b/src/doc/trpl/traits.md @@ -277,6 +277,29 @@ One last thing about traits: generic functions with a trait bound use dispatched. What's that mean? Check out the chapter on [static and dynamic dispatch](static-and-dynamic-dispatch.html) for more. +## Multiple trait bounds + +You’ve seen that you can bound a generic type parameter with a trait: + +```rust +fn foo(x: T) { + x.clone(); +} +``` + +If you need more than one bound, you can use `+`: + +```rust +use std::fmt::Debug; + +fn foo(x: T) { + x.clone(); + println!("{:?}", x); +} +``` + +`T` now needs to be both `Clone` as well as `Debug`. + ## Where clause Writing functions with only a few generic types and a small number of trait