[−][src]Struct hyper::Body
A stream of Bytes
, used when receiving bodies.
A good default HttpBody
to use in many
applications.
Methods
impl Body
[src][−]
pub fn empty() -> Body
[src][−]
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)
[src][−]
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
S: Stream<Item = Result<O, E>> + Send + Sync + 'static,
O: Into<Bytes> + 'static,
E: Into<Box<dyn StdError + Send + Sync>> + 'static,
[src][−]
S: Stream<Item = Result<O, E>> + Send + Sync + 'static,
O: Into<Bytes> + 'static,
E: Into<Box<dyn StdError + Send + Sync>> + '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
.
ⓘImportant traits for OnUpgradepub fn on_upgrade(self) -> OnUpgrade
[src][−]
ⓘImportant traits for OnUpgrade
Converts this Body
into a Future
of a pending HTTP upgrade.
See the upgrade
module for more.
Trait Implementations
impl Body for Body
[src][+]
impl Debug for Body
[src][+]
impl Default for Body
[src][+]
impl From<&'static [u8]> for Body
[src][+]
impl From<&'static str> for Body
[src][+]
impl From<Box<dyn Stream<Item = Result<Bytes, Box<dyn Error + 'static + Sync + Send>>> + 'static + Sync + Send>> for Body
[src][+]
fn from(
stream: Box<dyn Stream<Item = Result<Bytes, Box<dyn StdError + Send + Sync>>> + Send + Sync>
) -> Body
[src][−]
stream: Box<dyn Stream<Item = Result<Bytes, Box<dyn StdError + Send + Sync>>> + Send + Sync>
) -> Body
impl From<Bytes> for Body
[src][+]
impl From<Cow<'static, [u8]>> for Body
[src][+]
impl From<Cow<'static, str>> for Body
[src][+]
impl From<String> for Body
[src][+]
impl From<Vec<u8>> for Body
[src][+]
impl Stream for Body
[src][+]
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][+]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> From<T> for T
[src][+]
impl<T, U> Into<U> for T where
U: From<T>,
[src][+]
U: From<T>,
impl<T> StreamExt for T where
T: Stream + ?Sized,
[src][+]
T: Stream + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,
impl<S, T, E> TryStream for S where
S: Stream<Item = Result<T, E>> + ?Sized,
[src][+]
S: Stream<Item = Result<T, E>> + ?Sized,
impl<S> TryStreamExt for S where
S: TryStream + ?Sized,
[src][+]
S: TryStream + ?Sized,