Relax trait object to allow multiple ones to be passed


This comes from my attempts to abstract over channels in Actix. There only one trait allowed to be boxed at a time. Strangely it can be easily workaround but it’s just additional boilerplate code:

// Not allowed
// fn foo(f: Box<Trait1 + Trait2>) {}

trait Trait1AndTrait2: Trait1 + Trait2 {}
impl<T: Trait1 + Trait2> Trait1AndTrait2 for T {}
fn foo(f: Trait1AndTrait2) {}

It would be nice to remove the boilerplate.

1 Like


You may find the previous discussion in Where's the catch with Box<Read + Write>?


closed #3

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.