Enum Either

enum Either<A, B>

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;

# futures::executor::block_on(async {
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

impl<A, B> Either<A, B>

fn as_pin_ref(self: Pin<&Self>) -> Either<Pin<&A>, Pin<&B>>

Convert Pin<&Either<A, B>> to Either<Pin<&A>, Pin<&B>>, pinned projections of the inner variants.

fn as_pin_mut(self: Pin<&mut Self>) -> Either<Pin<&mut A>, Pin<&mut B>>

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

impl<A, B, T> Either<(A, T), (B, T)>

fn factor_second(self: 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.

impl<A, B, T> Either<(T, A), (T, B)>

fn factor_first(self: 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.

impl<T> Either<T, T>

fn into_inner(self: Self) -> T

Extract the value of an either over two equivalent types.

impl<A, B> AsyncBufRead for Either<A, B>

fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<&[u8]>>
fn consume(self: Pin<&mut Self>, amt: usize)

impl<A, B> AsyncRead for Either<A, B>

fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<Result<usize>>
fn poll_read_vectored(self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>]) -> Poll<Result<usize>>

impl<A, B> AsyncSeek for Either<A, B>

fn poll_seek(self: Pin<&mut Self>, cx: &mut Context<'_>, pos: SeekFrom) -> Poll<Result<u64>>

impl<A, B> AsyncWrite for Either<A, B>

fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>
fn poll_write_vectored(self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>]) -> Poll<Result<usize>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

impl<A, B> Freeze for Either<A, B>

impl<A, B> FusedFuture for Either<A, B>

fn is_terminated(self: &Self) -> bool

impl<A, B> FusedStream for Either<A, B>

fn is_terminated(self: &Self) -> bool

impl<A, B> Future for Either<A, B>

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

impl<A, B> RefUnwindSafe for Either<A, B>

impl<A, B> Send for Either<A, B>

impl<A, B> Stream for Either<A, B>

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<<Self as >::Item>>
fn size_hint(self: &Self) -> (usize, Option<usize>)

impl<A, B> Sync for Either<A, B>

impl<A, B> Unpin for Either<A, B>

impl<A, B> UnsafeUnpin for Either<A, B>

impl<A, B> UnwindSafe for Either<A, B>

impl<A, B, Item> Sink for Either<A, B>

fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), <Self as >::Error>>
fn start_send(self: Pin<&mut Self>, item: Item) -> Result<(), <Self as >::Error>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), <Self as >::Error>>
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), <Self as >::Error>>

impl<A: $crate::clone::Clone, B: $crate::clone::Clone> Clone for Either<A, B>

fn clone(self: &Self) -> Either<A, B>

impl<A: $crate::fmt::Debug, B: $crate::fmt::Debug> Debug for Either<A, B>

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

impl<F> IntoFuture for Either<A, B>

fn into_future(self: Self) -> <F as IntoFuture>::IntoFuture

impl<F, T, E> TryFuture for Either<A, B>

fn try_poll(self: Pin<&mut F>, cx: &mut Context<'_>) -> Poll<<F as Future>::Output>

impl<Fut> TryFutureExt for Either<A, B>

impl<R> AsyncBufReadExt for Either<A, B>

impl<R> AsyncReadExt for Either<A, B>

impl<S> AsyncSeekExt for Either<A, B>

impl<S> TryStreamExt for Either<A, B>

impl<S, T, E> TryStream for Either<A, B>

fn try_poll_next(self: Pin<&mut S>, cx: &mut Context<'_>) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

impl<T> Any for Either<A, B>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Either<A, B>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Either<A, B>

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

impl<T> CloneToUninit for Either<A, B>

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

impl<T> From for Either<A, B>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FutureExt for Either<A, B>

impl<T> StreamExt for Either<A, B>

impl<T> ToOwned for Either<A, B>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, Item> SinkExt for Either<A, B>

impl<T, U> Into for Either<A, B>

fn into(self: 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 for Either<A, B>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Either<A, B>

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

impl<W> AsyncWriteExt for Either<A, B>