Enum futures_util::future::Either
source · [−]pub enum Either<A, B> {
Left(A),
Right(B),
}
Expand description
Combines two different futures, streams, or sinks having the same associated types into a single type.
This is useful when conditionally choosing between two distinct future types:
use futures::future::Either;
let cond = true;
let fut = if cond {
Either::Left(async move { 12 })
} else {
Either::Right(async move { 44 })
};
assert_eq!(fut.await, 12);
Variants
Left(A)
First branch of the type
Right(B)
Second branch of the type
Implementations
sourceimpl<A, B, T> Either<(T, A), (T, B)>
impl<A, B, T> Either<(T, A), (T, B)>
sourcepub fn factor_first(self) -> (T, Either<A, B>)
pub fn factor_first(self) -> (T, Either<A, B>)
Factor out a homogeneous type from an either of pairs.
Here, the homogeneous type is the first element of the pairs.
sourceimpl<A, B, T> Either<(A, T), (B, T)>
impl<A, B, T> Either<(A, T), (B, T)>
sourcepub fn factor_second(self) -> (Either<A, B>, T)
pub fn factor_second(self) -> (Either<A, B>, T)
Factor out a homogeneous type from an either of pairs.
Here, the homogeneous type is the second element of the pairs.
sourceimpl<T> Either<T, T>
impl<T> Either<T, T>
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Extract the value of an either over two equivalent types.
Trait Implementations
sourceimpl<A: Clone, B: Clone> Clone for Either<A, B>
impl<A: Clone, B: Clone> Clone for Either<A, B>
sourcefn clone(&self) -> Either<A, B>ⓘNotable traits for Either<A, B>impl<A, B> Future for Either<A, B> where
A: Future,
B: Future<Output = A::Output>, type Output = A::Output;
fn clone(&self) -> Either<A, B>ⓘNotable traits for Either<A, B>impl<A, B> Future for Either<A, B> where
A: Future,
B: Future<Output = A::Output>, type Output = A::Output;
A: Future,
B: Future<Output = A::Output>, type Output = A::Output;
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<A, B> FusedFuture for Either<A, B> where
A: FusedFuture,
B: FusedFuture<Output = A::Output>,
impl<A, B> FusedFuture for Either<A, B> where
A: FusedFuture,
B: FusedFuture<Output = A::Output>,
sourcefn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
Returns true
if the underlying future should no longer be polled.
sourceimpl<A, B> FusedStream for Either<A, B> where
A: FusedStream,
B: FusedStream<Item = A::Item>,
impl<A, B> FusedStream for Either<A, B> where
A: FusedStream,
B: FusedStream<Item = A::Item>,
sourcefn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
Returns true
if the stream should no longer be polled.
sourceimpl<A, B> Stream for Either<A, B> where
A: Stream,
B: Stream<Item = A::Item>,
impl<A, B> Stream for Either<A, B> where
A: Stream,
B: Stream<Item = A::Item>,
Auto Trait Implementations
impl<A, B> RefUnwindSafe for Either<A, B> where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> Send for Either<A, B> where
A: Send,
B: Send,
impl<A, B> Sync for Either<A, B> where
A: Sync,
B: Sync,
impl<A, B> Unpin for Either<A, B> where
A: Unpin,
B: Unpin,
impl<A, B> UnwindSafe for Either<A, B> where
A: UnwindSafe,
B: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<F> IntoFuture for F where
F: Future,
impl<F> IntoFuture for F where
F: Future,
type Output = <F as Future>::Output
type Output = <F as Future>::Output
into_future
)The output that the future will produce on completion.
type Future = F
type Future = F
into_future
)Which kind of future are we turning this into?
sourcepub fn into_future(self) -> <F as IntoFuture>::Future
pub fn into_future(self) -> <F as IntoFuture>::Future
into_future
)Creates a future from a value.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more