Skip to main content

PersistenceManager

Struct PersistenceManager 

Source
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: PathBuf

The .limitless data directory.

§config_file: PathBuf

Path to config.json (user preferences).

§stats_file: PathBuf

Path to stats.json (lifetime counters).

§cache_file: PathBuf

Path to cache.json (last diagnostics snapshot).

Implementations§

Source§

impl PersistenceManager

Source

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).

Source

pub fn from_home(home: impl AsRef<Path>) -> Self

A manager rooted at <home>/.limitless for a given home directory.

Source

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.

Source

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.

Source

pub fn save_config(&self, config: &LimitlessConfig) -> Result<(), String>

Persists the configuration atomically, creating directories as needed.

Source

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.

Source

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).

Source

pub fn cache_diagnostics(&self, state: &EnvironmentState) -> Result<(), String>

Snapshots the current diagnostics state with a fresh timestamp.

Source

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.

Trait Implementations§

Source§

impl Clone for PersistenceManager

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PersistenceManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PersistenceManager

Source§

fn default() -> Self

Points at <home>/.limitless, falling back to the current directory when no home directory can be resolved.

Source§

impl Eq for PersistenceManager

Source§

impl PartialEq for PersistenceManager

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PersistenceManager

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.