3 ms·
Unless TraitB is an auto trait, that isn't currently valid? From the reference: > Trait objects are written as the optional keyword dyn followed by a set of t
by Tuna-Fish 6y ago
Unless TraitB is an auto trait, that isn't currently valid?
From the reference:
> Trait objects are written as the optional keyword dyn followed by a set of trait bounds, but with the following restrictions on the trait bounds. All traits except the first trait must be auto traits, there may not be more than one lifetime, and opt-out bounds (e.g. ?Sized) are not allowed.
The only one of those restrictions that is acceptable to have is the single lifetime one. All the others are seriously restricting. The devs seem to agree, but work on this aspect of rust is very slow, and people are arguing on how to implement it. (I, for one, feel very strongly that dyn TraitA + TraitB should have a size of 3 pointers. That is, no magic combining vtables, just every added trait adds a new pointer to vtable.)
- steveklabnik 6y agoThis is not a trait object, and so that part of the reference is irrelevant. Here's that example working: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=745c3742eefd594ca988f77d87c540cd https://play.rust-lang.org/?version=stable&mode=debug&editio... I am not entirely sure that it answers your point though; what you want is trait A or trait B, not both, right?
- Tuna-Fish 6y agoAh sorry, no, what I want is specifically a trait object that satisfies both trait A and B.
- steveklabnik 6y agoYes, in that case you are 100% right, your parent didn't provide an actual solution.
- loeg 6y agoI didn't understand what you meant by a trait object, mea culpa.