4 ms·
What is the representation for a type like Box<Reader+Writer>? Is there an extra indirection to get each of the vtables? Is there synthesized combined trait typ
by kalmar 11y ago
What is the representation for a type like Box<Reader+Writer>? Is there an extra indirection to get each of the vtables? Is there synthesized combined trait type and just one vtable pointer?
- Jweb_Guru 11y agoI am pretty sure you can't actually construct such a type (at least not at the moment) so Rust sort of sidesteps the question.
- Manishearth 11y agoIIRC you can.
- burntsushi 11y agoIt's early, so maybe I'm doing something stupid, but it looks like you can't! http://is.gd/9Y1HiS http://is.gd/9Y1HiS --- (I'm kind of surprised by the error message.)
- Rusky 11y agoI get this when I try something like `as Box<Read+Write>` error: only the builtin traits can be used as closure or object bounds [E0225]
- Manishearth 11y agoTIL; thanks :)
- drbawb 11y agoYou can sort of emulate this by having a trait which inherits from two other traits. (e.g: http://is.gd/SWZ9Ya http://is.gd/SWZ9Ya) In which case you'll have a single vtable for the "synthesized" trait object.