pub struct DisplayStream<S> { /* private fields */ }Expand description
A buffered line formatting body stream.
Each item yielded by the stream will be written to the response body using its
Display implementation.
This has significant memory efficiency advantages over returning an array of lines when the data set is very large because it avoids buffering the entire response.
§Examples
fn streaming_data_source() -> impl Stream<Item = u32> {
// get item stream from source
}
async fn handler() -> impl Responder {
let data_stream = streaming_data_source();
DisplayStream::new_infallible(data_stream)
.into_responder()
}Implementations§
Source§impl<S> DisplayStream<S>
impl<S> DisplayStream<S>
Source§impl<S> DisplayStream<S>
impl<S> DisplayStream<S>
Sourcepub fn new_infallible(stream: S) -> DisplayStream<InfallibleStream<S>>
pub fn new_infallible(stream: S) -> DisplayStream<InfallibleStream<S>>
Constructs a new DisplayStream from an infallible stream of lines.
Source§impl<S, T, E> DisplayStream<S>
impl<S, T, E> DisplayStream<S>
Sourcepub fn into_body_stream(self) -> impl MessageBody
pub fn into_body_stream(self) -> impl MessageBody
Creates a chunked body stream that serializes as CSV on-the-fly.
Sourcepub fn into_responder(self) -> impl Responderwhere
S: 'static,
T: 'static,
E: 'static,
pub fn into_responder(self) -> impl Responderwhere
S: 'static,
T: 'static,
E: 'static,
Creates a Responder type with a line-by-line serializing stream and text/plain
content-type header.
Sourcepub fn into_chunk_stream(self) -> impl Stream<Item = Result<Bytes, E>>
pub fn into_chunk_stream(self) -> impl Stream<Item = Result<Bytes, E>>
Creates a stream of serialized chunks.
Trait Implementations§
impl<'__pin, S> Unpin for DisplayStream<S>where
PinnedFieldsOf<__Origin<'__pin, S>>: Unpin,
Auto Trait Implementations§
impl<S> Freeze for DisplayStream<S>where
S: Freeze,
impl<S> RefUnwindSafe for DisplayStream<S>where
S: RefUnwindSafe,
impl<S> Send for DisplayStream<S>where
S: Send,
impl<S> Sync for DisplayStream<S>where
S: Sync,
impl<S> UnwindSafe for DisplayStream<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