Skip to main content

BodyGuard

Struct BodyGuard 

Source
pub struct BodyGuard<B> { /* private fields */ }
Expand description

A body wrapped with explicit lifecycle policy.

Implementations§

Source§

impl<B> BodyGuard<B>

Source

pub fn new(inner: B) -> Self

Create a new guarded body.

Source

pub fn with_policy(inner: B, policy: BodyPolicy) -> Self

Create a new guarded body with an explicit policy.

Source

pub fn max_bytes(self, bytes: u64) -> Self

Set the maximum accepted body size in bytes.

Source

pub fn overflow(self, policy: OverflowPolicy) -> Self

Set overflow behavior.

Source

pub fn drop_policy(self, policy: DropPolicy) -> Self

Set drop behavior.

Source

pub fn drain_policy(self, policy: DrainPolicy) -> Self

Set drain behavior.

Source

pub fn replay_policy(self, policy: ReplayPolicy) -> Self

Set replay behavior.

Source

pub fn shutdown_policy(self, policy: ShutdownPolicy) -> Self

Set shutdown behavior.

Source

pub fn state(&self) -> BodyState

Return the current lifecycle state.

Source

pub fn policy(&self) -> &BodyPolicy

Return the configured policy.

Source

pub fn bytes_seen(&self) -> u64

Return the number of bytes observed through this guard.

Source

pub fn mark_pending(&mut self)

Mark the body as waiting for an underlying body or stream to become ready.

Source

pub fn mark_reading(&mut self)

Mark the body as currently being read.

Source

pub fn mark_draining(&mut self)

Mark the body as draining.

Source

pub fn mark_completed(&mut self)

Mark the body as completed.

Source

pub fn mark_aborted(&mut self)

Mark the body as aborted.

Source

pub fn observe_bytes(&mut self, bytes: u64) -> BodyDecision

Record newly observed bytes and return the policy decision.

Source

pub fn into_inner(self) -> B

Consume the guard and return the inner body.

Trait Implementations§

Source§

impl<B: Debug> Debug for BodyGuard<B>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B> Freeze for BodyGuard<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for BodyGuard<B>
where B: RefUnwindSafe,

§

impl<B> Send for BodyGuard<B>
where B: Send,

§

impl<B> Sync for BodyGuard<B>
where B: Sync,

§

impl<B> Unpin for BodyGuard<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for BodyGuard<B>
where B: UnsafeUnpin,

§

impl<B> UnwindSafe for BodyGuard<B>
where B: 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.