pub trait PersistPort: Send + Sync {
// Required methods
fn save_theme(&self, theme: &Theme, path: impl AsRef<Path>) -> Result<()>;
fn load_theme(&self, path: impl AsRef<Path>) -> Result<Theme>;
fn config_dir(&self) -> Option<PathBuf>;
fn ensure_config_dir(&self) -> Result<PathBuf>;
fn exists(&self, path: impl AsRef<Path>) -> bool;
}Expand description
Port for persisting configuration and themes to storage.
PersistPort abstracts over different storage backends, enabling the
domain to save and load themes without knowing the underlying storage
mechanism.
§Implementations
- Filesystem — Writes JSON files to
~/.config/fern/ - XDG — Follows XDG Base Directory Specification
- Memory — In-memory storage for testing
§File Structure
The recommended file structure for persisted themes:
~/.config/fern/
├── config.toml # User configuration (source of truth)
├── config.json # Generated JSON for QuickShell
└── themes/
├── dark.json # Built-in dark theme
├── light.json # Built-in light theme
└── custom.json # User-created themes§Example
ⓘ
use fernctl::ports::outbound::PersistPort;
use fernctl::adapters::FileSystemAdapter;
let adapter = FileSystemAdapter::new();
// Save a theme
adapter.save_theme(&theme, "~/.config/fern/config.json")?;
// Load a theme
let loaded = adapter.load_theme("~/.config/fern/config.json")?;Required Methods§
Sourcefn config_dir(&self) -> Option<PathBuf>
fn config_dir(&self) -> Option<PathBuf>
Returns the default configuration directory.
This follows platform conventions:
- Linux:
~/.config/fern/ - macOS:
~/Library/Application Support/fern/ - Windows:
%APPDATA%\fern\
§Returns
The path to the configuration directory, or None if it cannot be
determined.
Sourcefn ensure_config_dir(&self) -> Result<PathBuf>
fn ensure_config_dir(&self) -> Result<PathBuf>
Ensures the configuration directory exists.
Creates the directory and any parent directories if they don’t exist.
§Errors
Returns [FernError::Io] if the directory cannot be created.
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.