Rust already has specialization

68 points GlitchedKoala

Demo code for specialized trait implementation: playground

There are two main reasons for why this works:

  1. when calling a method on an object, Rust tries every possible Deref of that type until it finds one that implements that method;
  2. when using generics, T is 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.