keri_core/event/event_data/
mod.rs

1pub mod delegated;
2pub mod inception;
3pub mod interaction;
4pub mod rotation;
5
6use crate::{
7    error::Error,
8    event_message::{EventTypeTag, Typeable},
9    state::{EventSemantics, IdentifierState},
10};
11use serde::{Deserialize, Serialize};
12
13pub use self::{
14    delegated::DelegatedInceptionEvent, inception::InceptionEvent, interaction::InteractionEvent,
15    rotation::RotationEvent,
16};
17
18/// Event Data
19///
20/// Event Data conveys the semantic content of a KERI event.
21#[derive(
22    Serialize,
23    Deserialize,
24    Debug,
25    Clone,
26    PartialEq,
27    rkyv::Archive,
28    rkyv::Serialize,
29    rkyv::Deserialize,
30)]
31#[serde(untagged, rename_all = "lowercase")]
32#[rkyv(derive(Debug))]
33pub enum EventData {
34    Dip(DelegatedInceptionEvent),
35    Icp(InceptionEvent),
36    Rot(RotationEvent),
37    Ixn(InteractionEvent),
38    Drt(RotationEvent),
39}
40
41impl EventSemantics for EventData {
42    fn apply_to(&self, state: IdentifierState) -> Result<IdentifierState, Error> {
43        match self {
44            Self::Icp(e) => e.apply_to(state),
45            Self::Rot(e) => e.apply_to(state),
46            Self::Ixn(e) => e.apply_to(state),
47            Self::Dip(e) => e.apply_to(state),
48            Self::Drt(e) => e.apply_to(state),
49        }
50    }
51}
52
53impl From<EventData> for EventTypeTag {
54    fn from(ed: EventData) -> Self {
55        match ed {
56            EventData::Icp(_) => EventTypeTag::Icp,
57            EventData::Rot(_) => EventTypeTag::Rot,
58            EventData::Ixn(_) => EventTypeTag::Ixn,
59            EventData::Dip(_) => EventTypeTag::Dip,
60            EventData::Drt(_) => EventTypeTag::Drt,
61        }
62    }
63}
64
65impl Typeable for EventData {
66    type TypeTag = EventTypeTag;
67    fn get_type(&self) -> EventTypeTag {
68        self.into()
69    }
70}