When you define a new trait, you’ll usually want to provide blanket implementations for that trait for:
&T, no dereferencing with shared references&mut T, same as aboveBox<T>, for heap-allocated types
For ergonomics, also consider:
IntoIteratorfor both&Tand&mut Tto have for loopsDerefif you provide a transparent type (likeArc) allows calling methods on the inner type via.. Avoid it on types in which you don’t know in advance the inner type
See also
- Principle of Least Astonishment
- Every Rust type should implement Debug, Send, Sync, Clone and Default - the parent: first focus on standard traits
- OCP - software should be open for extension and closed for modification - blanket implementations are open for extension
References
- J. Gjengset, Rust for Rustaceans: Idiomatic Programming for Experienced Developers. No Starch Press, 2021.