Skip to main content

Crate ferro_events

Crate ferro_events 

Source
Expand description

§Ferro Events

Event dispatcher and listener system for the Ferro framework.

Provides a Laravel-inspired event system with support for:

  • Synchronous listeners
  • Asynchronous listeners
  • Queued listeners (via ShouldQueue marker)
  • Ergonomic dispatch API (.dispatch() on events)

§Example

use ferro_events::{Event, Listener, Error};

#[derive(Clone)]
struct UserRegistered {
    user_id: i64,
    email: String,
}

impl Event for UserRegistered {
    fn name(&self) -> &'static str {
        "UserRegistered"
    }
}

struct SendWelcomeEmail;

#[async_trait::async_trait]
impl Listener<UserRegistered> for SendWelcomeEmail {
    async fn handle(&self, event: &UserRegistered) -> Result<(), Error> {
        println!("Sending welcome email to {}", event.email);
        Ok(())
    }
}

// Dispatch an event (ergonomic Laravel-style API)
UserRegistered { user_id: 1, email: "test@example.com".into() }.dispatch().await?;

// Or fire and forget (spawns background task)
UserRegistered { user_id: 1, email: "test@example.com".into() }.dispatch_sync();

Structs§

EventDispatcher
Global event dispatcher.

Enums§

Error
Errors that can occur in the event system.

Traits§

Event
Marker trait for events that can be dispatched.
Listener
A listener that handles events of type E.
ShouldQueue
Marker trait for listeners that should be queued for background processing.

Functions§

dispatch
Dispatch an event using the global dispatcher.
dispatch_sync
Dispatch an event synchronously (fire and forget).
global_dispatcher
Get the global event dispatcher.

Attribute Macros§

async_trait
Re-export async_trait for convenience