When should I not implement a trait for references to implementors of that trait?

when shouldn’t I implement this? Asked another way, why doesn’t the compiler automatically implement this for me? Since it currently doesn’t, I assume there must be cases where having this implementation would be disadvantageous. As an example, the Default trait immediately came to mind. pub trait Default { fn default() -> Self; } I could … Read more

How to avoid writing duplicate accessor functions for mutable and immutable references in Rust?

(playground links to solutions using type parameters and associated types) In this case &T and &mut T are just two different types. Code that is generic over different types (at both compile-time and run-time) is idiomatically written in Rust using traits. For example, given: struct Foo { value: i32 } struct Bar { foo: Foo … Read more