Can mutability be a generic parameter in traits? I'd like to implement a trait for a mutable and an immutable variant of a type without having to copy&paste the impl block.
trait Foo<T> {…}
impl<T> Foo for *const T {…}
impl<T> Foo for *mut T {…same thing again…}
Wishful pseudocode:
trait Foo<T> {…}
impl<T, Mutability> Foo for *Mutability T {…}
*const T, then define the impl for*mut Tas(self as *const T).method()or something like that. - user395760* const Tpointers and cast to*mut Tonly when explicitly needed. More generally, people want to be able to return parameterized over mutability, as well as change the mutability of references&T<->&mut T. I'd be very wary about casting or transmuting in those cases. - Shepmaster