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§
Implementations§
source§impl<A, B> Either<A, B>
impl<A, B> Either<A, B>
source§impl<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.
source§impl<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.
source§impl<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§
source§impl<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>,
source§fn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
Returns
true
if the underlying future should no longer be polled.source§impl<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>,
source§fn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
Returns
true
if the stream should no longer be polled.source§impl<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§
source§impl<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?
source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more