jaeb 0.1.0

simple actor based event bus
Documentation
pub mod event_bus;

use core::future::Future;
use core::pin::Pin;

pub use event_bus::{Event, EventBus};

// Re-export macros for users: #[event_listener] and bootstrap_listeners!
pub use jaeb_macros::{bootstrap_listeners, event_listener};

// Internal plumbing used by macros
pub mod _private {
    pub use inventory;
    // re-export so proc-macro submissions can reference without direct dep
}

// Types used by the inventory to collect listener registrars generated by macros
pub type RegistrarFuture<'a> = Pin<Box<dyn Future<Output = ()> + Send + 'a>>;
pub type RegistrarFn = for<'a> fn(&'a EventBus) -> RegistrarFuture<'a>;

pub struct ListenerRegistrar {
    pub func: RegistrarFn,
}

inventory::collect!(ListenerRegistrar);

// Bootstrap all registered listeners into the provided EventBus
pub async fn bootstrap_listeners(bus: &EventBus) {
    for reg in inventory::iter::<ListenerRegistrar> {
        (reg.func)(bus).await;
    }
}