Enum Either

pub enum Either<L, R>

The enum Either with variants Left and Right is a general purpose sum type with two cases.

The Either type is symmetric and treats its variants the same way, without preference. (For representing success or error, use the regular Result enum instead.)

Variants

Left(L)

A value of type L.

Right(R)

A value of type R.

Implementations

impl<L, R> Either<&L, &R>

fn cloned(self) -> Either<L, R>
where
    L: Clone,
    R: Clone,

Maps an Either<&L, &R> to an Either<L, R> by cloning the contents of either branch.

fn copied(self) -> Either<L, R>
where
    L: Copy,
    R: Copy,

Maps an Either<&L, &R> to an Either<L, R> by copying the contents of either branch.

impl<L, R> Either<&mut L, &mut R>

fn cloned(self) -> Either<L, R>
where
    L: Clone,
    R: Clone,

Maps an Either<&mut L, &mut R> to an Either<L, R> by cloning the contents of either branch.

fn copied(self) -> Either<L, R>
where
    L: Copy,
    R: Copy,

Maps an Either<&mut L, &mut R> to an Either<L, R> by copying the contents of either branch.

impl<L, R> Either<L, R>

fn is_left(&self) -> bool

Return true if the value is the Left variant.

use either::*;

let values = [Left(1), Right("the right value")];
assert_eq!(values[0].is_left(), true);
assert_eq!(values[1].is_left(), false);
fn is_left_and<F>(self, f: F) -> bool
where
    F: FnOnce(L) -> bool,

Returns true if the value is Left and the value inside of it matches a predicate.

Examples

use either::*;

let left0: Either<i32, i32> = Left(0);
let left2: Either<i32, i32> = Left(2);
let right: Either<i32, i32> = Right(2);

assert_eq!(left2.is_left_and(|n| n > 1), true);
assert_eq!(left0.is_left_and(|n| n > 1), false);
assert_eq!(right.is_left_and(|n| n > 1), false);
fn is_right_and<F>(self, f: F) -> bool
where
    F: FnOnce(R) -> bool,

Returns true if the value is Right and the value inside of it matches a predicate.

Examples

use either::*;

let right0: Either<i32, i32> = Right(0);
let right2: Either<i32, i32> = Right(2);
let left: Either<i32, i32> = Left(2);

assert_eq!(right2.is_right_and(|n| n > 1), true);
assert_eq!(right0.is_right_and(|n| n > 1), false);
assert_eq!(left.is_right_and(|n| n > 1), false);
fn is_right(&self) -> bool

Return true if the value is the Right variant.

use either::*;

let values = [Left(1), Right("the right value")];
assert_eq!(values[0].is_right(), false);
assert_eq!(values[1].is_right(), true);
fn left(self) -> Option<L>

Convert the left side of Either<L, R> to an Option<L>.

use either::*;

let left: Either<_, ()> = Left("some value");
assert_eq!(left.left(),  Some("some value"));

let right: Either<(), _> = Right(321);
assert_eq!(right.left(), None);
fn right(self) -> Option<R>

Convert the right side of Either<L, R> to an Option<R>.

use either::*;

let left: Either<_, ()> = Left("some value");
assert_eq!(left.right(),  None);

let right: Either<(), _> = Right(321);
assert_eq!(right.right(), Some(321));
fn as_ref(&self) -> Either<&L, &R>

Convert &Either<L, R> to Either<&L, &R>.

use either::*;

let left: Either<_, ()> = Left("some value");
assert_eq!(left.as_ref(), Left(&"some value"));

let right: Either<(), _> = Right("some value");
assert_eq!(right.as_ref(), Right(&"some value"));
fn as_mut(&mut self) -> Either<&mut L, &mut R>

Convert &mut Either<L, R> to Either<&mut L, &mut R>.

use either::*;

fn mutate_left(value: &mut Either<u32, u32>) {
    if let Some(l) = value.as_mut().left() {
        *l = 999;
    }
}

let mut left = Left(123);
let mut right = Right(123);
mutate_left(&mut left);
mutate_left(&mut right);
assert_eq!(left, Left(999));
assert_eq!(right, Right(123));
fn as_pin_ref(self: Pin<&Self>) -> Either<Pin<&L>, Pin<&R>>

Convert Pin<&Either<L, R>> to Either<Pin<&L>, Pin<&R>>, pinned projections of the inner variants.

fn as_pin_mut(self: Pin<&mut Self>) -> Either<Pin<&mut L>, Pin<&mut R>>

Convert Pin<&mut Either<L, R>> to Either<Pin<&mut L>, Pin<&mut R>>, pinned projections of the inner variants.

fn flip(self) -> Either<R, L>

Convert Either<L, R> to Either<R, L>.

use either::*;

let left: Either<_, ()> = Left(123);
assert_eq!(left.flip(), Right(123));

let right: Either<(), _> = Right("some value");
assert_eq!(right.flip(), Left("some value"));
fn map_left<F, M>(self, f: F) -> Either<M, R>
where
    F: FnOnce(L) -> M,

Apply the function f on the value in the Left variant if it is present rewrapping the result in Left.

use either::*;

let left: Either<_, u32> = Left(123);
assert_eq!(left.map_left(|x| x * 2), Left(246));

let right: Either<u32, _> = Right(123);
assert_eq!(right.map_left(|x| x * 2), Right(123));
fn map_right<F, S>(self, f: F) -> Either<L, S>
where
    F: FnOnce(R) -> S,

Apply the function f on the value in the Right variant if it is present rewrapping the result in Right.

use either::*;

let left: Either<_, u32> = Left(123);
assert_eq!(left.map_right(|x| x * 2), Left(123));

let right: Either<u32, _> = Right(123);
assert_eq!(right.map_right(|x| x * 2), Right(246));
fn map_left_or<F, S>(self, default: S, f: F) -> S
where
    F: FnOnce(L) -> S,

Returns the provided default (if Right), or applies a function to the contained value (if Left).

Examples

use either::*;

let x: Either<_, i32> = Left(123);
assert_eq!(x.map_left_or(0, |n| n * 2), 246);

let x: Either<i32, _> = Right(123);
assert_eq!(x.map_left_or(0, |n| n * 2), 0);
fn map_right_or<F, S>(self, default: S, f: F) -> S
where
    F: FnOnce(R) -> S,

Returns the provided default (if Left), or applies a function to the contained value (if Right).

Examples

use either::*;

let x: Either<_, i32> = Left(123);
assert_eq!(x.map_right_or(0, |n| n * 2), 0);

let x: Either<i32, _> = Right(123);
assert_eq!(x.map_right_or(0, |n| n * 2), 246);
fn map_either<F, G, M, S>(self, f: F, g: G) -> Either<M, S>
where
    F: FnOnce(L) -> M,
    G: FnOnce(R) -> S,

Apply the functions f and g to the Left and Right variants respectively. This is equivalent to bimap in functional programming.

use either::*;

let f = |s: String| s.len();
let g = |u: u8| u.to_string();

let left: Either<String, u8> = Left("loopy".into());
assert_eq!(left.map_either(f, g), Left(5));

let right: Either<String, u8> = Right(42);
assert_eq!(right.map_either(f, g), Right("42".into()));
fn map_either_with<Ctx, F, G, M, S>(self, ctx: Ctx, f: F, g: G) -> Either<M, S>
where
    F: FnOnce(Ctx, L) -> M,
    G: FnOnce(Ctx, R) -> S,

Similar to [map_either][Self::map_either], with an added context ctx accessible to both functions.

use either::*;

let mut sum = 0;

// Both closures want to update the same value, so pass it as context.
let mut f = |sum: &mut usize, s: String| { *sum += s.len(); s.to_uppercase() };
let mut g = |sum: &mut usize, u: usize| { *sum += u; u.to_string() };

let left: Either<String, usize> = Left("loopy".into());
assert_eq!(left.map_either_with(&mut sum, &mut f, &mut g), Left("LOOPY".into()));

let right: Either<String, usize> = Right(42);
assert_eq!(right.map_either_with(&mut sum, &mut f, &mut g), Right("42".into()));

assert_eq!(sum, 47);
fn either<F, G, T>(self, f: F, g: G) -> T
where
    F: FnOnce(L) -> T,
    G: FnOnce(R) -> T,

Apply one of two functions depending on contents, unifying their result. If the value is Left(L) then the first function f is applied; if it is Right(R) then the second function g is applied.

use either::*;

fn square(n: u32) -> i32 { (n * n) as i32 }
fn negate(n: i32) -> i32 { -n }

let left: Either<u32, i32> = Left(4);
assert_eq!(left.either(square, negate), 16);

let right: Either<u32, i32> = Right(-4);
assert_eq!(right.either(square, negate), 4);
fn either_with<Ctx, F, G, T>(self, ctx: Ctx, f: F, g: G) -> T
where
    F: FnOnce(Ctx, L) -> T,
    G: FnOnce(Ctx, R) -> T,

Like [either][Self::either], but provide some context to whichever of the functions ends up being called.

// In this example, the context is a mutable reference
use either::*;

let mut result = Vec::new();

let values = vec![Left(2), Right(2.7)];

for value in values {
    value.either_with(&mut result,
                      |ctx, integer| ctx.push(integer),
                      |ctx, real| ctx.push(f64::round(real) as i32));
}

assert_eq!(result, vec![2, 3]);
fn left_and<S>(self, other: Either<S, R>) -> Either<S, R>

Returns other if the value is Left, otherwise returns the Right value of self.

Arguments passed to left_and are eagerly evaluated; if you are passing the result of a function call, it is recommended to use left_and_then, which is lazily evaluated.

Examples

use either::*;

let left: Either<_, u32> = Left(123);
assert_eq!(left.left_and::<()>(Right(246)), Right(246));
assert_eq!(left.left_and(Left(246)), Left(246));

let right: Either<u32, _> = Right(123);
assert_eq!(right.left_and::<()>(Right(246)), Right(123));
assert_eq!(right.left_and(Left(246)), Right(123));
fn right_and<S>(self, other: Either<L, S>) -> Either<L, S>

Returns other if the value is Right, otherwise returns the Left value of self.

Arguments passed to right_and are eagerly evaluated; if you are passing the result of a function call, it is recommended to use right_and_then, which is lazily evaluated.

Examples

use either::*;

let left: Either<_, u32> = Left(123);
assert_eq!(left.right_and(Right(246)), Left(123));
assert_eq!(left.right_and::<()>(Left(246)), Left(123));

let right: Either<u32, _> = Right(123);
assert_eq!(right.right_and(Right(246)), Right(246));
assert_eq!(right.right_and::<()>(Left(246)), Left(246));
fn left_and_then<F, S>(self, f: F) -> Either<S, R>
where
    F: FnOnce(L) -> Either<S, R>,

Apply the function f on the value in the Left variant if it is present.

use either::*;

let left: Either<_, u32> = Left(123);
assert_eq!(left.left_and_then::<_,()>(|x| Right(x * 2)), Right(246));

let right: Either<u32, _> = Right(123);
assert_eq!(right.left_and_then(|x| Right::<(), _>(x * 2)), Right(123));
fn right_and_then<F, S>(self, f: F) -> Either<L, S>
where
    F: FnOnce(R) -> Either<L, S>,

Apply the function f on the value in the Right variant if it is present.

use either::*;

let left: Either<_, u32> = Left(123);
assert_eq!(left.right_and_then(|x| Right(x * 2)), Left(123));

let right: Either<u32, _> = Right(123);
assert_eq!(right.right_and_then(|x| Right(x * 2)), Right(246));
fn into_iter(self) -> Either<L::IntoIter, R::IntoIter>
where
    L: IntoIterator,
    R: IntoIterator<Item = L::Item>,

Convert the inner value to an iterator.

This requires the Left and Right iterators to have the same item type. See [factor_into_iter][Either::factor_into_iter] to iterate different types.

use either::*;

let left: Either<_, Vec<u32>> = Left(vec![1, 2, 3, 4, 5]);
let mut right: Either<Vec<u32>, _> = Right(vec![]);
right.extend(left.into_iter());
assert_eq!(right, Right(vec![1, 2, 3, 4, 5]));
fn iter(&self) -> Either<<&L as IntoIterator>::IntoIter, <&R as IntoIterator>::IntoIter>
where
    for<'a> &'a L: IntoIterator,
    for<'a> &'a R: IntoIterator<Item = <&'a L as IntoIterator>::Item>,

Borrow the inner value as an iterator.

This requires the Left and Right iterators to have the same item type. See [factor_iter][Either::factor_iter] to iterate different types.

use either::*;

let left: Either<_, &[u32]> = Left(vec![2, 3]);
let mut right: Either<Vec<u32>, _> = Right(&[4, 5][..]);
let mut all = vec![1];
all.extend(left.iter());
all.extend(right.iter());
assert_eq!(all, vec![1, 2, 3, 4, 5]);
fn iter_mut(&mut self) -> Either<<&mut L as IntoIterator>::IntoIter, <&mut R as IntoIterator>::IntoIter>
where
    for<'a> &'a mut L: IntoIterator,
    for<'a> &'a mut R: IntoIterator<Item = <&'a mut L as IntoIterator>::Item>,

Mutably borrow the inner value as an iterator.

This requires the Left and Right iterators to have the same item type. See [factor_iter_mut][Either::factor_iter_mut] to iterate different types.

use either::*;

let mut left: Either<_, &mut [u32]> = Left(vec![2, 3]);
for l in left.iter_mut() {
    *l *= *l
}
assert_eq!(left, Left(vec![4, 9]));

let mut inner = [4, 5];
let mut right: Either<Vec<u32>, _> = Right(&mut inner[..]);
for r in right.iter_mut() {
    *r *= *r
}
assert_eq!(inner, [16, 25]);
fn factor_into_iter(self) -> IterEither<L::IntoIter, R::IntoIter>
where
    L: IntoIterator,
    R: IntoIterator,

Converts an Either of Iterators to be an Iterator of Eithers

Unlike [into_iter][Either::into_iter], this does not require the Left and Right iterators to have the same item type.

use either::*;
let left: Either<_, Vec<u8>> = Left(&["hello"]);
assert_eq!(left.factor_into_iter().next(), Some(Left(&"hello")));

let right: Either<&[&str], _> = Right(vec![0, 1]);
assert_eq!(right.factor_into_iter().collect::<Vec<_>>(), vec![Right(0), Right(1)]);

fn factor_iter(&self) -> IterEither<<&L as IntoIterator>::IntoIter, <&R as IntoIterator>::IntoIter>
where
    for<'a> &'a L: IntoIterator,
    for<'a> &'a R: IntoIterator,

Borrows an Either of Iterators to be an Iterator of Eithers

Unlike [iter][Either::iter], this does not require the Left and Right iterators to have the same item type.

use either::*;
let left: Either<_, Vec<u8>> = Left(["hello"]);
assert_eq!(left.factor_iter().next(), Some(Left(&"hello")));

let right: Either<[&str; 2], _> = Right(vec![0, 1]);
assert_eq!(right.factor_iter().collect::<Vec<_>>(), vec![Right(&0), Right(&1)]);

fn factor_iter_mut(&mut self) -> IterEither<<&mut L as IntoIterator>::IntoIter, <&mut R as IntoIterator>::IntoIter>
where
    for<'a> &'a mut L: IntoIterator,
    for<'a> &'a mut R: IntoIterator,

Mutably borrows an Either of Iterators to be an Iterator of Eithers

Unlike [iter_mut][Either::iter_mut], this does not require the Left and Right iterators to have the same item type.

use either::*;
let mut left: Either<_, Vec<u8>> = Left(["hello"]);
left.factor_iter_mut().for_each(|x| *x.unwrap_left() = "goodbye");
assert_eq!(left, Left(["goodbye"]));

let mut right: Either<[&str; 2], _> = Right(vec![0, 1, 2]);
right.factor_iter_mut().for_each(|x| if let Right(r) = x { *r = -*r; });
assert_eq!(right, Right(vec![0, -1, -2]));

fn left_or(self, other: L) -> L

Return left value or given value

Arguments passed to left_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use [left_or_else][Self::left_or_else], which is lazily evaluated.

Examples

# use either::*;
let left: Either<&str, &str> = Left("left");
assert_eq!(left.left_or("foo"), "left");

let right: Either<&str, &str> = Right("right");
assert_eq!(right.left_or("left"), "left");
fn left_or_default(self) -> L
where
    L: Default,

Return left or a default

Examples

# use either::*;
let left: Either<String, u32> = Left("left".to_string());
assert_eq!(left.left_or_default(), "left");

let right: Either<String, u32> = Right(42);
assert_eq!(right.left_or_default(), String::default());
fn left_or_else<F>(self, f: F) -> L
where
    F: FnOnce(R) -> L,

Returns left value or computes it from a closure

Examples

# use either::*;
let left: Either<String, u32> = Left("3".to_string());
assert_eq!(left.left_or_else(|_| unreachable!()), "3");

let right: Either<String, u32> = Right(3);
assert_eq!(right.left_or_else(|x| x.to_string()), "3");
fn right_or(self, other: R) -> R

Return right value or given value

Arguments passed to right_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use [right_or_else][Self::right_or_else], which is lazily evaluated.

Examples

# use either::*;
let right: Either<&str, &str> = Right("right");
assert_eq!(right.right_or("foo"), "right");

let left: Either<&str, &str> = Left("left");
assert_eq!(left.right_or("right"), "right");
fn right_or_default(self) -> R
where
    R: Default,

Return right or a default

Examples

# use either::*;
let left: Either<String, u32> = Left("left".to_string());
assert_eq!(left.right_or_default(), u32::default());

let right: Either<String, u32> = Right(42);
assert_eq!(right.right_or_default(), 42);
fn right_or_else<F>(self, f: F) -> R
where
    F: FnOnce(L) -> R,

Returns right value or computes it from a closure

Examples

# use either::*;
let left: Either<String, u32> = Left("3".to_string());
assert_eq!(left.right_or_else(|x| x.parse().unwrap()), 3);

let right: Either<String, u32> = Right(3);
assert_eq!(right.right_or_else(|_| unreachable!()), 3);
fn unwrap_left(self) -> L
where
    R: Debug,

Returns the left value

Examples

# use either::*;
let left: Either<_, ()> = Left(3);
assert_eq!(left.unwrap_left(), 3);

Panics

When Either is a Right value

# use either::*;
let right: Either<(), _> = Right(3);
right.unwrap_left();
fn unwrap_right(self) -> R
where
    L: Debug,

Returns the right value

Examples

# use either::*;
let right: Either<(), _> = Right(3);
assert_eq!(right.unwrap_right(), 3);

Panics

When Either is a Left value

# use either::*;
let left: Either<_, ()> = Left(3);
left.unwrap_right();
fn expect_left(self, msg: &str) -> L
where
    R: Debug,

Returns the left value

Examples

# use either::*;
let left: Either<_, ()> = Left(3);
assert_eq!(left.expect_left("value was Right"), 3);

Panics

When Either is a Right value

# use either::*;
let right: Either<(), _> = Right(3);
right.expect_left("value was Right");
fn expect_right(self, msg: &str) -> R
where
    L: Debug,

Returns the right value

Examples

# use either::*;
let right: Either<(), _> = Right(3);
assert_eq!(right.expect_right("value was Left"), 3);

Panics

When Either is a Left value

# use either::*;
let left: Either<_, ()> = Left(3);
left.expect_right("value was Right");
fn inspect_left<F>(self, f: F) -> Self
where
    F: FnOnce(&L),

Calls a function with a reference to the contained value if Left.

Returns the original self.

Examples

use either::*;

# fn foo() -> Either<u32, u32> { Right(2) }
let x = foo()
    .inspect_left(|n| println!("left: {n}"))
    .left_or(0);
fn inspect_right<F>(self, f: F) -> Self
where
    F: FnOnce(&R),

Calls a function with a reference to the contained value if Right.

Returns the original self.

Examples

use either::*;

# fn foo() -> Either<u32, u32> { Right(2) }
let x = foo()
    .inspect_right(|n| println!("right: {n}"))
    .left_or(0);
fn either_into<T>(self) -> T
where
    L: Into<T>,
    R: Into<T>,

Convert the contained value into T

Examples

# use either::*;
// Both u16 and u32 can be converted to u64.
let left: Either<u16, u32> = Left(3u16);
assert_eq!(left.either_into::<u64>(), 3u64);
let right: Either<u16, u32> = Right(7u32);
assert_eq!(right.either_into::<u64>(), 7u64);

impl<L, R> Either<Option<L>, Option<R>>

fn factor_none(self) -> Option<Either<L, R>>

Factors out None from an Either of Option.

use either::*;
let left: Either<_, Option<String>> = Left(Some(vec![0]));
assert_eq!(left.factor_none(), Some(Left(vec![0])));

let right: Either<Option<Vec<u8>>, _> = Right(Some(String::new()));
assert_eq!(right.factor_none(), Some(Right(String::new())));

impl<L, R, E> Either<Result<L, E>, Result<R, E>>

fn factor_err(self) -> Result<Either<L, R>, E>

Factors out a homogeneous type from an Either of Result.

Here, the homogeneous type is the Err type of the Result.

use either::*;
let left: Either<_, Result<String, u32>> = Left(Ok(vec![0]));
assert_eq!(left.factor_err(), Ok(Left(vec![0])));

let right: Either<Result<Vec<u8>, u32>, _> = Right(Ok(String::new()));
assert_eq!(right.factor_err(), Ok(Right(String::new())));

impl<T> Either<T, T>

fn into_inner(self) -> T

Extract the value of an either over two equivalent types.

use either::*;

let left: Either<_, u32> = Left(123);
assert_eq!(left.into_inner(), 123);

let right: Either<u32, _> = Right(123);
assert_eq!(right.into_inner(), 123);
fn map<F, M>(self, f: F) -> Either<M, M>
where
    F: FnOnce(T) -> M,

Map f over the contained value and return the result in the corresponding variant.

use either::*;

let value: Either<_, i32> = Right(42);

let other = value.map(|x| x * 2);
assert_eq!(other, Right(84));

impl<T, L, R> Either<(L, T), (R, T)>

fn factor_second(self) -> (Either<L, R>, T)

Factor out a homogeneous type from an either of pairs.

Here, the homogeneous type is the second element of the pairs.

use either::*;
let left: Either<_, (String, u32)> = Left((vec![0], 123));
assert_eq!(left.factor_second().1, 123);

let right: Either<(Vec<u8>, u32), _> = Right((String::new(), 123));
assert_eq!(right.factor_second().1, 123);

impl<T, L, R> Either<(T, L), (T, R)>

fn factor_first(self) -> (T, Either<L, R>)

Factor out a homogeneous type from an either of pairs.

Here, the homogeneous type is the first element of the pairs.

use either::*;
let left: Either<_, (u32, String)> = Left((123, vec![0]));
assert_eq!(left.factor_first().0, 123);

let right: Either<(u32, Vec<u8>), _> = Right((123, String::new()));
assert_eq!(right.factor_first().0, 123);

impl<T, L, R> Either<Result<T, L>, Result<T, R>>

fn factor_ok(self) -> Result<T, Either<L, R>>

Factors out a homogeneous type from an Either of Result.

Here, the homogeneous type is the Ok type of the Result.

use either::*;
let left: Either<_, Result<u32, String>> = Left(Err(vec![0]));
assert_eq!(left.factor_ok(), Err(Left(vec![0])));

let right: Either<Result<u32, Vec<u8>>, _> = Right(Err(String::new()));
assert_eq!(right.factor_ok(), Err(Right(String::new())));

Trait Implementations

impl<L, R> AsMut<CStr> for Either<L, R> where L: AsMut<CStr>, R: AsMut<CStr>,

fn as_mut(&mut self) -> &mut CStr

impl<L, R> AsMut<OsStr> for Either<L, R> where L: AsMut<OsStr>, R: AsMut<OsStr>,

fn as_mut(&mut self) -> &mut OsStr

impl<L, R> AsMut<Path> for Either<L, R> where L: AsMut<Path>, R: AsMut<Path>,

fn as_mut(&mut self) -> &mut Path

impl<L, R> AsMut<str> for Either<L, R> where L: AsMut<str>, R: AsMut<str>,

fn as_mut(&mut self) -> &mut str

impl<L, R> AsRef<CStr> for Either<L, R> where L: AsRef<CStr>, R: AsRef<CStr>,

fn as_ref(&self) -> &CStr

impl<L, R> AsRef<OsStr> for Either<L, R> where L: AsRef<OsStr>, R: AsRef<OsStr>,

fn as_ref(&self) -> &OsStr

impl<L, R> AsRef<Path> for Either<L, R> where L: AsRef<Path>, R: AsRef<Path>,

fn as_ref(&self) -> &Path

impl<L, R> AsRef<str> for Either<L, R> where L: AsRef<str>, R: AsRef<str>,

fn as_ref(&self) -> &str

impl<L, R> Binary for Either<L, R> where L: Binary, R: Binary,

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<L, R> BufRead for Either<L, R> where L: BufRead, R: BufRead,

fn fill_buf(&mut self) -> Result<&[u8]>
fn consume(&mut self, amt: usize)
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize>
fn read_line(&mut self, buf: &mut String) -> Result<usize>

impl<L, R> Deref for Either<L, R> where L: Deref, R: Deref<Target = L::Target>,

type Target = <L as Deref>::Target;
fn deref(&self) -> &Self::Target

impl<L, R> DerefMut for Either<L, R> where L: DerefMut, R: DerefMut<Target = L::Target>,

fn deref_mut(&mut self) -> &mut Self::Target

impl<L, R> Display for Either<L, R> where L: Display, R: Display,

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<L, R> DoubleEndedIterator for Either<L, R> where L: DoubleEndedIterator, R: DoubleEndedIterator<Item = L::Item>,

fn next_back(&mut self) -> Option<Self::Item>
fn nth_back(&mut self, n: usize) -> Option<Self::Item>
fn rfold<Acc, G>(self, init: Acc, f: G) -> Acc
where
    G: FnMut(Acc, Self::Item) -> Acc,
fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>
where
    P: FnMut(&Self::Item) -> bool,

impl<L, R> Error for Either<L, R> where L: Error, R: Error,

fn source(&self) -> Option<&dyn Error + 'static>
fn description(&self) -> &str
fn cause(&self) -> Option<&dyn Error>

impl<L, R> ExactSizeIterator for Either<L, R> where L: ExactSizeIterator, R: ExactSizeIterator<Item = L::Item>,

fn len(&self) -> usize

impl<L, R> From<Result<R, L>> for Either<L, R>

fn from(r: Result<R, L>) -> Self

impl<L, R> FusedIterator for Either<L, R> where L: FusedIterator, R: FusedIterator<Item = L::Item>,

impl<L, R> Future for Either<L, R> where L: Future, R: Future<Output = L::Output>,

type Output = <L as Future>::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

impl<L, R> Iterator for Either<L, R> where L: Iterator, R: Iterator<Item = L::Item>,

type Item = <L as Iterator>::Item;
fn next(&mut self) -> Option<Self::Item>
fn size_hint(&self) -> (usize, Option<usize>)
fn fold<Acc, G>(self, init: Acc, f: G) -> Acc
where
    G: FnMut(Acc, Self::Item) -> Acc,
fn for_each<F>(self, f: F)
where
    F: FnMut(Self::Item),
fn count(self) -> usize
fn last(self) -> Option<Self::Item>
fn nth(&mut self, n: usize) -> Option<Self::Item>
fn collect<B>(self) -> B
where
    B: FromIterator<Self::Item>,
fn partition<B, F>(self, f: F) -> (B, B)
where
    B: Default + Extend<Self::Item>,
    F: FnMut(&Self::Item) -> bool,
fn all<F>(&mut self, f: F) -> bool
where
    F: FnMut(Self::Item) -> bool,
fn any<F>(&mut self, f: F) -> bool
where
    F: FnMut(Self::Item) -> bool,
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
where
    P: FnMut(&Self::Item) -> bool,
fn find_map<B, F>(&mut self, f: F) -> Option<B>
where
    F: FnMut(Self::Item) -> Option<B>,
fn position<P>(&mut self, predicate: P) -> Option<usize>
where
    P: FnMut(Self::Item) -> bool,

impl<L, R> LowerExp for Either<L, R> where L: LowerExp, R: LowerExp,

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<L, R> LowerHex for Either<L, R> where L: LowerHex, R: LowerHex,

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<L, R> Octal for Either<L, R> where L: Octal, R: Octal,

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<L, R> Pointer for Either<L, R> where L: Pointer, R: Pointer,

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<L, R> Read for Either<L, R> where L: Read, R: Read,

fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>

impl<L, R> Seek for Either<L, R> where L: Seek, R: Seek,

fn seek(&mut self, pos: SeekFrom) -> Result<u64>

impl<L, R> UpperExp for Either<L, R> where L: UpperExp, R: UpperExp,

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<L, R> UpperHex for Either<L, R> where L: UpperHex, R: UpperHex,

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<L, R> Write for Either<L, R> where L: Write, R: Write,

fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
fn flush(&mut self) -> Result<()>

impl<L, R> Write for Either<L, R> where L: Write, R: Write,

fn write_str(&mut self, s: &str) -> Result
fn write_char(&mut self, c: char) -> Result
fn write_fmt(&mut self, args: Arguments<'_>) -> Result

impl<L, R, A> Extend<A> for Either<L, R> where L: Extend<A>, R: Extend<A>,

fn extend<T>(&mut self, iter: T)
where
    T: IntoIterator<Item = A>,

impl<L, R, Target> AsMut<Target> for Either<L, R> where L: AsMut<Target>, R: AsMut<Target>,

fn as_mut(&mut self) -> &mut Target

impl<L, R, Target> AsMut<[Target]> for Either<L, R> where L: AsMut<[Target]>, R: AsMut<[Target]>,

fn as_mut(&mut self) -> &mut [Target]

impl<L, R, Target> AsRef<Target> for Either<L, R> where L: AsRef<Target>, R: AsRef<Target>,

fn as_ref(&self) -> &Target

impl<L, R, Target> AsRef<[Target]> for Either<L, R> where L: AsRef<[Target]>, R: AsRef<[Target]>,

fn as_ref(&self) -> &[Target]

impl<L: Clone, R: Clone> Clone for Either<L, R>

fn clone(&self) -> Self
fn clone_from(&mut self, source: &Self)

impl<L: Copy, R: Copy> Copy for Either<L, R>

impl<L: Debug, R: Debug> Debug for Either<L, R>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<L: Eq, R: Eq> Eq for Either<L, R>

impl<L: Hash, R: Hash> Hash for Either<L, R>

fn hash<__H: Hasher>(&self, state: &mut __H)

impl<L: Ord, R: Ord> Ord for Either<L, R>

fn cmp(&self, other: &Self) -> Ordering

impl<L: PartialEq, R: PartialEq> PartialEq for Either<L, R>

fn eq(&self, other: &Self) -> bool

impl<L: PartialEq, R: PartialEq> StructuralPartialEq for Either<L, R>

impl<L: PartialOrd, R: PartialOrd> PartialOrd for Either<L, R>

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

Auto Trait Implementations

impl<L, R> Freeze for Either<L, R> where L: Freeze, R: Freeze,

impl<L, R> RefUnwindSafe for Either<L, R> where L: RefUnwindSafe, R: RefUnwindSafe,

impl<L, R> Send for Either<L, R> where L: Send, R: Send,

impl<L, R> Sync for Either<L, R> where L: Sync, R: Sync,

impl<L, R> Unpin for Either<L, R> where L: Unpin, R: Unpin,

impl<L, R> UnsafeUnpin for Either<L, R> where L: UnsafeUnpin, R: UnsafeUnpin,

impl<L, R> UnwindSafe for Either<L, R> where L: UnwindSafe, R: UnwindSafe,

Blanket Implementations

impl<F> IntoFuture for Either<L, R> where F: Future,

type Output = <F as Future>::Output;
type IntoFuture = F;
fn into_future(self) -> <F as IntoFuture>::IntoFuture

impl<I> IntoIterator for Either<L, R> where I: Iterator,

type Item = <I as Iterator>::Item;
type IntoIter = I;
fn into_iter(self) -> I

impl<P, T> Receiver for Either<L, R> where P: Deref<Target = T> + ?Sized, T: ?Sized,

type Target = T;

impl<T> Any for Either<L, R> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Either<L, R> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Either<L, R> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Either<L, R> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Either<L, R>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> IntoEither for Either<L, R>

impl<T> ToOwned for Either<L, R> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> ToString for Either<L, R> where T: Display + ?Sized,

fn to_string(&self) -> String

impl<T, U> Into<U> for Either<L, R> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Either<L, R> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Either<L, R> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>