marcianx:
I don't quite understand how you intend to implement DerefMut<Target=Wrapper<Trait>>. The return type of deref_mut() would be &'a mut Wrapper<Trait>. But Wrapper<T> does not contain a Wrapper<Trait> and you would need to return a reference to the latter with the right lifetime. As far as I can see a conversion function, not a dereferencing one, needs to be implemented that unwraps T, casts it to Trait and returns the wrapped version of it; i.e. &'a Wrapper<T> --> Wrapper<Trait + 'a>.
I can already do this. See my other thread .
comex:
One potential problem with the latter I can think of is that if Rust eventually supports &(Trait1+Trait2+Trait3) properly (it currently only allows it if all but the first trait are builtin marker traits with no methods), going from that to, say, &(Trait1+Trait3) would definitely require a separate vtable, so if such casting were allowed in general, turning a concrete reference to a trait object with N traits would require generating a number of vtables exponential in N. And such a compound trait object would match your generic impl. The special case of casting to a single-trait object as you're trying to do - say, going from &(Trait1+Trait2) to &Trait2 - would be possible if vtables for compound objects embedded full copies of the vtables for their component traits, such that the conversion would just be a pointer addition, but even that might be problematic when combined with trait inheritance...
I thought this was an inherent problem in supporting &(Trait1+Trait2+Trait3)
. That is, to support some form of &(Trait1+Trait2+Trait3)
, we'd either need super-fat pointers, dynamic indirect vtables (i.e., dynamically allocated tables mapping traits to vtables), or "thin" traits. Unless I'm mistaken, all of these would allow this cast.