Trait Notifiable

Source
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

MethodPurpose
severityHow serious is this?
titleShort summary for notification header
bodyDetailed explanation

§Optional Methods

MethodPurposeDefault
suggestionHow to fix itNone
codeError code for docsNone

§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§

Source

fn severity(&self) -> Severity

Returns the severity level of this notification.

Severity determines the visual presentation and behavior:

  • Info — Subtle, may auto-dismiss
  • Warning — Visible, yellow/orange styling
  • Error — Prominent, red styling, requires attention
  • Fatal — Critical, may block other UI
Source

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)
Source

fn body(&self) -> String

Returns the detailed body text of the notification.

This should explain what happened. For errors, include specifics about what went wrong. Keep it readable — avoid raw error dumps.

Provided Methods§

Source

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)
Source

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_color
  • fern::io::permission_denied
  • fern::ipc::timeout
Source

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)?;

Implementors§