rust - Option<T> where T can be two different traits? -
if have 2 different traits:
trait foo {} trait bar {}
is possible have option can either of them (or none, of course), like:
struct foobar { fb: option<~foo or bar> } let fb1 = foobar{fb: some(~somestruct ~foo)} let fb2 = foobar{fb: some(~otherstruct ~bar)}
and have them both work?
there nothing special option<t>
; this, plus convenience methods , bit of documentation:
pub enum option<t> { some(t), none, }
bear in mind: it's enums way. can make own enums. explicit, learn appreciate thing.
pub enum fooorbar { foo(~foo), bar(~bar), }
you can make option<t>
of this. or perhaps prefer blend two, if can better semantic meaning out of it:
pub enum { foozy(~foo), bark(~bar), adifferentvariant, }
Comments
Post a Comment