Trait NotifyPort

Source
pub trait NotifyPort: Send + Sync {
    // Required method
    fn send(&self, notification: Notification) -> Result<()>;

    // Provided methods
    fn info(
        &self,
        title: impl Into<String>,
        body: impl Into<String>,
    ) -> Result<()> { ... }
    fn warning(
        &self,
        title: impl Into<String>,
        body: impl Into<String>,
    ) -> Result<()> { ... }
    fn error(
        &self,
        title: impl Into<String>,
        body: impl Into<String>,
    ) -> Result<()> { ... }
    fn is_available(&self) -> bool { ... }
}
Expand description

Port for sending desktop notifications.

NotifyPort provides a way to display notifications to the user. This is used for:

  • Configuration errors that need user attention
  • Successful theme reloads
  • Warnings about deprecated options

§Notification Levels

LevelUse CaseUser Impact
InfoSuccess messagesBrief, auto-dismiss
WarningPotential issuesVisible but non-blocking
ErrorProblems requiring actionPersistent, prominent

§Desktop Integration

The notification adapter should use the system notification service:

  • Linux: D-Bus org.freedesktop.Notifications
  • macOS: NSUserNotificationCenter
  • Windows: Toast notifications

§Example

ⓘ
use fernctl::ports::outbound::NotifyPort;
use fernctl::error::Notification;

// Send an info notification
let notification = Notification::info(
    "Theme Loaded",
    "Dark theme applied successfully",
);
adapter.send(notification)?;

// Send an error notification
let notification = Notification::error(
    "Invalid Color",
    "Color '#gg0000' is not valid",
).with_suggestion("Use hex format: #RRGGBB");
adapter.send(notification)?;

§Suppressing Notifications

Users may want to disable notifications. Adapters should respect a configuration option for this:

ⓘ
if !config.notifications_enabled {
    return Ok(()); // Silently succeed
}

Required Methods§

Source

fn send(&self, notification: Notification) -> Result<()>

Sends a notification to the desktop notification service.

§Arguments
  • notification — The notification to display
§Errors

Returns an error if the notification cannot be sent. However, notification failures are typically non-fatal — the application should continue even if notifications are unavailable.

§Example
ⓘ
let notification = Notification::info("Test", "Hello world");
if let Err(e) = adapter.send(notification) {
    // Log but don't fail
    log::warn!("Could not send notification: {}", e);
}

Provided Methods§

Source

fn info(&self, title: impl Into<String>, body: impl Into<String>) -> Result<()>

Sends an info-level notification.

Convenience method for sending simple informational notifications.

§Arguments
  • title — The notification title
  • body — The notification body text
§Example
ⓘ
adapter.info("Theme Loaded", "Configuration applied")?;
Source

fn warning( &self, title: impl Into<String>, body: impl Into<String>, ) -> Result<()>

Sends a warning-level notification.

Convenience method for sending warning notifications.

§Arguments
  • title — The notification title
  • body — The notification body text
§Example
ⓘ
adapter.warning("Deprecated Option", "The 'colour' key is deprecated")?;
Source

fn error(&self, title: impl Into<String>, body: impl Into<String>) -> Result<()>

Sends an error-level notification.

Convenience method for sending error notifications.

§Arguments
  • title — The notification title
  • body — The notification body text
§Example
ⓘ
adapter.error("Config Error", "Invalid color format")?;
Source

fn is_available(&self) -> bool

Checks if notifications are available on this system.

§Returns

true if the notification service is available and responding.

§Example
ⓘ
if adapter.is_available() {
    adapter.send(notification)?;
} else {
    eprintln!("{}", notification); // Fallback to stderr
}

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§