pub struct Event<P> {
pub header: EventHeader,
pub payload: P,
pub hash_chain: Option<HashChain>,
}Expand description
A complete event with header and payload.
The payload is generic to allow different event types to have different payload structures while sharing the same header format.
Fields§
§header: EventHeader§payload: P§hash_chain: Option<HashChain>Hash chain for tamper-evident audit trail (Blake3 hash of parent + self). None for genesis events.
Implementations§
Source§impl<P> Event<P>
impl<P> Event<P>
Sourcepub fn new(header: EventHeader, payload: P) -> Self
pub fn new(header: EventHeader, payload: P) -> Self
Create a new event with the given header and payload (genesis event, no hash chain).
Sourcepub fn with_hash_chain(
header: EventHeader,
payload: P,
hash_chain: HashChain,
) -> Self
pub fn with_hash_chain( header: EventHeader, payload: P, hash_chain: HashChain, ) -> Self
Create a new event with the given header, payload, and hash chain.
Sourcepub fn event_kind(&self) -> EventKind
pub fn event_kind(&self) -> EventKind
Get the event kind.
Sourcepub fn correlation_id(&self) -> EventId
pub fn correlation_id(&self) -> EventId
Get the correlation ID.
Sourcepub fn position(&self) -> DagPosition
pub fn position(&self) -> DagPosition
Get the DAG position.
Sourcepub fn map_payload<Q, F: FnOnce(P) -> Q>(self, f: F) -> Event<Q>
pub fn map_payload<Q, F: FnOnce(P) -> Q>(self, f: F) -> Event<Q>
Map the payload to a different type.
Source§impl<P: Serialize> Event<P>
impl<P: Serialize> Event<P>
Sourcepub fn compute_hash(&self) -> [u8; 32]
pub fn compute_hash(&self) -> [u8; 32]
Compute Blake3 hash of this event’s content (header + payload).
Hashes only header and payload — the hash_chain field is excluded to avoid a circular dependency (event_hash cannot include itself).
Sourcepub fn verify(&self, parent_hash: &[u8; 32]) -> bool
pub fn verify(&self, parent_hash: &[u8; 32]) -> bool
Verify this event against a parent hash using Blake3. Returns true for genesis events (no hash chain).
Sourcepub fn is_genesis(&self) -> bool
pub fn is_genesis(&self) -> bool
Check if this is a genesis event (no parent).
Trait Implementations§
Source§impl<'de, P> Deserialize<'de> for Event<P>where
P: Deserialize<'de>,
impl<'de, P> Deserialize<'de> for Event<P>where
P: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl<P: Eq> Eq for Event<P>
impl<P> StructuralPartialEq for Event<P>
Auto Trait Implementations§
impl<P> Freeze for Event<P>where
P: Freeze,
impl<P> RefUnwindSafe for Event<P>where
P: RefUnwindSafe,
impl<P> Send for Event<P>where
P: Send,
impl<P> Sync for Event<P>where
P: Sync,
impl<P> Unpin for Event<P>where
P: Unpin,
impl<P> UnwindSafe for Event<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.