Rust already has specialization
Demo code for specialized trait implementation: playground
There are two main reasons for why this works:
- when calling a method on an object, Rust tries every possible
Derefof that type until it finds one that implements that method; - when using generics,
Tis equivalent to&T, but that does not count for mutable references.
I with some members of the Rust Italy community found this trick while helping Nappa do this and I don't know if this was already known but I think it's cool.