event_sourcing/
event.rs

1use alloc::string::String;
2use core::fmt;
3
4use chrono::{DateTime, Utc};
5use uuid::Uuid;
6
7use super::EventListBuilder;
8
9/// Represents a single event
10///
11/// Besides from the payload, the event structure contains some additional helpful fields
12#[derive(Debug, Clone)]
13#[cfg_attr(
14    feature = "serde",
15    derive(serde::Serialize, serde::Deserialize)
16)]
17pub struct Event<T> {
18    /// The id of the aggregate this event belongs to
19    pub aggregate_id: Uuid,
20
21    /// The id of this particular event. Events always use a numbered sequence starting from 1
22    pub event_id: u64,
23
24    /// When this event did happen
25    pub created_at: DateTime<Utc>,
26
27    /// An optional reference to the user who caused this event
28    pub user_id: Option<String>,
29
30    /// The event payload
31    pub payload: T,
32}
33
34impl<T: fmt::Debug> Event<T> {
35    pub fn list_builder() -> EventListBuilder<T> {
36        EventListBuilder::new()
37    }
38}
39
40