Skip to main content

ferro_events/
lib.rs

1//! # Ferro Events
2//!
3//! Event dispatcher and listener system for the Ferro framework.
4//!
5//! Provides a Laravel-inspired event system with support for:
6//! - Synchronous listeners
7//! - Asynchronous listeners
8//! - Queued listeners (via `ShouldQueue` marker)
9//! - Ergonomic dispatch API (`.dispatch()` on events)
10//!
11//! ## Example
12//!
13//! ```rust,ignore
14//! use ferro_events::{Event, Listener, Error};
15//!
16//! #[derive(Clone)]
17//! struct UserRegistered {
18//!     user_id: i64,
19//!     email: String,
20//! }
21//!
22//! impl Event for UserRegistered {
23//!     fn name(&self) -> &'static str {
24//!         "UserRegistered"
25//!     }
26//! }
27//!
28//! struct SendWelcomeEmail;
29//!
30//! #[async_trait::async_trait]
31//! impl Listener<UserRegistered> for SendWelcomeEmail {
32//!     async fn handle(&self, event: &UserRegistered) -> Result<(), Error> {
33//!         println!("Sending welcome email to {}", event.email);
34//!         Ok(())
35//!     }
36//! }
37//!
38//! // Dispatch an event (ergonomic Laravel-style API)
39//! UserRegistered { user_id: 1, email: "test@example.com".into() }.dispatch().await?;
40//!
41//! // Or fire and forget (spawns background task)
42//! UserRegistered { user_id: 1, email: "test@example.com".into() }.dispatch_sync();
43//! ```
44
45mod dispatcher;
46mod error;
47mod traits;
48
49pub use dispatcher::{dispatch, dispatch_sync, global_dispatcher, EventDispatcher};
50pub use error::Error;
51pub use traits::{Event, Listener, ShouldQueue};
52
53/// Re-export async_trait for convenience
54pub use async_trait::async_trait;