Skip to main content

Body

Struct Body 

Source
pub struct Body { /* private fields */ }
Expand description

A response body, read in the chunks the platform delivers. The body pulls from the network only while its reader keeps up. Dropping it before the end cancels the request.

Implementations§

Source§

impl Body

Source

pub fn next(&mut self) -> NextChunk<'_> ⓘ

The next chunk; None after the last.

Source

pub fn next_blocking(&mut self) -> Option<Result<Vec<u8>, HttpError>>

Wait for the next chunk on this thread. Never call it on the UI thread.

Source

pub fn in_flight(&self) -> InFlight

A grip that cancels this body’s request from any thread, also after Body::read_async took the body.

Source

pub fn received(&self) -> u64

Bytes received so far, including chunks not read yet.

Source

pub fn expected_length(&self) -> Option<u64>

Content-Length, when the response declared one.

Source

pub fn metrics(&self) -> Option<Metrics>

Transfer metrics, once the platform reported them (usually just before the end).

Source

pub fn pause(&self)

Stop pulling from the network. Chunks already on their way still arrive.

Source

pub fn resume(&self)

Pull from the network again after Body::pause.

Source

pub fn read_async( self, on_chunk: impl FnMut(Option<Result<Vec<u8>, HttpError>>) -> bool + Send + 'static, )

Hand each chunk to on_chunk as it arrives, then None at the end or Some(Err) on failure. The body pulls the next chunk only after on_chunk returns; returning false cancels the request.

Trait Implementations§

Source§

impl Debug for Body

Source§

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

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

impl Drop for Body

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Body

§

impl !UnwindSafe for Body

§

impl Forget for Body

§

impl Freeze for Body

§

impl Move for Body

§

impl Send for Body

§

impl Sync for Body

§

impl Unpin for Body

§

impl UnsafeUnpin for Body

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.