When building a complex architecture, prerequisite behavior is very common. In Rust, this means that we cannot build either generic or other types without requiring them to conform to some prior behavior, or, in other words, we need to be able to specify which traits are required. Trait bounds are one way of doing that – and you have seen multiple instances of this already, even if you have skipped many recipes so far.
Enforcing behavior with trait bounds
How to do it...
Follow these steps to learn more about traits:
- Create a new project using cargo new trait-bounds and open it in your favorite editor.
- Edit src/main.rs to add the following code, where we can easily print a variable's debug format since an implementation...