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>
Sourcepub fn new(stream: S) -> StreamBody<S>
pub fn new(stream: S) -> StreamBody<S>
Create a new streaming body from a stream
Sourcepub fn content_type(self, content_type: impl Into<String>) -> StreamBody<S>
pub fn content_type(self, content_type: impl Into<String>) -> StreamBody<S>
Set the content type for the response
Trait Implementations§
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more