Enum Either
enum Either<L, R>
Either represents an alternative holding one value out of
either of the two possible values.
Either is a general purpose sum type of two parts. For representing
success or error, use the regular Result<T, E> instead.
Variants
-
Left(L) A value of type
L.-
Right(R) A value of type
R.
Implementations
impl<L, R> Either<L, R>
fn is_left(self: &Self) -> boolReturn true if the value is the
Leftvariant.use *; let values = ; assert_eq!; assert_eq!;fn is_right(self: &Self) -> boolReturn true if the value is the
Rightvariant.use *; let values = ; assert_eq!; assert_eq!;fn left(self: Self) -> Option<L>Convert the left side of
Either<L, R>to anOption<L>.use *; let left: = Left; assert_eq!; let right: = Right; assert_eq!;fn right(self: Self) -> Option<R>Convert the right side of
Either<L, R>to anOption<R>.use *; let left: = Left; assert_eq!; let right: = Right; assert_eq!;fn as_ref(self: &Self) -> Either<&L, &R>Convert
&Either<L, R>toEither<&L, &R>.use *; let left: = Left; assert_eq!; let right: = Right; assert_eq!;fn as_mut(self: &mut Self) -> Either<&mut L, &mut R>Convert
&mut Either<L, R>toEither<&mut L, &mut R>.use *; let mut left = Left; let mut right = Right; mutate_left; mutate_left; assert_eq!; assert_eq!;fn flip(self: Self) -> Either<R, L>Convert
Either<L, R>toEither<R, L>.use *; let left: = Left; assert_eq!; let right: = Right; assert_eq!;fn map_left<F, M>(self: Self, f: F) -> Either<M, R> where F: FnOnce(L) -> MApply the function
fon the value in theLeftvariant if it is present.use *; let left: = Left; assert_eq!; let right: = Right; assert_eq!;fn map_right<F, S>(self: Self, f: F) -> Either<L, S> where F: FnOnce(R) -> SApply the function
fon the value in theRightvariant if it is present.use *; let left: = Left; assert_eq!; let right: = Right; assert_eq!;fn either<F, G, T>(self: Self, f: F, g: G) -> T where F: FnOnce(L) -> T, G: FnOnce(R) -> TApply one of two functions depending on contents, unifying their result. If the value is
Left(L)then the first functionfis applied; if it isRight(R)then the second functiongis applied.use *; let left: = Left; assert_eq!; let right: = Right; assert_eq!;
impl<I> IntoIterator for Either<L, R>
fn into_iter(self: Self) -> I
impl<L, R> BufRead for Either<L, R>
fn fill_buf(self: &mut Self) -> Result<&[u8]>fn consume(self: &mut Self, amt: usize)
impl<L, R> Deref for Either<L, R>
fn deref(self: &Self) -> &<Self as >::Target
impl<L, R> DerefMut for Either<L, R>
fn deref_mut(self: &mut Self) -> &mut <Self as >::Target
impl<L, R> Display for Either<L, R>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<L, R> DoubleEndedIterator for Either<L, R>
fn next_back(self: &mut Self) -> Option<<L as >::Item>
impl<L, R> Error for Either<L, R>
fn description(self: &Self) -> &strfn cause(self: &Self) -> Option<&dyn Error>
impl<L, R> ExactSizeIterator for Either<L, R>
impl<L, R> Freeze for Either<L, R>
impl<L, R> From for Either<L, R>
fn from(r: Result<R, L>) -> Self
impl<L, R> Into for Either<L, R>
fn into(self: Self) -> Result<R, L>
impl<L, R> Iterator for Either<L, R>
fn next(self: &mut Self) -> Option<<L as >::Item>fn size_hint(self: &Self) -> (usize, Option<usize>)
impl<L, R> Read for Either<L, R>
fn read(self: &mut Self, buf: &mut [u8]) -> Result<usize>fn read_to_end(self: &mut Self, buf: &mut Vec<u8>) -> Result<usize>
impl<L, R> RefUnwindSafe for Either<L, R>
impl<L, R> Send for Either<L, R>
impl<L, R> StructuralPartialEq for Either<L, R>
impl<L, R> Sync for Either<L, R>
impl<L, R> Unpin for Either<L, R>
impl<L, R> UnsafeUnpin for Either<L, R>
impl<L, R> UnwindSafe for Either<L, R>
impl<L, R> Write for Either<L, R>
fn write(self: &mut Self, buf: &[u8]) -> Result<usize>fn flush(self: &mut Self) -> Result<()>
impl<L, R, Target> AsMut for Either<L, R>
fn as_mut(self: &mut Self) -> &mut Target
impl<L, R, Target> AsRef for Either<L, R>
fn as_ref(self: &Self) -> &Target
impl<L: $crate::clone::Clone, R: $crate::clone::Clone> Clone for Either<L, R>
fn clone(self: &Self) -> Either<L, R>
impl<L: $crate::cmp::Eq, R: $crate::cmp::Eq> Eq for Either<L, R>
impl<L: $crate::cmp::Ord, R: $crate::cmp::Ord> Ord for Either<L, R>
fn cmp(self: &Self, other: &Either<L, R>) -> Ordering
impl<L: $crate::cmp::PartialEq, R: $crate::cmp::PartialEq> PartialEq for Either<L, R>
fn eq(self: &Self, other: &Either<L, R>) -> bool
impl<L: $crate::cmp::PartialOrd, R: $crate::cmp::PartialOrd> PartialOrd for Either<L, R>
fn partial_cmp(self: &Self, other: &Either<L, R>) -> Option<Ordering>
impl<L: $crate::fmt::Debug, R: $crate::fmt::Debug> Debug for Either<L, R>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<L: $crate::hash::Hash, R: $crate::hash::Hash> Hash for Either<L, R>
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl<L: $crate::marker::Copy, R: $crate::marker::Copy> Copy for Either<L, R>
impl<P, T> Receiver for Either<L, R>
impl<T> Any for Either<L, R>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Either<L, R>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Either<L, R>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Either<L, R>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Either<L, R>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Either<L, R>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for Either<L, R>
fn to_string(self: &Self) -> String
impl<T, U> Into for Either<L, R>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Either<L, R>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Either<L, R>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>