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, BoxBody>
impl<L> EitherBody<L, BoxBody>
Trait Implementations§
source§impl<L: Clone, R: Clone> Clone for EitherBody<L, R>
impl<L: Clone, R: Clone> Clone for EitherBody<L, R>
source§fn clone(&self) -> EitherBody<L, R>
fn clone(&self) -> EitherBody<L, R>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§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,
impl<'__pin, L, R> Unpin for EitherBody<L, R>where
PinnedFieldsOf<__Origin<'__pin, L, R>>: 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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)