pub struct Message<T> { /* private fields */ }Expand description
A message envelope that wraps a payload with an ID and metadata.
This is the primary type for exactly-once processing. It provides:
- A unique identifier for deduplication
- Metadata for tracking and routing
- The actual payload
§Type Parameters
T: The payload type
§Example
use streamweave::message::{Message, MessageId, MessageMetadata};
// Create a simple message
let msg = Message::new(42, MessageId::new_uuid());
// Create a message with metadata
let msg = Message::with_metadata(
"hello",
MessageId::new_sequence(1),
MessageMetadata::with_timestamp_now().source("my-source")
);Implementations§
Source§impl<T> Message<T>
impl<T> Message<T>
Sourcepub fn new(payload: T, id: MessageId) -> Self
pub fn new(payload: T, id: MessageId) -> Self
Create a new message with the given payload and ID.
Sourcepub fn with_metadata(
payload: T,
id: MessageId,
metadata: MessageMetadata,
) -> Self
pub fn with_metadata( payload: T, id: MessageId, metadata: MessageMetadata, ) -> Self
Create a new message with payload, ID, and metadata.
Sourcepub fn payload_mut(&mut self) -> &mut T
pub fn payload_mut(&mut self) -> &mut T
Get a mutable reference to the payload.
Sourcepub fn metadata(&self) -> &MessageMetadata
pub fn metadata(&self) -> &MessageMetadata
Get the metadata.
Sourcepub fn metadata_mut(&mut self) -> &mut MessageMetadata
pub fn metadata_mut(&mut self) -> &mut MessageMetadata
Get a mutable reference to the metadata.
Sourcepub fn into_parts(self) -> (MessageId, T, MessageMetadata)
pub fn into_parts(self) -> (MessageId, T, MessageMetadata)
Consume the message and return its components.
Sourcepub fn into_payload(self) -> T
pub fn into_payload(self) -> T
Consume the message and return just the payload.
Sourcepub fn map<U, F>(self, f: F) -> Message<U>where
F: FnOnce(T) -> U,
pub fn map<U, F>(self, f: F) -> Message<U>where
F: FnOnce(T) -> U,
Map the payload to a new type.
Sourcepub fn map_with_id<U, F>(self, f: F) -> Message<U>
pub fn map_with_id<U, F>(self, f: F) -> Message<U>
Map the payload to a new type, with access to the message ID.
Sourcepub fn with_payload<U>(self, payload: U) -> Message<U>
pub fn with_payload<U>(self, payload: U) -> Message<U>
Replace the payload with a new value.
Trait Implementations§
impl<T: Eq> Eq for Message<T>
Auto Trait Implementations§
impl<T> Freeze for Message<T>where
T: Freeze,
impl<T> RefUnwindSafe for Message<T>where
T: RefUnwindSafe,
impl<T> Send for Message<T>where
T: Send,
impl<T> Sync for Message<T>where
T: Sync,
impl<T> Unpin for Message<T>where
T: Unpin,
impl<T> UnwindSafe for Message<T>where
T: UnwindSafe,
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