pub enum EitherBody<L, R = BoxBody> {
    Left {
        body: L,
    },
    Right {
        body: R,
    },
}Expand description
An “either” type specialized for body types.
It is common, in middleware especially, to conditionally return an inner service’s unknown/
generic body B type or return early with a new response. This type’s “right” variant
defaults to BoxBody since error responses are the common case.
For example, middleware will often have type Response = ServiceResponse<EitherBody<B>>.
This means that the inner service’s response body type maps to the Left variant and the
middleware’s own error responses use the default Right variant of BoxBody. Of course,
there’s no reason it couldn’t use EitherBody<B, String> instead if its alternative
responses have a known type.
Variants§
Implementations§
Source§impl<L> EitherBody<L>
 
impl<L> EitherBody<L>
Sourcepub fn new(body: L) -> EitherBody<L>
 
pub fn new(body: L) -> EitherBody<L>
Creates new EitherBody left variant with a boxed right variant.
If the expected R type will be inferred and is not BoxBody then use the
left constructor instead.
Source§impl<L, R> EitherBody<L, R>
 
impl<L, R> EitherBody<L, R>
Sourcepub fn left(body: L) -> EitherBody<L, R>
 
pub fn left(body: L) -> EitherBody<L, R>
Creates new EitherBody using left variant.
Sourcepub fn right(body: R) -> EitherBody<L, R>
 
pub fn right(body: R) -> EitherBody<L, R>
Creates new EitherBody using right variant.
Trait Implementations§
Source§impl<L, R> Clone for EitherBody<L, R>
 
impl<L, R> Clone for EitherBody<L, R>
Source§fn clone(&self) -> EitherBody<L, R>
 
fn clone(&self) -> EitherBody<L, R>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<L, R> Debug for EitherBody<L, R>
 
impl<L, R> Debug for EitherBody<L, R>
Source§impl<L, R> MessageBody for EitherBody<L, R>where
    L: MessageBody + 'static,
    R: MessageBody + 'static,
 
impl<L, R> MessageBody for EitherBody<L, R>where
    L: MessageBody + 'static,
    R: MessageBody + 'static,
Source§fn poll_next(
    self: Pin<&mut EitherBody<L, R>>,
    cx: &mut Context<'_>,
) -> Poll<Option<Result<Bytes, <EitherBody<L, R> as MessageBody>::Error>>>
 
fn poll_next( self: Pin<&mut EitherBody<L, R>>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Bytes, <EitherBody<L, R> as MessageBody>::Error>>>
Source§fn try_into_bytes(self) -> Result<Bytes, EitherBody<L, R>>
 
fn try_into_bytes(self) -> Result<Bytes, EitherBody<L, R>>
impl<'__pin, L, R> Unpin for EitherBody<L, R>where
    <PinnedFieldsOfHelperStruct<__Origin<'__pin, L, R>> as PinnedFieldsOfHelperTrait>::Actual: Unpin,
Auto Trait Implementations§
impl<L, R> Freeze for EitherBody<L, R>
impl<L, R> RefUnwindSafe for EitherBody<L, R>where
    L: RefUnwindSafe,
    R: RefUnwindSafe,
impl<L, R> Send for EitherBody<L, R>
impl<L, R> Sync for EitherBody<L, R>
impl<L, R> UnwindSafe for EitherBody<L, R>where
    L: UnwindSafe,
    R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<T> Instrument for T
 
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
 
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
 
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more