Trait either::IntoEither
source · pub trait IntoEither: Sized {
// Provided methods
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ { ... }
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool { ... }
}
Expand description
Provides methods for converting a type Self
into either a Left
or Right
variant of Either<Self, Self>
.
The into_either
method takes a bool
to determine
whether to convert to Left
or Right
.
The into_either_with
method takes a
predicate function to determine whether to convert to Left
or Right
.
Provided Methods§
sourcefn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise.
§Examples
use either::{IntoEither, Left, Right};
let x = 0;
assert_eq!(x.into_either(true), Left(x));
assert_eq!(x.into_either(false), Right(x));
sourcefn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise.
§Examples
use either::{IntoEither, Left, Right};
fn is_even(x: &u8) -> bool {
x % 2 == 0
}
let x = 0;
assert_eq!(x.into_either_with(is_even), Left(x));
assert_eq!(x.into_either_with(|x| !is_even(x)), Right(x));
Object Safety§
This trait is not object safe.