Skip to main content

Envelope

Struct Envelope 

Source
pub struct Envelope<E: Event> { /* private fields */ }
Expand description

Event plus metadata used by the broker for routing and observability.

  • event: the user-defined payload implementing Event.
  • meta: Meta describing who emitted the event and when. Includes actor_name and optional correlation_id for linking related events.

Implementations§

Source§

impl<E: Event> Envelope<E>

Source

pub fn new(event: E, actor_id: ActorId) -> Self

Create a new envelope tagging the event with the given actor name.

Source

pub fn with_correlation( event: E, actor_id: ActorId, correlation_id: EventId, ) -> Self

Create a new envelope with an explicit correlation id.

Use this to link child events to a parent or to group related flows.

Source

pub fn event(&self) -> &E

Returns a reference to the event payload.

This is a convenience method for pattern matching. For method calls, you can also use Deref (e.g., envelope.some_event_method()).

§Example
match envelope.event() {
    MyEvent::Foo(x) => handle_foo(x),
    MyEvent::Bar => handle_bar(),
}
Source

pub fn meta(&self) -> &Meta

Source

pub fn id(&self) -> EventId

Trait Implementations§

Source§

impl<E: Clone + Event> Clone for Envelope<E>

Source§

fn clone(&self) -> Envelope<E>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E: Event + Debug> Debug for Envelope<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E: Event> Deref for Envelope<E>

Source§

type Target = E

The resulting type after dereferencing.
Source§

fn deref(&self) -> &E

Dereferences the value.
Source§

impl<E: Event> From<(&E, &Meta)> for Envelope<E>

Source§

fn from((event, meta): (&E, &Meta)) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<E> Freeze for Envelope<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for Envelope<E>
where E: RefUnwindSafe,

§

impl<E> Send for Envelope<E>

§

impl<E> Sync for Envelope<E>

§

impl<E> Unpin for Envelope<E>
where E: Unpin,

§

impl<E> UnwindSafe for Envelope<E>
where E: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.