File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -277,6 +277,29 @@ One last thing about traits: generic functions with a trait bound use
277
277
dispatched. What's that mean? Check out the chapter on [ static and dynamic
278
278
dispatch] ( static-and-dynamic-dispatch.html ) for more.
279
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
+ ``` 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
+
280
303
## Where clause
281
304
282
305
Writing functions with only a few generic types and a small number of trait
You can’t perform that action at this time.
0 commit comments