[][src]Enum roa::Body

pub enum Body {
    Empty,
    Once(Bytes),
    Stream(Segment),
}

The body of response.

Example

use roa_core::Body;
use futures::StreamExt;
use std::io;
use bytes::Bytes;

async fn read_body(body: Body) -> io::Result<Bytes> {
    Ok(match body {
        Body::Empty => Bytes::new(),
        Body::Once(bytes) => bytes,
        Body::Stream(mut stream) => {
            let mut bytes = Vec::new();
            while let Some(item) = stream.next().await {
                bytes.extend_from_slice(&*item?);
            }
            bytes.into()
        }
    })
}

Variants

Empty

Empty kind

Once(Bytes)

Bytes kind.

Stream(Segment)

Stream kind.

Methods

impl Body[src]

pub fn empty() -> Body[src]

Construct an empty body.

pub fn once(bytes: impl Into<Bytes>) -> Body[src]

Construct a once body.

pub fn stream<S>(stream: S) -> Body where
    S: Stream<Item = Result<Bytes, Error>> + Sync + Send + 'static, 
[src]

Construct an empty body of stream kind.

pub fn write_stream(
    &mut self,
    stream: impl Send + Sync + Stream<Item = Result<Bytes, Error>> + 'static
) -> &mut Body
[src]

Write stream.

pub fn write_reader(
    &mut self,
    reader: impl Send + Sync + Unpin + AsyncRead + 'static
) -> &mut Body
[src]

Write reader with default chunk size.

pub fn write_chunk(
    &mut self,
    reader: impl Send + Sync + Unpin + AsyncRead + 'static,
    chunk_size: usize
) -> &mut Body
[src]

Write reader with chunk size.

pub fn write(&mut self, data: impl Into<Bytes>) -> &mut Body[src]

Write Bytes.

Trait Implementations

impl Default for Body[src]

impl Stream for Body[src]

type Item = Result<Bytes, Error>

Values yielded by the stream.

Auto Trait Implementations

impl !RefUnwindSafe for Body

impl Send for Body

impl Sync for Body

impl Unpin for Body

impl !UnwindSafe for Body

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoStream for I where
    I: Stream
[src]

type Item = <I as Stream>::Item

The type of the elements being iterated over.

type IntoStream = I

Which kind of stream are we turning this into?

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<St> StreamExt for St where
    St: Stream + ?Sized
[src]

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<S, T, E> TryStream for S where
    S: Stream<Item = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<S> TryStreamExt for S where
    S: TryStream + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,