pub struct Body(/* private fields */);Expand description
An request body.
Implementations§
Source§impl Body
impl Body
Sourcepub fn as_bytes(&self) -> Option<&[u8]>
pub fn as_bytes(&self) -> Option<&[u8]>
Returns a reference to the internal data of the Body.
None is returned, if the underlying data is a stream.
Sourcepub fn wrap_stream<S>(stream: S) -> Body
Available on crate feature stream only.
pub fn wrap_stream<S>(stream: S) -> Body
stream only.Sourcepub fn into_bytes_mut(self) -> Option<BytesMut>
pub fn into_bytes_mut(self) -> Option<BytesMut>
Convert the body into a mutable bytes::BytesMut if possible.
This is useful for zero-copy operations where you need a mutable buffer, such as with SIMD JSON parsing.
Returns Some(BytesMut) if the body is a reusable Bytes chunk,
None if the body is a streaming body.
§Example
use bytes::BytesMut;
use hpx::Body;
let body = Body::from("hello world");
if let Some(bytes_mut) = body.into_bytes_mut() {
// Use mutable bytes for zero-copy operations
println!("Got {} bytes", bytes_mut.len());
}Sourcepub fn reader(self) -> impl AsyncRead
Available on crate feature stream only.
pub fn reader(self) -> impl AsyncRead
stream only.Get an tokio::io::AsyncRead adapter for the body.
This enables efficient streaming of the body using standard async I/O traits.
§Example
use hpx::Body;
use tokio::io::AsyncReadExt;
let body = Body::from("hello world");
let mut reader = body.reader();
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).await?;§Optional
This requires the optional stream feature to be enabled.
Trait Implementations§
Source§impl Body for Body
impl Body for Body
Source§fn poll_frame(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>>
fn poll_frame( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>>
Attempt to pull out the next data buffer of this stream.
Source§fn size_hint(&self) -> SizeHint
fn size_hint(&self) -> SizeHint
Returns the bounds on the remaining length of the stream. Read more
Source§fn is_end_stream(&self) -> bool
fn is_end_stream(&self) -> bool
Returns
true when the end of stream has been reached. Read moreAuto Trait Implementations§
impl !Freeze for Body
impl !RefUnwindSafe for Body
impl Send for Body
impl Sync for Body
impl Unpin for Body
impl UnsafeUnpin for Body
impl !UnwindSafe for Body
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more