pub trait Notification: Send + Sync {
// Required method
fn via(&self) -> Vec<Channel>;
// Provided methods
fn to_mail(&self) -> Option<MailMessage> { ... }
fn to_database(&self) -> Option<DatabaseMessage> { ... }
fn to_slack(&self) -> Option<SlackMessage> { ... }
fn notification_type(&self) -> &'static str { ... }
}Expand description
A notification that can be sent through multiple channels.
Notifications encapsulate a message that should be delivered to users through one or more channels (mail, database, slack, etc.).
§Example
use ferro_notifications::{Notification, Channel, MailMessage, DatabaseMessage};
struct OrderShipped {
order_id: i64,
tracking_number: String,
}
impl Notification for OrderShipped {
fn via(&self) -> Vec<Channel> {
vec![Channel::Mail, Channel::Database]
}
fn to_mail(&self) -> Option<MailMessage> {
Some(MailMessage::new()
.subject("Your order has shipped!")
.body(format!("Tracking: {}", self.tracking_number)))
}
fn to_database(&self) -> Option<DatabaseMessage> {
Some(DatabaseMessage::new("order_shipped")
.data("order_id", self.order_id)
.data("tracking", &self.tracking_number))
}
}Required Methods§
Provided Methods§
Sourcefn to_mail(&self) -> Option<MailMessage>
fn to_mail(&self) -> Option<MailMessage>
Convert the notification to a mail message.
Sourcefn to_database(&self) -> Option<DatabaseMessage>
fn to_database(&self) -> Option<DatabaseMessage>
Convert the notification to a database message.
Sourcefn to_slack(&self) -> Option<SlackMessage>
fn to_slack(&self) -> Option<SlackMessage>
Convert the notification to a Slack message.
Sourcefn notification_type(&self) -> &'static str
fn notification_type(&self) -> &'static str
Get the notification type name for logging.