Struct actix_web_lab::respond::NdJson
source · pub struct NdJson<S> { /* private fields */ }
Expand description
A buffered NDJSON serializing body stream.
This has significant memory efficiency advantages over returning an array of JSON objects when the data set is very large because it avoids buffering the entire response.
§Examples
fn streaming_data_source() -> impl Stream<Item = serde_json::Value> {
// get item stream from source
}
async fn handler() -> impl Responder {
let data_stream = streaming_data_source();
NdJson::new_infallible(data_stream)
.into_responder()
}
Implementations§
source§impl<S> NdJson<S>
impl<S> NdJson<S>
sourcepub fn new_infallible(stream: S) -> NdJson<InfallibleStream<S>>
pub fn new_infallible(stream: S) -> NdJson<InfallibleStream<S>>
Constructs a new NdJson
from an infallible stream of items.
source§impl<S, T, E> NdJson<S>
impl<S, T, E> NdJson<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 NDJSON 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 serializing stream and correct 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§
Auto Trait Implementations§
impl<S> Freeze for NdJson<S>where
S: Freeze,
impl<S> RefUnwindSafe for NdJson<S>where
S: RefUnwindSafe,
impl<S> Send for NdJson<S>where
S: Send,
impl<S> Sync for NdJson<S>where
S: Sync,
impl<S> UnwindSafe for NdJson<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