pub enum StreamFrame {
Data(Value),
Error {
code: String,
payload: Value,
},
}Expand description
One frame yielded by a StreamHandler.
Mirrors the SPEC §4.2 SSE event shapes:
Self::Data→event: data\ndata: <json>\n\nSelf::Error→event: error\ndata: <{code,payload}>\n\n
The terminal event: end\ndata:\n\n frame is implicit — when the
underlying stream finishes, the router emits it. Stream handlers should
just stop yielding rather than try to encode the end frame themselves.
StreamFrame is intentionally runtime-only: it carries pre-serialized
serde_json::Values so the router can splat them into SSE bodies without
re-running user Serialize impls. It does not implement
serde::Serialize/Deserialize itself — there’s no wire shape to round
trip.
Variants§
Data(Value)
A successful payload frame. Becomes event: data\ndata: <json>\n\n
on the SSE wire.
Error
An error frame. Becomes event: error\ndata: {"code","payload"}\n\n
on the SSE wire. Streaming errors do not terminate the connection
at the SPEC level — the user’s stream chooses whether to keep yielding
after an Error frame or stop. (The HTTP response is already
committed by the time SSE frames flow, so there’s no status code to
flip.)
Implementations§
Source§impl StreamFrame
impl StreamFrame
Sourcepub fn data(value: impl Serialize) -> Self
pub fn data(value: impl Serialize) -> Self
Serialize a value into StreamFrame::Data.
On serialization failure, falls back to a StreamFrame::Error with
code = "serialization_error" and a null payload — same fallback
shape as ProcedureResult::ok, for consistency between the unary
and streaming paths.
Sourcepub fn err(code: impl Into<String>, payload: impl Serialize) -> Self
pub fn err(code: impl Into<String>, payload: impl Serialize) -> Self
Build StreamFrame::Error from a stable code and serializable
payload. Same fallback semantics as Self::data when the payload
fails to serialize.
Sourcepub fn from_taut_error<E: TautError>(e: E) -> Self
pub fn from_taut_error<E: TautError>(e: E) -> Self
Build StreamFrame::Error from a crate::TautError. The payload
is serde_json::to_value(&e); if that fails the payload becomes
null but code is still taken from the error.
Note that, unlike the unary ProcedureResult::from_taut_error, the
http_status of the error is intentionally dropped: SSE frames flow
after the HTTP status line is already committed, so per-frame status
codes don’t fit. Callers wanting status-mapping semantics should use a
unary procedure instead.
Trait Implementations§
Source§impl Clone for StreamFrame
impl Clone for StreamFrame
Source§fn clone(&self) -> StreamFrame
fn clone(&self) -> StreamFrame
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more