pub enum Either<L, R> { Left(L), Right(R), }
Either
is a type that represents one of two alternatives
impl<L, R> Either<L, R>
fn either<T>(&self, f_left: &fn(&L) -> T, f_right: &fn(&R) -> T) -> T
Applies a function based on the given either value
If value
is Left(L)
then f_left
is applied to its contents, if
value
is Right(R)
then f_right
is applied to its contents, and the
result is returned.
fn flip(self) -> Either<R, L>
Flips between left and right of a given Either
fn is_left(&self) -> bool
Checks whether the given value is a Left
fn is_right(&self) -> bool
Checks whether the given value is a Right
fn expect_left(self, reason: &str) -> L
Retrieves the value from a Left
.
Fails with a specified reason if the Either
is Right
.
fn unwrap_left(self) -> L
Retrieves the value from a Left
. Fails if the Either
is Right
.
fn expect_right(self, reason: &str) -> R
Retrieves the value from a Right
.
Fails with a specified reason if the Either
is Left
.
fn unwrap_right(self) -> R
Retrieves the value from a Right
. Fails if the Either
is Left
.
impl<L: Clone, R: Clone> Clone for Either<L, R>
fn clone(&self) -> Either<L, R>
Returns a copy of the value. The contents of owned pointers are copied to maintain uniqueness, while the contents of managed pointers are not copied.
impl<L: Eq, R: Eq> Eq for Either<L, R>
impl<L: IterBytes, R: IterBytes> IterBytes for Either<L, R>
fn iter_bytes(&self, __arg_0: bool, __arg_1: Cb) -> bool
Call the provided callback f
one or more times with
byte-slices that should be used when computing a hash
value or otherwise "flattening" the structure into
a sequence of bytes. The lsb0
parameter conveys
whether the caller is asking for little-endian bytes
(true
) or big-endian (false
); this should only be
relevant in implementations that represent a single
multi-byte datum such as a 32 bit integer or 64 bit
floating-point value. It can be safely ignored for
larger structured types as they are usually processed
left-to-right in declaration order, regardless of
underlying memory endianness.
impl<L, R: Clone> ToOption<R> for Either<L, R>
fn to_option(&self) -> Option<R>
Convert to the option
type
impl<L, R> IntoOption<R> for Either<L, R>
fn into_option(self) -> Option<R>
Convert to the option
type
impl<L, R> AsOption<R> for Either<L, R>
fn as_option<'a>(&'a self) -> Option<&'a R>
Convert to the option
type
impl<L: Clone, R: Clone> ToResult<R, L> for Either<L, R>
fn to_result(&self) -> Result<R, L>
Convert to the result
type
impl<L, R> IntoResult<R, L> for Either<L, R>
fn into_result(self) -> Result<R, L>
Convert to the result
type
impl<L, R> AsResult<R, L> for Either<L, R>
fn as_result<'a>(&'a self) -> Result<&'a R, &'a L>
Convert to the result
type
impl<L: Clone, R: Clone> ToEither<L, R> for Either<L, R>
fn to_either(&self) -> Either<L, R>
Convert to the either
type
impl<L, R> IntoEither<L, R> for Either<L, R>
fn into_either(self) -> Either<L, R>
Convert to the either
type
impl<L, R> AsEither<L, R> for Either<L, R>
fn as_either<'a>(&'a self) -> Either<&'a L, &'a R>
Convert to the either
type
Prefix searches with a type followed by a colon (e.g.
fn:
) to restrict the search to a given type.
Accepted types are: fn
, mod
,
struct
(or str
), enum
,
trait
, typedef
(or
tdef
).