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§

§

Left

A body of type L.

Fields

§body: L
§

Right

A body of type R.

Fields

§body: R

Implementations§

source§

impl<L> EitherBody<L>

source

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>

source

pub fn left(body: L) -> EitherBody<L, R>

Creates new EitherBody using left variant.

source

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,

source§

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)

Performs copy-assignment from source. Read more
source§

impl<L, R> Debug for EitherBody<L, R>
where L: Debug, R: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<L, R> MessageBody for EitherBody<L, R>
where L: MessageBody + 'static, R: MessageBody + 'static,

source§

type Error = Error

The type of error that will be returned if streaming body fails. Read more
source§

fn size(&self) -> BodySize

Body size hint. Read more
source§

fn poll_next( self: Pin<&mut EitherBody<L, R>>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Bytes, <EitherBody<L, R> as MessageBody>::Error>>>

Attempt to pull out the next chunk of body bytes. Read more
source§

fn try_into_bytes(self) -> Result<Bytes, EitherBody<L, R>>

Try to convert into the complete chunk of body bytes. Read more
source§

fn boxed(self) -> BoxBody

Wraps this body into a BoxBody. Read more
source§

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>
where L: Freeze, R: Freeze,

§

impl<L, R> RefUnwindSafe for EitherBody<L, R>

§

impl<L, R> Send for EitherBody<L, R>
where L: Send, R: Send,

§

impl<L, R> Sync for EitherBody<L, R>
where L: Sync, R: Sync,

§

impl<L, R> UnwindSafe for EitherBody<L, R>
where L: UnwindSafe, R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more