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> Either<A, B>
impl<A, B> Either<A, B>
sourcepub fn as_pin_ref(self: Pin<&Self>) -> Either<Pin<&A>, Pin<&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;
pub fn as_pin_ref(self: Pin<&Self>) -> Either<Pin<&A>, Pin<&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;
Convert Pin<&Either<A, B>>
to Either<Pin<&A>, Pin<&B>>
,
pinned projections of the inner variants.
sourcepub fn as_pin_mut(self: Pin<&mut Self>) -> Either<Pin<&mut A>, Pin<&mut 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;
pub fn as_pin_mut(self: Pin<&mut Self>) -> Either<Pin<&mut A>, Pin<&mut 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;
Convert Pin<&mut Either<A, B>>
to Either<Pin<&mut A>, Pin<&mut B>>
,
pinned projections of the inner variants.
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 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl<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 Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
sourcefn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more