impl Trait inside structs


#1

So I encountered a problem recently, and the best way to solve it was either:

Is there any proper solution I am not aware of?


#2

This seems like a use case for a named abstract/existential type (proposal). Then you could just have

existential type DebugImpl: Debug;
impl S<DebugImpl> {
    fn new() -> S<DebugImpl> { ... }
}

Another way for the language to support this use case would be to allow impls on type-constructors:

impl S {
    fn new() -> S<impl Debug> { ... }
}

but there isn’t a proposal for this (we’ll have to see how generic associated types turn out and see whether/how first-class type constructors should be added to the language).