pub trait EsEvent:
DeserializeOwned
+ Serialize
+ Send
+ Sync {
type EntityId: Clone + PartialEq + Type<Postgres> + Eq + Hash + Send + Sync;
// Required method
fn event_context() -> bool;
}Expand description
Required trait for all event enums to be compatible and recognised by es-entity.
All EntityEvent enums implement this trait to ensure it satisfies basic requirements for
es-entity compatibility. The trait ensures trait implementations and compile-time validation that required fields (like id) are present.
Implemented by the EsEvent derive macro with #[es_event] attribute.
§Example
ⓘ
use es_entity::*;
use serde::{Serialize, Deserialize};
entity_id!{ UserId }
// Compile-time error: missing `id` attribute in `es_event`
#[derive(EsEvent, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
// #[es_event(id = "UserId")] <- This line is required!
pub enum UserEvent {
Initialized { id: UserId, name: String },
NameUpdated { name: String },
Deactivated { reason: String }
}Correct usage:
use es_entity::*;
use serde::{Serialize, Deserialize};
entity_id!{ UserId }
#[derive(EsEvent, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
#[es_event(id = "UserId")]
pub enum UserEvent {
Initialized { id: UserId, name: String },
NameUpdated { name: String },
Deactivated { reason: String }
}Required Associated Types§
Required Methods§
fn event_context() -> bool
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.