Skip to main content

Notifiable

Trait Notifiable 

Source
pub trait Notifiable: Send + Sync {
    // Required method
    fn route_notification_for(&self, channel: Channel) -> Option<String>;

    // Provided methods
    fn notifiable_id(&self) -> String { ... }
    fn notifiable_type(&self) -> &'static str { ... }
    fn notify<'life0, 'async_trait, N>(
        &'life0 self,
        notification: N,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             N: 'async_trait + Notification + 'static,
             Self: 'async_trait { ... }
}
Expand description

Trait for entities that can receive notifications.

Implement this trait on your User model or any other entity that should be able to receive notifications.

§Example

use ferro_notifications::{Notifiable, Channel};

struct User {
    id: i64,
    email: String,
    slack_webhook: Option<String>,
}

impl Notifiable for User {
    fn route_notification_for(&self, channel: Channel) -> Option<String> {
        match channel {
            Channel::Mail => Some(self.email.clone()),
            Channel::Slack => self.slack_webhook.clone(),
            Channel::Database => Some(self.id.to_string()),
            _ => None,
        }
    }
}

Required Methods§

Source

fn route_notification_for(&self, channel: Channel) -> Option<String>

Get the routing information for a specific channel.

Returns the destination for the notification (email address, webhook URL, user ID, etc.) or None if the channel is not available for this entity.

Provided Methods§

Source

fn notifiable_id(&self) -> String

Get the unique identifier for this notifiable entity. Used for database notifications.

Source

fn notifiable_type(&self) -> &'static str

Get the type name of this notifiable entity.

Source

fn notify<'life0, 'async_trait, N>( &'life0 self, notification: N, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, N: 'async_trait + Notification + 'static, Self: 'async_trait,

Send a notification to this entity.

This is the main entry point for sending notifications. It dispatches the notification through all configured channels.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§