Skip to main content

Event

Struct Event 

Source
pub struct Event {
    pub event_type: String,
    pub data: Value,
    pub ts: u64,
    pub id: Option<String>,
    pub actor: Option<String>,
    pub meta: Option<Value>,
}
Expand description

An immutable event record stored in the log.

Events are serialized as single JSON lines in app.jsonl. The data field is intentionally untyped (serde_json::Value) — the log has no opinion about event shapes. Reducers give events meaning.

Optional metadata fields (id, actor, meta) support multi-user applications, audit trails, and event correlation. When None, these fields are omitted from serialized output — existing logs without metadata deserialize without error.

§Examples

use eventfold::Event;
use serde_json::json;

// Simple event — no metadata
let event = Event::new("user_clicked", json!({"button": "submit"}));
assert_eq!(event.event_type, "user_clicked");
assert!(event.ts > 0);

// With metadata
let event = Event::new("order_placed", json!({"total": 99.99}))
    .with_id("ord-001")
    .with_actor("user_42");
assert_eq!(event.id, Some("ord-001".to_string()));
assert_eq!(event.actor, Some("user_42".to_string()));

Fields§

§event_type: String

The event type identifier (e.g. "todo_added", "user_clicked").

Serialized as "type" in JSON for brevity.

§data: Value

Arbitrary JSON payload. The log does not validate this — reducers interpret it however they need.

§ts: u64

Unix timestamp in seconds, auto-populated by Event::new.

§id: Option<String>

Unique event identifier.

Not auto-generated — callers provide their own (uuid, ulid, etc.) or leave as None for simple use cases.

§actor: Option<String>

Identity of the actor that caused this event (user ID, service name, API key, etc.). Interpretation is application-defined.

§meta: Option<Value>

Extensible metadata bag for cross-cutting concerns.

Typical keys: "session", "correlation_id", "source", "schema_version". Kept separate from data so domain payloads stay clean.

Implementations§

Source§

impl Event

Source

pub fn new(event_type: &str, data: Value) -> Self

Create a new event with the given type and data.

The timestamp is set to the current time (seconds since Unix epoch). Metadata fields (id, actor, meta) default to None — use the builder methods to set them.

§Panics

Panics if the system clock is set before the Unix epoch.

§Examples
use eventfold::Event;
use serde_json::json;

let event = Event::new("page_view", json!({"url": "/home"}));
assert_eq!(event.event_type, "page_view");
assert_eq!(event.data["url"], "/home");
assert_eq!(event.id, None);
assert_eq!(event.actor, None);
assert_eq!(event.meta, None);
Source

pub fn with_id(self, id: impl Into<String>) -> Self

Set the event’s unique identifier.

§Examples
use eventfold::Event;
use serde_json::json;

let event = Event::new("click", json!({})).with_id("evt-123");
assert_eq!(event.id, Some("evt-123".to_string()));
Source

pub fn with_actor(self, actor: impl Into<String>) -> Self

Set the actor that caused this event.

§Examples
use eventfold::Event;
use serde_json::json;

let event = Event::new("click", json!({})).with_actor("user_42");
assert_eq!(event.actor, Some("user_42".to_string()));
Source

pub fn with_meta(self, meta: Value) -> Self

Set extensible metadata.

§Examples
use eventfold::Event;
use serde_json::json;

let event = Event::new("click", json!({}))
    .with_meta(json!({"session": "sess_abc"}));
assert!(event.meta.is_some());

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

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