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_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 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§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