pub trait Notifiable {
// Required methods
fn severity(&self) -> Severity;
fn title(&self) -> String;
fn body(&self) -> String;
// Provided methods
fn suggestion(&self) -> Option<String> { ... }
fn code(&self) -> Option<&'static str> { ... }
fn to_notification(&self) -> Notification { ... }
}Expand description
Trait for types that can be converted to user-facing notifications.
Implement this trait on error types to enable rich desktop notifications. The trait provides all the information needed to display a helpful, actionable notification to the user.
§Required Methods
| Method | Purpose |
|---|---|
severity | How serious is this? |
title | Short summary for notification header |
body | Detailed explanation |
§Optional Methods
| Method | Purpose | Default |
|---|---|---|
suggestion | How to fix it | None |
code | Error code for docs | None |
§Example Implementation
use fernctl::error::{Notifiable, Severity};
struct MyError {
message: String,
}
impl Notifiable for MyError {
fn severity(&self) -> Severity {
Severity::Error
}
fn title(&self) -> String {
"Something Went Wrong".to_string()
}
fn body(&self) -> String {
self.message.clone()
}
fn suggestion(&self) -> Option<String> {
Some("Try restarting the shell".to_string())
}
fn code(&self) -> Option<&'static str> {
Some("my::error::code")
}
}Required Methods§
Sourcefn title(&self) -> String
fn title(&self) -> String
Returns a short title for the notification header.
This should be concise (ideally under 50 characters) and immediately convey the nature of the notification.
§Good Titles
- “Invalid Color”
- “Config Loaded”
- “Module Failed: Clock”
§Bad Titles
- “Error” (too vague)
- “The color value you specified in config.toml is not valid” (too long)
Provided Methods§
Sourcefn suggestion(&self) -> Option<String>
fn suggestion(&self) -> Option<String>
Returns an optional suggestion for fixing the problem.
When present, this should be an actionable instruction the user can follow. Be specific and helpful.
§Good Suggestions
- “Use hex format: #RRGGBB”
- “Did you mean
color?” - “Check that QuickShell is running”
§Bad Suggestions
- “Fix the error” (not actionable)
- “See documentation” (too vague — link to specific docs instead)
Sourcefn code(&self) -> Option<&'static str>
fn code(&self) -> Option<&'static str>
Returns an optional error code for documentation lookup.
Error codes follow the pattern category::subcategory::name and can
be used to find detailed documentation.
§Example Codes
fern::config::invalid_colorfern::io::permission_deniedfern::ipc::timeout
Sourcefn to_notification(&self) -> Notification
fn to_notification(&self) -> Notification
Converts this notifiable into a Notification struct.
This is a convenience method that creates a notification with all fields populated from the trait methods.
§Example
let notification = error.to_notification();
notify_port.send(notification)?;