Skip to main content

NewEvent

Struct NewEvent 

Source
#[non_exhaustive]
pub struct NewEvent { pub correlation_id: CorrelationId, pub causation_id: Option<CausationId>, pub conversation_id: ConversationId, pub process_id: ProcessId, pub tenant_id: TenantId, pub workflow_id: WorkflowId, pub event_type: Box<str>, pub schema_version: u32, pub payload: Value, }
Expand description

A pending event ready to be appended to a stream.

The caller constructs a NewEvent for each domain event produced by a workflow command. Fields that the store assigns (event_id, sequence_number, timestamp, stream_id) are absent.

§Idiomatic construction

Prefer CommandContext::new_event inside workflow handlers and transport adapters — it propagates all correlation IDs from the command context automatically:

// Inside a MessageAdapter or test:
let new_event = ctx.new_event(&SupplierChangeEvent::Initiated { .. })?;
store.append(&stream_id, ExpectedVersion::Any, &[new_event]).await?;

Use EventEnvelope::new_caused_event when building a follow-up event causally linked to a prior persisted event.

For test scaffolding that needs a NewEvent without a typed payload or context, use NewEvent::new. The #[non_exhaustive] attribute future-proofs callers against new optional fields being added without requiring a semver-breaking change.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§correlation_id: CorrelationId

Groups all events that originate from the same root command.

§causation_id: Option<CausationId>

The event or command that directly caused this event, if any.

§conversation_id: ConversationId

Links events belonging to the same business conversation.

§process_id: ProcessId

Stable identifier for the MaKo process instance.

§tenant_id: TenantId

Tenant that owns this event.

§workflow_id: WorkflowId

Workflow definition that produced this event.

§event_type: Box<str>

Stable, human-readable type discriminant (e.g. "SupplierChangeInitiated").

§schema_version: u32

Schema version of the serialized payload.

§payload: Value

The domain event payload, serialized as JSON.

Implementations§

Source§

impl NewEvent

Source

pub fn new( correlation_id: CorrelationId, causation_id: Option<CausationId>, conversation_id: ConversationId, process_id: ProcessId, tenant_id: TenantId, workflow_id: WorkflowId, event_type: impl Into<Box<str>>, schema_version: u32, payload: Value, ) -> Self

Construct a NewEvent from its constituent parts.

This is the escape hatch for callers that need full control over all fields (e.g. test scaffolding, migration tooling, storage-layer tests). In application code, prefer CommandContext::new_event which propagates correlation metadata automatically.

Trait Implementations§

Source§

impl Clone for NewEvent

Source§

fn clone(&self) -> NewEvent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for NewEvent

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more