Closed Munksgaard closed 9 years ago
Yes
@Manishearth: In Rust the tendency is to create new types for stuff like this; being a well known type Result has a connotation too, which isn't satisfied here. If a method returns a result people will tend to assume it's for error handling (and often magick it away via unwrap()
or try!
which we don't want -- each branch should be handled)
@laumann: I guess it would be a matter of substituting Result
for an enum like
enum Branch<L, R> {
Left(L),
Right(R)
}
and match like
match c.offer() {
Branch::Left(c) => { /* Left branch */ }
Branch::Right(c) => { /* Right branch */ }
}
@Manishearth: Yep, more or less. Publicly exporting Branch::*
makes it less noisy too.
We could change sel1()
/sel2()
with left()
and right()
too
@laumann: The names sel1
and sel2
are from the Haskell paper from which we've borrowed the structure and all the names. But I like left()
and right()
more - personally I find it more intuitive.
Following a discussion with @Manishearth, I've become convinced that we shouldn't abuse
Result
inoffer
. Instead we should implement our ownEither
orBranch
type.@laumann: Agree?