pub struct Envelope {
pub pattern: PatternId,
pub correlation: CorrelationId,
pub kind: MessageKind,
pub payload: Value,
}Expand description
One decoded, validated conversation envelope.
Fields§
§pattern: PatternIdNominal pattern contract, matched exactly.
correlation: CorrelationIdTyped correlation identity, caller-unique per exchange.
kind: MessageKindMessage kind within the pattern’s closed set.
payload: ValueThe pattern’s typed message, as its JSON value.
Implementations§
Source§impl Envelope
impl Envelope
Sourcepub fn from_typed<T: Serialize>(
pattern: PatternId,
correlation: CorrelationId,
kind: MessageKind,
body: &T,
) -> Result<Self, EnvelopeError>
pub fn from_typed<T: Serialize>( pattern: PatternId, correlation: CorrelationId, kind: MessageKind, body: &T, ) -> Result<Self, EnvelopeError>
Builds an envelope from a typed message, refusing schema-invalid values BEFORE the wire (F-3a R1).
§Errors
Returns slug::CONV_SCHEMA_INVALID when the typed value does not
serialize, and slug::CONV_KIND_INVALID when kind is outside the
pattern’s closed kind set.
Sourcepub fn decode_payload<T: DeserializeOwned>(&self) -> Result<T, EnvelopeError>
pub fn decode_payload<T: DeserializeOwned>(&self) -> Result<T, EnvelopeError>
Decodes this envelope’s payload into the pattern’s typed message.
§Errors
Returns slug::CONV_SCHEMA_INVALID when the payload is not a valid
value of the typed message — surfaced typed, never dropped (F-3a R1).
Sourcepub fn encode(&self) -> Result<Vec<u8>, EnvelopeError>
pub fn encode(&self) -> Result<Vec<u8>, EnvelopeError>
Encodes the envelope to its deterministic wire bytes.
§Errors
Returns slug::CONV_ENVELOPE_MALFORMED if JSON encoding fails —
unreachable for the envelope grammar, surfaced typed rather than
swallowed if the impossible happens.
Sourcepub fn decode(bytes: &[u8]) -> Result<Self, EnvelopeError>
pub fn decode(bytes: &[u8]) -> Result<Self, EnvelopeError>
Decodes and validates wire bytes into a typed envelope.
§Errors
Returns the closed refusal set: slug::CONV_ENVELOPE_MALFORMED for
bytes that are not the wire shape (unknown fields refused — the
refuse-non-canonical-receiver discipline),
slug::CONV_PATTERN_UNKNOWN for a pattern outside the contract
set, slug::CONV_CORRELATION_INVALID for a correlation that is not
a typed correlation identity, and slug::CONV_KIND_INVALID for a
kind outside the named pattern’s closed set.
Trait Implementations§
impl Eq for Envelope
impl StructuralPartialEq for Envelope
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request