#[macro_use] extern crate eventbus; use std::fmt::Debug; use eventbus::{Event, EventBus, Cancellable}; trait MyEvent : Event + Debug { } trait MyExtraEvent : MyEvent + Cancellable { } #[derive(Debug)] struct MyEventImpl { i: i32 } #[derive(Debug)] struct MyExtraEventImpl { i: i32 } impl Event for MyEventImpl { } impl MyEvent for MyEventImpl { } impl Event for MyExtraEventImpl { } impl MyEvent for MyExtraEventImpl { } impl MyExtraEvent for MyExtraEventImpl { } impl Cancellable for MyExtraEventImpl { } fn on_myevent(evt: &mut dyn MyEvent) { println!("Got event for inspection and manipulation: {:?}", evt); } fn on_myextraevent(evt: &mut dyn MyExtraEvent) { println!("Got event for inspection, manipulation, and cancellation: {:?}", evt); } #[test] fn test_dyn_usage() { let event_bus = EventBus::new(); let mut event = MyEventImpl { i: 3 }; let mut extraEvent = MyExtraEventImpl { i: 4 }; //let handler_id = event_bus.register(add_handler, 0); register_hook!(&event_bus, 0, dyn MyEvent, on_myevent); register_hook!(&event_bus, 1, dyn MyExtraEvent, on_myextraevent); post_event!(&event_bus, dyn MyEvent, &mut event); post_event_cancellable!(&event_bus, dyn MyExtraEvent, &mut extraEvent); }