titan_http::body

Enum Body

Source
pub enum Body {
    Full(Box<[u8]>),
    Stream(Pin<Box<dyn Stream<Item = Vec<u8>> + Send>>),
}
Expand description

Represents the body of an HTTP response.

The Body enum can either represent a fully-loaded body in memory or a stream of data. It is used as the response body when implementing the Respondable trait, allowing handlers to return either a complete body or a body that streams data incrementally.

§Variants

  • Full(Box<[u8]>): This variant holds the full body of the response in memory as a boxed byte slice. This is typically used when the response body is small enough to be loaded entirely into memory at once.

  • Stream(Pin<Box<dyn Stream<Item = Vec<u8>> + Send>>): This variant represents a streaming body, where the body is returned incrementally in chunks. This is useful when dealing with large responses (e.g., files or large datasets) that should be sent in multiple parts. The stream yields Vec<u8> chunks, allowing the receiver to process the data incrementally as it arrives.

This enum is not usually used of the library user and is quite low-level.

Variants§

§

Full(Box<[u8]>)

§

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

Trait Implementations§

Source§

impl Body for Body

Source§

type Data = Bytes

Values yielded by the Body.
Source§

type Error = Infallible

The error type this Body might generate.
Source§

fn size_hint(&self) -> SizeHint

Returns the bounds on the remaining length of the stream. Read more
Source§

fn poll_frame( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>>

Attempt to pull out the next data buffer of this stream.
Source§

fn is_end_stream(&self) -> bool

Returns true when the end of stream has been reached. Read more
Source§

impl From<&[u8]> for Body

Source§

fn from(value: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for Body

Source§

fn from(value: &'a 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<Box<[u8]>> for Body

Source§

fn from(value: Box<[u8]>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Body

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Body

Source§

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

Converts to this type from the input type.
Source§

impl From<i128> for Body

Source§

fn from(value: i128) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Body

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Body

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Body

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Body

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Body

Source§

fn from(value: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for Body

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Body

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Body

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Body

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Body

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Body

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Body

§

impl !RefUnwindSafe for Body

§

impl Send for Body

§

impl !Sync for Body

§

impl Unpin 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.