pub struct PersistenceManager {
pub config_dir: PathBuf,
pub config_file: PathBuf,
pub stats_file: PathBuf,
pub cache_file: PathBuf,
}Expand description
Owns the ~/.limitless/ data directory and its three JSON files.
use limitless_cli::modules::config::PersistenceManager;
let manager = PersistenceManager::default();
assert!(manager.config_file.ends_with("config.json"));
assert!(manager.stats_file.ends_with("stats.json"));
assert!(manager.cache_file.ends_with("cache.json"));Fields§
§config_dir: PathBufThe .limitless data directory.
config_file: PathBufPath to config.json (user preferences).
stats_file: PathBufPath to stats.json (lifetime counters).
cache_file: PathBufPath to cache.json (last diagnostics snapshot).
Implementations§
Source§impl PersistenceManager
impl PersistenceManager
Sourcepub fn at_dir(dir: impl AsRef<Path>) -> Self
pub fn at_dir(dir: impl AsRef<Path>) -> Self
A manager rooted at an explicit .limitless directory (tests use
this to keep the real home directory untouched).
Sourcepub fn from_home(home: impl AsRef<Path>) -> Self
pub fn from_home(home: impl AsRef<Path>) -> Self
A manager rooted at <home>/.limitless for a given home directory.
Sourcepub fn load_config(&self) -> Result<Option<LimitlessConfig>, String>
pub fn load_config(&self) -> Result<Option<LimitlessConfig>, String>
Loads the config file, or None when it does not exist.
A corrupt file is an error (not silently a default), so bad edits are visible instead of silently reset.
Sourcepub fn init_config(&self) -> Result<LimitlessConfig, String>
pub fn init_config(&self) -> Result<LimitlessConfig, String>
Ensures the data directory and config file exist, then returns the parsed configuration. Missing files are recreated with defaults.
Sourcepub fn save_config(&self, config: &LimitlessConfig) -> Result<(), String>
pub fn save_config(&self, config: &LimitlessConfig) -> Result<(), String>
Persists the configuration atomically, creating directories as needed.
Sourcepub fn load_stats(&self) -> Result<ArcadeStats, String>
pub fn load_stats(&self) -> Result<ArcadeStats, String>
Loads the lifetime usage counters. A missing file yields an empty
ArcadeStats; a corrupt file is surfaced as an error. Pre-config.rs
files that stored the old {stats, unlocked} progress wrapper in
stats.json are read via the inner counters.
Sourcepub fn save_stats(&self, stats: &ArcadeStats) -> Result<(), String>
pub fn save_stats(&self, stats: &ArcadeStats) -> Result<(), String>
Persists the lifetime counters atomically, creating directories as needed. Always saves a full snapshot (counters keep accumulating across runs).
Sourcepub fn cache_diagnostics(&self, state: &EnvironmentState) -> Result<(), String>
pub fn cache_diagnostics(&self, state: &EnvironmentState) -> Result<(), String>
Snapshots the current diagnostics state with a fresh timestamp.
Sourcepub fn get_cached_diagnostics(&self) -> Option<EnvironmentState>
pub fn get_cached_diagnostics(&self) -> Option<EnvironmentState>
Returns the cached EnvironmentState when it is fresh (≤ 5 minutes
old). Expired, missing or corrupt caches yield None.
On a hit the health score is recomputed so it is never stale.