pub trait EventSubscriber: Send + Sync {
// Required methods
fn subscribed_events(&self) -> Vec<Event>;
fn on_event(
&self,
event: Event,
ctx: &HookContext,
attrs: &HashMap<String, Value>,
) -> SubscriberResult<()>;
// Provided method
fn name(&self) -> &str { ... }
}Expand description
事件订阅者 trait
与 Observer 不同,EventSubscriber 只接收订阅的特定事件。
适合只关心特定事件的场景(如缓存失效仅关心 UPDATE/DELETE)。
Required Methods§
Sourcefn subscribed_events(&self) -> Vec<Event>
fn subscribed_events(&self) -> Vec<Event>
返回订阅的事件列表
仅当事件在此列表中时,on_event 才会被调用。
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".