Enum Either
pub 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 Either;
# block_on
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>>toEither<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>>toEither<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) -> (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) -> (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) -> TExtract the value of an either over two equivalent types.
Trait Implementations
impl<A, B> AsyncBufRead for Either<A, B>
where
A: AsyncBufRead,
B: AsyncBufRead,
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>
where
A: AsyncRead,
B: AsyncRead,
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>
where
A: AsyncSeek,
B: AsyncSeek,
fn poll_seek(self: Pin<&mut Self>, cx: &mut Context<'_>, pos: SeekFrom) -> Poll<Result<u64>>
impl<A, B> AsyncWrite for Either<A, B>
where
A: AsyncWrite,
B: AsyncWrite,
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> FusedFuture for Either<A, B>
where
A: FusedFuture,
B: FusedFuture<Output = A::Output>,
fn is_terminated(&self) -> bool
impl<A, B> FusedStream for Either<A, B>
where
A: FusedStream,
B: FusedStream<Item = A::Item>,
fn is_terminated(&self) -> bool
impl<A, B> Future for Either<A, B>
where
A: Future,
B: Future<Output = A::Output>,
type Output = <A as Future>::Output;fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>
impl<A, B> Stream for Either<A, B>
where
A: Stream,
B: Stream<Item = A::Item>,
type Item = <A as Stream>::Item;fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>fn size_hint(&self) -> (usize, Option<usize>)
impl<A, B, Item> Sink<Item> for Either<A, B>
where
A: Sink<Item>,
B: Sink<Item, Error = A::Error>,
type Error = <A as Sink<Item>>::Error;fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>fn start_send(self: Pin<&mut Self>, item: Item) -> Result<(), Self::Error>fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
impl<A: Clone, B: Clone> Clone for Either<A, B>
fn clone(&self) -> Self
impl<A: Debug, B: Debug> Debug for Either<A, B>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl<A, B> Freeze for Either<A, B>
where
A: Freeze,
B: Freeze,
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> UnsafeUnpin for Either<A, B>
where
A: UnsafeUnpin,
B: UnsafeUnpin,
impl<A, B> UnwindSafe for Either<A, B>
where
A: UnwindSafe,
B: UnwindSafe,
Blanket Implementations
impl<F> IntoFuture for Either<A, B>
where
F: Future,
type Output = <F as Future>::Output;type IntoFuture = F;fn into_future(self) -> <F as IntoFuture>::IntoFuture
impl<F, T, E> TryFuture for Either<A, B>
where
F: Future<Output = Result<T, E>> + ?Sized,
type Ok = T;type Error = E;fn try_poll(self: Pin<&mut F>, cx: &mut Context<'_>) -> Poll<<F as Future>::Output>
impl<Fut> TryFutureExt for Either<A, B>
where
Fut: TryFuture + ?Sized,
impl<R> AsyncBufReadExt for Either<A, B>
where
R: AsyncBufRead + ?Sized,
impl<R> AsyncReadExt for Either<A, B>
where
R: AsyncRead + ?Sized,
impl<S> AsyncSeekExt for Either<A, B>
where
S: AsyncSeek + ?Sized,
impl<S> TryStreamExt for Either<A, B>
where
S: TryStream + ?Sized,
impl<S, T, E> TryStream for Either<A, B>
where
S: Stream<Item = Result<T, E>> + ?Sized,
type Ok = T;type Error = E;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>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Either<A, B>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Either<A, B>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Either<A, B>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Either<A, B>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> FutureExt for Either<A, B>
where
T: Future + ?Sized,
impl<T> StreamExt for Either<A, B>
where
T: Stream + ?Sized,
impl<T> ToOwned for Either<A, B>
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, Item> SinkExt<Item> for Either<A, B>
where
T: Sink<Item> + ?Sized,
impl<T, U> Into<U> for Either<A, B>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Either<A, B>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Either<A, B>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>