Enum awc::body::EitherBody
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§
§impl<L> EitherBody<L>
impl<L> EitherBody<L>
pub 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.
§impl<L, R> EitherBody<L, R>
impl<L, R> EitherBody<L, R>
pub fn left(body: L) -> EitherBody<L, R>
pub fn left(body: L) -> EitherBody<L, R>
Creates new EitherBody
using left variant.
pub fn right(body: R) -> EitherBody<L, R>
pub fn right(body: R) -> EitherBody<L, R>
Creates new EitherBody
using right variant.
Trait Implementations§
§impl<L, R> Clone for EitherBody<L, R>
impl<L, R> Clone for EitherBody<L, R>
§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