Skip to main content

Event

Struct Event 

Source
pub struct Event {
    pub event_id: Uuid,
    pub aggregate_type: String,
    pub aggregate_id: String,
    pub sequence: i64,
    pub event_type: String,
    pub payload: Value,
    pub audit: AuditMetadata,
    pub timestamp: u64,
}
Expand description

Core event type representing an immutable domain event.

§Fields

  • event_id: Unique identifier for this specific event occurrence
  • aggregate_type: Type of aggregate this event belongs to (e.g., “User”)
  • aggregate_id: ID of the specific aggregate instance
  • sequence: Sequential number within the aggregate stream (starts at 1)
  • event_type: Type of event (e.g., “UserRegistered”)
  • payload: Event data as JSON (flexible, evolvable schema)
  • audit: HIPAA audit metadata. pending() until the bus stamps it.
  • timestamp: When the event occurred (milliseconds since UNIX epoch)

Fields§

§event_id: Uuid

Unique identifier for this event

§aggregate_type: String

Aggregate type (e.g., “User”, “Order”)

§aggregate_id: String

Aggregate instance identifier

§sequence: i64

Sequence number within the aggregate (starts at 1)

§event_type: String

Event type (e.g., “UserCreated”, “ProfileUpdated”) Convention: Past tense, PascalCase

§payload: Value

Event payload as JSON

§audit: AuditMetadata

HIPAA audit metadata. AuditMetadata::pending() until the CommandBus overwrites it before append. EventStore::append implementations call audit.validate() and reject pending values.

§timestamp: u64

Wall-clock timestamp (milliseconds since UNIX epoch). For HIPAA audit-quality time, use audit.timestamp_utc_us (microsecond precision).

Implementations§

Source§

impl Event

Source

pub fn new( aggregate_type: impl Into<String>, aggregate_id: impl Into<String>, sequence: i64, event_type: impl Into<String>, payload: Value, ) -> Self

Create a new event with audit = AuditMetadata::pending().

Aggregates call this from handle() and the CommandBus overwrites the audit field with a request-scoped value before persisting. The pending placeholder fails store-side validation, so a forgotten stamp is impossible to commit.

§Example
use arc_core::event::Event;
use serde_json::json;

let event = Event::new(
    "User",
    "user-456",
    1,
    "UserCreated",
    json!({ "name": "Bob", "email": "bob@example.com" }),
);
assert!(event.audit.is_pending());
Source

pub fn with_audit(self, audit: AuditMetadata) -> Self

Replace audit with a fully-stamped value. Used by CommandBus before calling EventStore::append.

Source

pub fn to_json(&self) -> Result<String, Error>

Serialize event to JSON string.

Source

pub fn from_json(json_str: &str) -> Result<Self, Error>

Deserialize event from JSON string.

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

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 Event

Source§

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

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

impl<'de> Deserialize<'de> for Event

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Event

Source§

fn eq(&self, other: &Event) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Event

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Event

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnsafeUnpin for Event

§

impl UnwindSafe for Event

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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

Source§

type Output = T

Should always be Self
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