Struct salvo::hyper::Body[]

#[must_use = "streams do nothing unless polled"]pub struct Body { /* fields omitted */ }

A stream of Bytes, used when receiving bodies.

A good default HttpBody to use in many applications.

Note: To read the full body, use body::to_bytes or body::aggregate.

Implementations

impl Body

pub fn empty() -> Body

Create an empty Body stream.

Example

use hyper::{Body, Request};

// create a `GET /` request
let get = Request::new(Body::empty());

pub fn channel() -> (Sender, Body)

Create a Body stream with an associated sender half.

Useful when wanting to stream chunks from another thread.

pub fn wrap_stream<S, O, E>(stream: S) -> Body where
    E: Into<Box<dyn Error + 'static + Sync + Send, Global>> + 'static,
    S: Stream<Item = Result<O, E>> + Send + 'static,
    O: Into<Bytes> + 'static, 

Wrap a futures Stream in a box inside Body.

Example

let chunks: Vec<Result<_, std::io::Error>> = vec![
    Ok("hello"),
    Ok(" "),
    Ok("world"),
];

let stream = futures_util::stream::iter(chunks);

let body = Body::wrap_stream(stream);

Optional

This function requires enabling the stream feature in your Cargo.toml.

Trait Implementations

impl Body for Body

type Data = Bytes

Values yielded by the Body.

type Error = Error

The error type this Body might generate.

impl Debug for Body

impl Default for Body

pub fn default() -> Body

Returns Body::empty().

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

impl From<&'static str> for Body

impl From<Body> for Body[src]

impl From<Box<dyn Stream<Item = Result<Bytes, Box<dyn Error + 'static + Sync + Send, Global>>> + 'static + Send, Global>> for Body

Optional

This function requires enabling the stream feature in your Cargo.toml.

impl From<Bytes> for Body

impl From<Cow<'static, [u8]>> for Body

impl From<Cow<'static, str>> for Body

impl From<String> for Body

impl From<Vec<u8, Global>> for Body

impl Stream for Body

Optional

This function requires enabling the stream feature in your Cargo.toml.

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> Instrument for T[src]

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

impl<T> Same<T> for T

type Output = T

Should always be Self

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

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

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

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

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