pub struct BodyBytes { /* private fields */ }Expand description
A concrete implementation of an HTTP body.
BodyBytes is an enum-backed type that can represent various kinds of HTTP bodies:
- Empty bodies
- Full bodies with all data available upfront
- Streaming bodies from various sources
- Collected bodies
- Boxed bodies for type erasure
§Examples
§Creating an empty body
use product_os_http_body::BodyBytes;
let body = BodyBytes::empty();§Creating a body from bytes
use product_os_http_body::{BodyBytes, Bytes};
let body = BodyBytes::new(Bytes::from("Hello, World!"));§Creating a body from a string
use product_os_http_body::BodyBytes;
let body = BodyBytes::from("string data");
let body2 = BodyBytes::from(String::from("owned string"));§Feature-gated functionality
Some constructors and conversions are only available with specific features:
stream: Enablesnew_stream()andfrom_stream()for streaming bodiesbox_body: Enables conversions fromBoxBodyincoming: Enables conversions fromhyper::body::Incoming
§Body trait implementation
BodyBytes implements the http_body::Body trait (when the std feature is enabled),
allowing it to be used anywhere an HTTP body is expected.
Implementations§
Trait Implementations§
Source§impl Body for BodyBytes
impl Body for BodyBytes
Source§fn poll_frame(
self: Pin<&mut BodyBytes>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Frame<<BodyBytes as Body>::Data>, <BodyBytes as Body>::Error>>>
fn poll_frame( self: Pin<&mut BodyBytes>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Frame<<BodyBytes as Body>::Data>, <BodyBytes as Body>::Error>>>
Attempt to pull out the next data buffer of this stream.
Source§fn is_end_stream(&self) -> bool
fn is_end_stream(&self) -> bool
Returns
true when the end of stream has been reached. Read moreSource§impl IntoResponse for BodyBytes
Available on crate feature axum only.
impl IntoResponse for BodyBytes
Available on crate feature
axum only.Source§fn into_response(self) -> Response<Body>
fn into_response(self) -> Response<Body>
Create a response.
Auto Trait Implementations§
impl !Freeze for BodyBytes
impl RefUnwindSafe for BodyBytes
impl Send for BodyBytes
impl Sync for BodyBytes
impl Unpin for BodyBytes
impl UnsafeUnpin for BodyBytes
impl UnwindSafe for BodyBytes
Blanket Implementations§
Source§impl<T> BodyExt for T
impl<T> BodyExt for T
Source§fn frame(&mut self) -> Frame<'_, Self>where
Self: Unpin,
fn frame(&mut self) -> Frame<'_, Self>where
Self: Unpin,
Returns a future that resolves to the next
Frame, if any.Source§fn map_frame<F, B>(self, f: F) -> MapFrame<Self, F>
fn map_frame<F, B>(self, f: F) -> MapFrame<Self, F>
Maps this body’s frame to a different kind.
Source§fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
Maps this body’s error value to a different value.
Source§fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
Turn this body into a boxed trait object that is !Sync.
Source§fn collect(self) -> Collect<Self>where
Self: Sized,
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 with_trailers<F>(self, trailers: F) -> WithTrailers<Self, F>
fn with_trailers<F>(self, trailers: F) -> WithTrailers<Self, F>
Add trailers to the body. Read more
Source§fn into_data_stream(self) -> BodyDataStream<Self>where
Self: Sized,
fn into_data_stream(self) -> BodyDataStream<Self>where
Self: Sized,
Turn this body into
BodyDataStream.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
Source§fn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
Call the handler with the given request.
Source§fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
Apply a
tower::Layer to the handler. Read moreSource§fn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Convert the handler into a
Service by providing the stateSource§impl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
Source§fn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Convert the handler into a
Service and no state.Source§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
Convert the handler into a
MakeService and no state. Read moreSource§fn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
Convert the handler into a
MakeService which stores information
about the incoming connection and has no state. Read more