Struct Body

Source
pub struct Body { /* private fields */ }
Expand description

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§

Source§

impl Body

Source

pub fn empty() -> Body

Create an empty Body stream.

§Example
use hyper::{Body, Request};

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

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

Create a Body stream with an associated sender half.

Useful when wanting to stream chunks from another thread.

Trait Implementations§

Source§

impl Body for Body

Source§

type Data = Bytes

Values yielded by the Body.
Source§

type Error = Error

The error type this Body might generate.
Source§

fn poll_data( self: Pin<&mut Body>, cx: &mut Context<'_>, ) -> Poll<Option<Result<<Body as Body>::Data, <Body as Body>::Error>>>

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

fn poll_trailers( self: Pin<&mut Body>, cx: &mut Context<'_>, ) -> Poll<Result<Option<HeaderMap>, <Body as Body>::Error>>

Poll for an optional single HeaderMap of trailers. Read more
Source§

fn is_end_stream(&self) -> bool

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

fn size_hint(&self) -> SizeHint

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

fn data(&mut self) -> Data<'_, Self>
where Self: Sized + Unpin,

Returns future that resolves to next data chunk, if any.
Source§

fn trailers(&mut self) -> Trailers<'_, Self>
where Self: Sized + Unpin,

Returns future that resolves to trailers, if any.
Source§

fn map_data<F, B>(self, f: F) -> MapData<Self, F>
where Self: Sized, F: FnMut(Self::Data) -> B, B: Buf,

Maps this body’s data value to a different value.
Source§

fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
where Self: Sized, F: FnMut(Self::Error) -> E,

Maps this body’s error value to a different value.
Source§

fn collect(self) -> Collect<Self>
where Self: Sized,

Turn this body into Collected body which will collect all the DATA frames and trailers.
Source§

fn boxed(self) -> BoxBody<Self::Data, Self::Error>
where Self: Sized + Send + Sync + 'static,

Turn this body into a boxed trait object.
Source§

fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
where Self: Sized + Send + 'static,

Turn this body into a boxed trait object that is !Sync.
Source§

impl Debug for Body

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Body

Source§

fn default() -> Body

Returns Body::empty().

Source§

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

Source§

fn from(slice: &'static [u8]) -> Body

Converts to this type from the input type.
Source§

impl From<&'static str> for Body

Source§

fn from(slice: &'static str) -> Body

Converts to this type from the input type.
Source§

impl From<Bytes> for Body

Source§

fn from(chunk: Bytes) -> Body

Converts to this type from the input type.
Source§

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

Source§

fn from(cow: Cow<'static, [u8]>) -> Body

Converts to this type from the input type.
Source§

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

Source§

fn from(cow: Cow<'static, str>) -> Body

Converts to this type from the input type.
Source§

impl From<String> for Body

Source§

fn from(s: String) -> Body

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Body

Source§

fn from(vec: Vec<u8>) -> Body

Converts to this type from the input type.
Source§

impl ResponseExtBuild<Body> for Response<Body>

Source§

fn new_with_status_and_body( _status: StatusCode, _body: impl Into<Body>, _content_type: Option<impl Into<HeaderValue>>, ) -> Self

Source§

fn new_empty() -> Self
where B: Default,

Source§

fn new_with_status(_status: StatusCode) -> Self
where B: Default,

Source§

fn new_201() -> Self
where B: Default,

Source§

fn new_200_with_body( _body: impl Into<B>, _content_type: Option<impl Into<HeaderValue>>, ) -> Self

Source§

fn new_200_with_text(_body: impl Into<B>) -> Self

Source§

fn new_200_with_html(_body: impl Into<B>) -> Self

Source§

fn new_200() -> Self
where B: From<&'static str>,

Source§

fn new_301(_location: impl Into<HeaderValue>) -> Self
where B: Default,

Source§

fn new_302(_location: impl Into<HeaderValue>) -> Self
where B: Default,

Source§

fn new_303(_location: impl Into<HeaderValue>) -> Self
where B: Default,

Source§

fn new_307(_location: impl Into<HeaderValue>) -> Self
where B: Default,

Source§

fn new_308(_location: impl Into<HeaderValue>) -> Self
where B: Default,

Source§

fn new_301_str_static(_location: &'static str) -> Self
where B: Default,

Source§

fn new_302_str_static(_location: &'static str) -> Self
where B: Default,

Source§

fn new_303_str_static(_location: &'static str) -> Self
where B: Default,

Source§

fn new_307_str_static(_location: &'static str) -> Self
where B: Default,

Source§

fn new_308_str_static(_location: &'static str) -> Self
where B: Default,

Source§

fn new_301_string(_location: String) -> Self
where B: Default,

Source§

fn new_302_string(_location: String) -> Self
where B: Default,

Source§

fn new_303_string(_location: String) -> Self
where B: Default,

Source§

fn new_307_string(_location: String) -> Self
where B: Default,

Source§

fn new_308_string(_location: String) -> Self
where B: Default,

Source§

fn new_redirect_with_code( _status: StatusCode, _location: impl Into<HeaderValue>, ) -> Self
where B: Default,

Source§

fn new_404() -> Self
where B: From<&'static str>,

Source§

fn new_method_not_allowed() -> Self
where B: From<&'static str>,

Source§

fn ok<E>(self) -> Result<Self, E>

Source§

fn ok_0(self) -> Result<Self, ServerError>

Source§

fn ready<E>(self) -> Ready<Result<Self, E>>

Source§

fn ready_0(self) -> Ready<Result<Self, ServerError>>

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<B> BodyDyn for B
where B: Body<Data = Bytes> + Send + 'static, <B as Body>::Error: Error + Send + Sync + 'static,

Source§

fn poll_data( self: Pin<&mut B>, _context: &mut Context<'_>, ) -> Poll<Option<Result<Bytes, Error>>>

Source§

fn poll_trailers( self: Pin<&mut B>, _context: &mut Context<'_>, ) -> Poll<Result<Option<HeaderMap>, Error>>

Source§

fn is_end_stream(&self) -> bool

Source§

fn size_hint(&self) -> SizeHint

Source§

impl<B> BodyExt for B
where B: Body<Data = Bytes> + Send + Sync + 'static + Unpin, <B as Body>::Error: Error + Send + Sync + 'static,

Source§

fn consume_into_vec( &mut self, _buffer: &mut Vec<u8>, _runtime: Option<&Runtime>, ) -> Result<(), Error>

Source§

fn consume_to_vec( &mut self, _runtime: Option<&Runtime>, ) -> ServerResult<Vec<u8>>

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<EI, EO> ErrorExtWrap<EO> for EI
where EO: ErrorExtWrapFrom<EI>,

Source§

fn wrap(self, _code: u32) -> EO

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more