Enum actix_web::body::EitherBody
source · 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>
sourcepub fn new(body: L) -> EitherBody<L, BoxBody>
pub fn new(body: L) -> EitherBody<L, BoxBody>
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>where
L: Clone,
R: Clone,
impl<L, R> Clone for EitherBody<L, R>where L: Clone, R: Clone,
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 more