| Crates.io | ferro-notifications |
| lib.rs | ferro-notifications |
| version | 0.1.71 |
| created_at | 2026-01-16 17:13:33.614236+00 |
| updated_at | 2026-01-17 20:04:38.888636+00 |
| description | Multi-channel notification system for Ferro framework |
| homepage | |
| repository | https://github.com/albertogferrario/ferro |
| max_upload_size | |
| id | 2048981 |
| size | 87,361 |
Multi-channel notification system for the Ferro framework.
use ferro_notifications::{Notification, Notifiable, Channel, MailMessage};
// Define a notification
struct OrderShipped {
order_id: i64,
tracking: 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)))
}
}
// Make User notifiable
struct User {
id: i64,
email: String,
}
impl Notifiable for User {
fn route_notification_for(&self, channel: Channel) -> Option<String> {
match channel {
Channel::Mail => Some(self.email.clone()),
Channel::Database => Some(self.id.to_string()),
_ => None,
}
}
}
// Send the notification
let user = User { id: 1, email: "user@example.com".into() };
user.notify(OrderShipped {
order_id: 123,
tracking: "ABC123".into(),
}).await?;
fn to_slack(&self) -> Option<SlackMessage> {
Some(SlackMessage::new()
.text("New order shipped!")
.attachment(SlackAttachment::new()
.title("Order Details")
.field("Order ID", &self.order_id.to_string(), true)))
}
MIT