ricecoder_hooks/dispatcher/mod.rs
1//! Event dispatcher for triggering hooks
2
3pub mod event;
4
5pub use event::DefaultEventDispatcher;
6
7use crate::error::Result;
8use crate::types::Event;
9
10/// Trait for dispatching events to hooks
11///
12/// The EventDispatcher is responsible for:
13/// 1. Receiving events from the system
14/// 2. Querying the HookRegistry for hooks matching the event type
15/// 3. Routing events to matching hooks
16/// 4. Passing event context to hooks
17/// 5. Handling hook execution and error recovery
18///
19/// # Examples
20///
21/// ```ignore
22/// let dispatcher = DefaultEventDispatcher::new(registry, executor);
23/// let event = Event {
24/// event_type: "file_saved".to_string(),
25/// context: EventContext { ... },
26/// timestamp: "2024-01-01T12:00:00Z".to_string(),
27/// };
28/// dispatcher.dispatch_event(event)?;
29/// ```
30pub trait EventDispatcher: Send + Sync {
31 /// Dispatch an event to matching hooks
32 ///
33 /// This method:
34 /// 1. Queries the registry for hooks matching the event type
35 /// 2. Filters enabled hooks
36 /// 3. Executes each hook with the event context
37 /// 4. Logs errors but continues with other hooks
38 /// 5. Returns success if at least one hook executed
39 fn dispatch_event(&self, event: Event) -> Result<()>;
40}