Skip to main content

Body

Enum Body 

Source
pub enum Body {
    Empty,
    Full(FullBody),
    Stream(StreamBody),
}
Expand description

The body type for requests and responses in the OxiHTTP stack.

This enum supports three modes:

  • Empty: No body content.
  • Full: A body fully buffered in memory as Bytes.
  • Stream: A streaming body backed by an async byte stream.

Variants§

§

Empty

An empty body with no content.

§

Full(FullBody)

A body fully loaded in memory.

§

Stream(StreamBody)

A streaming body. The inner stream is opaque.

Implementations§

Source§

impl Body

Source

pub fn empty() -> Self

Create an empty body.

Source

pub fn full(data: impl Into<Bytes>) -> Self

Create a body from bytes already in memory.

Source

pub fn stream( inner: Pin<Box<dyn Stream<Item = Result<Bytes, OxiHttpError>> + Send>>, ) -> Self

Create a streaming body from a pinned async byte-chunk stream.

Source

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

Returns the content length if known.

Returns Some(0) for empty bodies, Some(n) for full bodies, and None for streams (unknown length).

Source

pub fn into_pinned(self) -> PinnedBody

Convert this Body into a PinnedBody suitable for use with http_body::Body.

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 Default for Body

Source§

fn default() -> Body

Returns the “default value” for a type. Read more
Source§

impl From<&'static [u8]> for Body

Source§

fn from(s: &'static [u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&'static str> for Body

Source§

fn from(s: &'static str) -> Self

Converts to this type from the input type.
Source§

impl From<()> for Body

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl From<Body> for PinnedBody

Source§

fn from(body: Body) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for Body

Source§

fn from(b: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Body

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Body

Source§

fn from(v: Vec<u8>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !Freeze for Body

§

impl !RefUnwindSafe for Body

§

impl !Sync for Body

§

impl !UnwindSafe for Body

§

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