Skip to main content

Streamed

Struct Streamed 

Source
pub struct Streamed(/* private fields */);
Available on crate features http and streaming only.
Expand description

A JSONL body, written one line at a time.

Built by the generated LIST handler when the client sends Accept: application/jsonl and the resource routes STREAM. Each row is serialized, written, and dropped, so the response holds one row rather than the collection — see jsonl for the trade this makes against a document.

Implementations§

Source§

impl Streamed

Source

pub fn new( lines: impl Stream<Item = Result<Vec<u8>, Infallible>> + Send + Unpin + 'static, ) -> Self

Build a JSONL body from a stream of already-rendered lines.

Each item is one complete line, newline included. The error type is Infallible deliberately: a failure has to become a line rather than a transport error, because the status was already sent — see ERROR_LINE.

Source

pub fn line(resource: &ResourceObject) -> Vec<u8> ⓘ

Render one resource object as a JSONL line.

Serialization cannot fail for a ResourceObject, but if it somehow did, an error line is emitted rather than a truncated stream — a client must never mistake a partial export for a whole one.

Source

pub fn result_line(resource: &ResourceObject) -> Vec<u8> ⓘ

Render one created resource as an ingest result line.

A document per line — {"data":{…}} — where line writes a bare resource object. The difference is deliberate: an export is a row stream, but an ingest result line sits next to error lines that are themselves documents, so a client parses every line the same way and looks for data or errors.

Source

pub fn error_line_at(error: &JsonApiError, line: usize) -> Vec<u8> ⓘ

Render an error as one line’s result, stamped with its line number.

The line number is what makes a per-line failure actionable: a client that sent a hundred thousand rows needs to know which ones did not land, so it can retry exactly those. See LINE_MEMBER.

Source

pub fn error_line(error: &JsonApiError) -> Vec<u8> ⓘ

Render an error as the stream’s final line.

Shaped like a JSON:API error document so a client parsing lines as JSON finds the same errors member it would in a normal response.

Trait Implementations§

Source§

impl IntoResponse for Streamed

Source§

fn into_response(self) -> Response

Create a response.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more