Struct axum::body::StreamBody
source · 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::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>where
S: TryStream,
S::Ok: Into<Bytes>,
S::Error: Into<BoxError>,
impl<S> Body for StreamBody<S>where
S: TryStream,
S::Ok: Into<Bytes>,
S::Error: Into<BoxError>,
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§impl<S> Debug for StreamBody<S>
impl<S> Debug for StreamBody<S>
source§impl<S> From<S> for StreamBody<S>where
S: TryStream + Send + 'static,
S::Ok: Into<Bytes>,
S::Error: Into<BoxError>,
impl<S> From<S> for StreamBody<S>where
S: TryStream + Send + 'static,
S::Ok: Into<Bytes>,
S::Error: Into<BoxError>,
source§impl<S> IntoResponse for StreamBody<S>where
S: TryStream + Send + 'static,
S::Ok: Into<Bytes>,
S::Error: Into<BoxError>,
impl<S> IntoResponse for StreamBody<S>where
S: TryStream + Send + 'static,
S::Ok: Into<Bytes>,
S::Error: Into<BoxError>,
source§fn into_response(self) -> Response
fn into_response(self) -> Response
Create a response.