#[non_exhaustive]pub struct Envelope<T> {
pub id: MessageId,
pub message_type: MessageType,
pub body: T,
pub metadata: Metadata,
/* private fields */
}Expand description
An envelope: a typed or serialized body plus the metadata Reliar understands and the custom
headers it does not (§9). Envelope != OutboxRecord != InboxRecord (§17) — nothing here
carries delivery state (attempts, leases, dead-letter bookkeeping).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: MessageIdThe envelope’s own identity.
message_type: MessageTypeThe message’s stable contract identity — T::TYPE/T::VERSION, never chosen ad hoc.
body: TThe message body: typed on the application side, bytes::Bytes once serialized.
metadata: MetadataCanonical, typed framework metadata — the single source of truth (ADR 0004).
Implementations§
Source§impl<T> Envelope<T>
impl<T> Envelope<T>
Sourcepub fn headers_mut(&mut self) -> &mut Headers
pub fn headers_mut(&mut self) -> &mut Headers
Mutably accesses the envelope’s custom headers, lazily allocating an empty Headers
the first time this is called.
Sourcepub fn set_headers(&mut self, headers: Option<Headers>)
pub fn set_headers(&mut self, headers: Option<Headers>)
Replaces the whole header map. The rehydration path for providers and transport mappers, which read back an already-validated map rather than inserting key by key.
Sourcepub fn map_body<U>(self, f: impl FnOnce(T) -> U) -> Envelope<U>
pub fn map_body<U>(self, f: impl FnOnce(T) -> U) -> Envelope<U>
Converts the body, keeping every other field. The only conversion between typed and serialized envelopes — no field is ever re-declared, so none can be dropped in the process (ADR 0003).
use bytes::Bytes;
use reliar_core::Envelope;
let envelope = Envelope::builder(Ping).build();
let serialized: Envelope<Bytes> = envelope.map_body(|_| Bytes::from_static(b"{}"));
assert_eq!(serialized.body.as_ref(), b"{}");Sourcepub fn try_map_body<U, E>(
self,
f: impl FnOnce(T) -> Result<U, E>,
) -> Result<Envelope<U>, E>
pub fn try_map_body<U, E>( self, f: impl FnOnce(T) -> Result<U, E>, ) -> Result<Envelope<U>, E>
Fallible variant of Self::map_body, for SerializedEnvelope -> Envelope<T> via a
Serializer.
§Errors
Returns whatever error f returns, unchanged.
Source§impl<T: Message> Envelope<T>
impl<T: Message> Envelope<T>
Sourcepub fn builder(body: T) -> EnvelopeBuilder<T>
pub fn builder(body: T) -> EnvelopeBuilder<T>
Starts building an envelope for body. message_type is derived from T::TYPE/
T::VERSION and cannot be passed in (ADR 0010).
use reliar_core::Envelope;
#[derive(serde::Serialize, serde::Deserialize)]
struct OrderCreated { order_id: u64 }
impl reliar_core::Message for OrderCreated {
const TYPE: &'static str = "orders.created";
const VERSION: u16 = 1;
}
let envelope = Envelope::builder(OrderCreated { order_id: 42 })
.tenant("acme")
.header("x-import-batch", "2026-09-04")?
.build();
assert_eq!(envelope.message_type.to_string(), "orders.created.v1");
assert_eq!(envelope.metadata.tenant_id.as_deref(), Some("acme"));Source§impl Envelope<Bytes>
impl Envelope<Bytes>
Sourcepub fn from_parts(
id: MessageId,
message_type: MessageType,
body: Bytes,
metadata: Metadata,
headers: Option<Headers>,
) -> Self
pub fn from_parts( id: MessageId, message_type: MessageType, body: Bytes, metadata: Metadata, headers: Option<Headers>, ) -> Self
Rehydration entry point for providers and transport mappers, which have a MessageType
read from storage or the wire rather than from a Rust type (ADR 0011).
Trait Implementations§
Source§impl<T: Clone> Clone for Envelope<T>
Clone only where T: Clone — nothing in Reliar requires it (the dispatcher moves owned
records into publish tasks, SRS §9.1); the impl exists for tests and host code.
impl<T: Clone> Clone for Envelope<T>
Clone only where T: Clone — nothing in Reliar requires it (the dispatcher moves owned
records into publish tasks, SRS §9.1); the impl exists for tests and host code.