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;
async fn handler() -> impl IntoResponse {
let chunks: Vec<Result<_, std::io::Error>> = vec![
Ok("Hello,"),
Ok(" "),
Ok("world!"),
];
let stream = stream::iter(chunks);
StreamBody::new(stream)
}
let app = Router::new().route("/", get(handler));
Implementations
Trait Implementations
Attempt to pull out the next data buffer of this stream.
Poll for an optional single HeaderMap
of trailers. Read more
Returns true
when the end of stream has been reached. Read more
Returns the bounds on the remaining length of the stream. Read more
Returns future that resolves to next data chunk, if any.
Returns future that resolves to trailers, if any.
Maps this body’s data value to a different value.
Maps this body’s error value to a different value.
Turn this body into a boxed trait object.
Turn this body into a boxed trait object that is !Sync.
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>,
Create a response.
Auto Trait Implementations
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
Mutably borrows from an owned value. Read more
Create a new Policy
that returns Action::Follow
only if self
and other
return
Action::Follow
. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more