// path_from_the_root: src/orchestrator/event_bus.rs extern crate alloc; use alloc::boxed::Box; use alloc::vec::Vec; pub trait EventHandler { fn handle(&mut self, event: E); } pub struct EventBus { handlers: Vec>>, } impl Default for EventBus { fn default() -> Self { Self::new() } } impl EventBus { pub fn new() -> Self { Self { handlers: Vec::new(), } } pub fn register(&mut self, handler: Box>) { self.handlers.push(handler); } pub fn emit(&mut self, event: E) { for handler in &mut self.handlers { handler.handle(event.clone()); } } pub fn handler_count(&self) -> usize { self.handlers.len() } pub fn is_empty(&self) -> bool { self.handlers.is_empty() } }