Macro either::try_left [−][src]
Macro for unwrapping the left side of an Either
, which fails early
with the opposite side. Can only be used in functions that return
Either
because of the early return of Right
that it provides.
See also try_right!
for its dual, which applies the same just to the
right side.
Example
#[macro_use] extern crate either; use either::{Either, Left, Right}; fn twice(wrapper: Either<u32, &str>) -> Either<u32, &str> { let value = try_left!(wrapper); Left(value * 2) } fn main() { assert_eq!(twice(Left(2)), Left(4)); assert_eq!(twice(Right("ups")), Right("ups")); }