OK, time to wrap traits up for now and head for the summary and exercises. Here's what you need to remember from traits:
- Traits are like interfaces in OO languages: they allow giving types additional functionalities in a controlled way
- We can make types fulfill the traits by supplying impl blocks
- We can define impl blocks for types that have generics too, although we need to be careful about the type bounds
- Type bounds allow us to narrow down our generic types by declaring what traits need to be implemented for a type
And here's some extra work you can and should do to drive traits in:
- Make your own type, without generics. Perhaps just strip off the generic type from our Money<T>. Implement some or all of the operators ...