pub struct StreamBody<S> { /* private fields */ }Expand description
A streaming body wrapper for HTTP responses
StreamBody wraps a stream of bytes and converts it to an HTTP response.
This is useful for streaming large amounts of data without buffering
the entire response in memory.
§Example
ⓘ
use rustapi_core::stream::StreamBody;
use futures_util::stream;
use bytes::Bytes;
async fn stream_data() -> StreamBody<impl Stream<Item = Result<Bytes, std::convert::Infallible>>> {
let stream = stream::iter(vec![
Ok(Bytes::from("chunk 1")),
Ok(Bytes::from("chunk 2")),
]);
StreamBody::new(stream)
}Implementations§
Source§impl<S> StreamBody<S>
impl<S> StreamBody<S>
Trait Implementations§
Source§impl<S, E> IntoResponse for StreamBody<S>
impl<S, E> IntoResponse for StreamBody<S>
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Convert self into a Response
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>where
S: Sync,
impl<S> Unpin for StreamBody<S>where
S: Unpin,
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