pub struct EventKind { /* private fields */ }Expand description
Domain-neutral event identity and structured fields.
The type tag and flattened field layout deliberately preserve the wire
shape used by earlier concrete event variants. Domain crates and runtime
compatibility modules own typed payloads and encode them through
Self::from_payload; this crate does not own their vocabulary.
Implementations§
Source§impl EventKind
impl EventKind
Sourcepub fn from_fields(
event_type: impl Into<String>,
fields: BTreeMap<String, Value>,
) -> Result<EventKind, EventKindError>
pub fn from_fields( event_type: impl Into<String>, fields: BTreeMap<String, Value>, ) -> Result<EventKind, EventKindError>
Builds an event record from an explicit type and flattened fields.
§Errors
Returns an error when the type is empty or the fields contain the
reserved type key.
Sourcepub fn from_payload<T>(
event_type: impl Into<String>,
payload: &T,
) -> Result<EventKind, EventKindError>where
T: Serialize,
pub fn from_payload<T>(
event_type: impl Into<String>,
payload: &T,
) -> Result<EventKind, EventKindError>where
T: Serialize,
Serializes a typed domain payload into an event record.
§Errors
Returns an error when serialization fails, the payload is not an
object, the type is empty, or the payload contains the reserved type
key.
Sourcepub fn plugin(
plugin: impl Into<String>,
event_type: impl Into<String>,
) -> EventKind
pub fn plugin( plugin: impl Into<String>, event_type: impl Into<String>, ) -> EventKind
Constructs the compatibility wire identity for a plugin event.
pub fn event_type(&self) -> &str
pub fn is_type(&self, event_type: &str) -> bool
pub fn fields(&self) -> BTreeMap<String, Value>
pub fn field(&self, name: &str) -> Option<Value>
Sourcepub fn set_field<T>(
&mut self,
name: &str,
value: &T,
) -> Result<(), EventKindError>where
T: Serialize,
pub fn set_field<T>(
&mut self,
name: &str,
value: &T,
) -> Result<(), EventKindError>where
T: Serialize,
Replaces one existing field with a serializable value.
§Errors
Returns an error when the field is absent or the value cannot be represented as structured JSON data.
Sourcepub fn decode_payload<T>(&self) -> Result<T, EventKindError>where
T: DeserializeOwned,
pub fn decode_payload<T>(&self) -> Result<T, EventKindError>where
T: DeserializeOwned,
Decodes all flattened fields into a domain-owned payload type.
§Errors
Returns an error when the fields do not deserialize as T.
Sourcepub fn decode_field<T>(&self, name: &str) -> Result<T, EventKindError>where
T: DeserializeOwned,
pub fn decode_field<T>(&self, name: &str) -> Result<T, EventKindError>where
T: DeserializeOwned,
Decodes one named field.
§Errors
Returns an error when the field is absent or does not deserialize as
T.
pub fn plugin_identity(&self) -> Option<(&str, &str)>
Sourcepub fn qualified_event_type(&self) -> String
pub fn qualified_event_type(&self) -> String
Returns the stable, display-oriented type identity for this event.
Built-in event kinds retain the same snake-case labels returned by
Self::event_type. Plugin events are qualified with their registered
plugin name and event type, separated by a dot. The two plugin-provided
components are preserved as registered; no case folding or additional
normalization is applied.