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
| Level | Use Case | User Impact |
|---|---|---|
| Info | Success messages | Brief, auto-dismiss |
| Warning | Potential issues | Visible but non-blocking |
| Error | Problems requiring action | Persistent, 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§
Sourcefn send(&self, notification: Notification) -> Result<()>
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§
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.