Testcase: empty bounds

A consequence of how bounds work is that even if a trait doesn’t include any functionality, you can still use it as a bound. Eq and Ord are examples of such traits from the std library.

1. struct Cardinal;
2. struct BlueJay;
3. struct Turkey;

5. trait Red {}
6. trait Blue {}

8. impl Red for Cardinal {}
9. impl Blue for BlueJay {}

11. // These functions are only valid for types which implement these
12. // traits. The fact that the traits are empty is irrelevant.
13. fn red<T: Red>(_: &T)   -> &'static str { "red" }
14. fn blue<T: Blue>(_: &T) -> &'static str { "blue" }

16. fn main() {
17. let cardinal = Cardinal;
18. let blue_jay = BlueJay;
19. let _turkey   = Turkey;

21. // `red()` won't work on a blue jay nor vice versa
22. // because of the bounds.
23. println!("A cardinal is {}", red(&cardinal));
24. println!("A blue jay is {}", blue(&blue_jay));
25. //println!("A turkey is {}", red(&_turkey));
26. // ^ TODO: Try uncommenting this line.
27. }

See also:

std:![:cmp:](https://www.emoji-cheat-sheet.com/graphics/emojis/cmp.png ":cmp:"):Eq, std:![:cmp:](https://www.emoji-cheat-sheet.com/graphics/emojis/cmp.png ":cmp:"):Ords, and traits