pub struct Envelope {
pub v: u32,
pub id: RequestId,
pub op: String,
pub ok: Option<bool>,
pub payload: Option<Value>,
pub error: Option<ProtocolError>,
}Expand description
Envelope wrapping every worker message.
Fields§
§v: u32Protocol version.
id: RequestIdCorrelation id.
op: StringOperation name.
ok: Option<bool>Success flag (responses only; omitted on requests).
payload: Option<Value>Payload.
error: Option<ProtocolError>Structured error (responses only).
Implementations§
Source§impl Envelope
impl Envelope
Sourcepub fn ok_response(id: RequestId, op: impl Into<String>, payload: Value) -> Self
pub fn ok_response(id: RequestId, op: impl Into<String>, payload: Value) -> Self
Build a successful response.
Sourcepub fn err_response(
id: RequestId,
op: impl Into<String>,
error: ProtocolError,
) -> Self
pub fn err_response( id: RequestId, op: impl Into<String>, error: ProtocolError, ) -> Self
Build an error response.
Sourcepub fn to_ndjson_line(&self) -> Result<String>
pub fn to_ndjson_line(&self) -> Result<String>
Encode as a single NDJSON line (with trailing newline).
Sourcepub fn from_ndjson_line(line: &str) -> Result<Self>
pub fn from_ndjson_line(line: &str) -> Result<Self>
Parse a single NDJSON line.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Envelope
impl<'de> Deserialize<'de> for Envelope
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Envelope
impl RefUnwindSafe for Envelope
impl Send for Envelope
impl Sync for Envelope
impl Unpin for Envelope
impl UnsafeUnpin for Envelope
impl UnwindSafe for Envelope
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