pub struct StreamBody<S> { /* private fields */ }
Expand description
An http_body::Body
created from a Stream
.
The purpose of this type is to be used in responses. If you want to
extract the request body as a stream consider using
BodyStream
.
§Example
use axum::{
Router,
routing::get,
body::StreamBody,
response::IntoResponse,
};
use futures_util::stream::{self, Stream};
use std::io;
async fn handler() -> StreamBody<impl Stream<Item = io::Result<&'static str>>> {
let chunks: Vec<io::Result<_>> = vec![
Ok("Hello,"),
Ok(" "),
Ok("world!"),
];
let stream = stream::iter(chunks);
StreamBody::new(stream)
}
let app = Router::new().route("/", get(handler));
Implementations§
Trait Implementations§
Source§impl<S> Body for StreamBody<S>
impl<S> Body for StreamBody<S>
Source§fn poll_data(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Self::Data, Self::Error>>>
fn poll_data( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Self::Data, Self::Error>>>
Attempt to pull out the next data buffer of this stream.
Source§fn poll_trailers(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
) -> Poll<Result<Option<HeaderMap>, Self::Error>>
fn poll_trailers( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<Option<HeaderMap>, Self::Error>>
Poll for an optional single
HeaderMap
of trailers. Read moreSource§fn is_end_stream(&self) -> bool
fn is_end_stream(&self) -> bool
Returns
true
when the end of stream has been reached. Read moreSource§fn size_hint(&self) -> SizeHint
fn size_hint(&self) -> SizeHint
Returns the bounds on the remaining length of the stream. Read more
Source§fn trailers(&mut self) -> Trailers<'_, Self>
fn trailers(&mut self) -> Trailers<'_, Self>
Returns future that resolves to trailers, if any.
Source§fn map_data<F, B>(self, f: F) -> MapData<Self, F>
fn map_data<F, B>(self, f: F) -> MapData<Self, F>
Maps this body’s data value to a different value.
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 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 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§impl<S> Debug for StreamBody<S>
impl<S> Debug for StreamBody<S>
Source§impl<S> From<S> for StreamBody<S>
impl<S> From<S> for StreamBody<S>
Source§impl<S> IntoResponse for StreamBody<S>
impl<S> IntoResponse for StreamBody<S>
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Create a response.
impl<'__pin, S> Unpin for StreamBody<S>where
__Origin<'__pin, S>: Unpin,
Auto Trait Implementations§
impl<S> Freeze for StreamBody<S>where
S: Freeze,
impl<S> RefUnwindSafe for StreamBody<S>where
S: RefUnwindSafe,
impl<S> Send for StreamBody<S>where
S: Send,
impl<S> Sync for StreamBody<S>
impl<S> UnwindSafe for StreamBody<S>where
S: UnwindSafe,
Blanket Implementations§
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