Skip to main content

Body

Enum Body 

Source
pub enum Body {
    Empty,
    Static(&'static [u8]),
    Bytes(Vec<u8>),
    Stream(Box<dyn Iterator<Item = Vec<u8>> + Send>),
    File {
        fd: OwnedFd,
        offset: u64,
        len: u64,
    },
    Raw(&'static [u8]),
}
Expand description

The body of an HTTP response.

Supports multiple storage strategies: zero-copy static slices, heap-allocated bytes, streaming iterators, and kernel-level sendfile for files.

Variants§

§

Empty

No body content.

§

Static(&'static [u8])

A compile-time static byte slice — zero allocation, zero copy.

§

Bytes(Vec<u8>)

Heap-allocated byte vector.

§

Stream(Box<dyn Iterator<Item = Vec<u8>> + Send>)

Chunked streaming body — each call to next() yields a chunk.

§

File

Zero-copy file body — served via sendfile() entirely in kernel space. The fd is owned and will be closed when the response is consumed or dropped.

Fields

§offset: u64
§len: u64
§

Raw(&'static [u8])

Fully pre-baked raw HTTP response (status line + headers + body) as a static byte slice. The worker writes this verbatim, bypassing ALL header serialization logic. Maximum throughput — zero overhead.

Use Response::raw to construct. You are responsible for producing a valid HTTP/1.1 response including “\r\n\r\n” and the body.

Implementations§

Source§

impl Body

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn as_bytes(&self) -> &[u8]

Source

pub fn is_file(&self) -> bool

Returns true if this body will be served via zero-copy sendfile.

Source

pub fn is_raw(&self) -> bool

Returns true if this body is a pre-baked full raw HTTP response.

Auto Trait Implementations§

§

impl Freeze for Body

§

impl !RefUnwindSafe for Body

§

impl Send for Body

§

impl !Sync for Body

§

impl Unpin for Body

§

impl UnsafeUnpin for Body

§

impl !UnwindSafe 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.