pub struct SettingsStore { /* private fields */ }Expand description
Handles persistence of Settings to disk.
By default, uses ~/.config/tinyharness/settings.json. This can be
overridden with SettingsStore::new for testing or alternative paths.
Implementations§
Source§impl SettingsStore
impl SettingsStore
Sourcepub fn default_path() -> Self
pub fn default_path() -> Self
Create a store that reads/writes from the default path
(~/.config/tinyharness/settings.json).
Prefer SettingsStore::from_paths when the caller has a
Paths instance — this form resolves from the
ambient process environment.
Sourcepub fn from_paths(paths: &Paths) -> Self
pub fn from_paths(paths: &Paths) -> Self
Create a store that reads/writes from paths.settings_file().
Sourcepub fn load(&self) -> Result<Settings, SettingsError>
pub fn load(&self) -> Result<Settings, SettingsError>
Load settings from disk.
Returns Ok(Settings) with defaults if the file doesn’t exist,
or an error if the file exists but cannot be parsed.
Sourcepub fn load_or_default(&self) -> Settings
pub fn load_or_default(&self) -> Settings
Load settings from disk, returning defaults on any error.
This matches the original behaviour and is suitable for application
startup where you don’t want to fail on corrupt settings files.
If the file is present but unparseable, it is renamed to
settings.json.corrupt so the user can recover their data.
Sourcepub fn save(&self, settings: &Settings) -> Result<(), SettingsError>
pub fn save(&self, settings: &Settings) -> Result<(), SettingsError>
Save settings to disk atomically (write to temp file, fsync, then rename).
Uses a unique temp file name (with PID) to avoid collisions if two saves overlap. The temp file is fsync’d before the rename to ensure data durability — without this, a crash after rename but before the kernel flushes the data could leave an empty or partial file.