pub trait SettingsManager {
    // Required methods
    fn load_file<T: DeserializeOwned>(
        &self,
        path: impl AsRef<Path>
    ) -> Result<T>;
    fn save_file<T: Serialize>(
        &self,
        path: impl AsRef<Path>,
        data: &T,
        pretty: bool
    ) -> Result<()>;
    fn settings_path(&self) -> Result<PathBuf>;
    fn global_record_path(&self, game: &str) -> Result<PathBuf>;
    fn records_path(
        &self,
        game: &str
    ) -> Result<impl Iterator<Item = Result<PathBuf>>>;
    fn record_path(&self, game: &str, i: usize) -> Result<PathBuf>;

    // Provided methods
    fn load_settings(&self) -> Result<Settings> { ... }
    fn save_settings(&self, data: &Settings) -> Result<()> { ... }
    fn load_global_record(&self, game: &str) -> Result<GlobalRecord> { ... }
    fn save_global_record(&self, game: &str, data: &GlobalRecord) -> Result<()> { ... }
    fn load_records(&self, game: &str) -> Result<Vec<ActionRecord>> { ... }
    fn save_records(&self, game: &str, contexts: &[ActionRecord]) -> Result<()> { ... }
}
Expand description

A settings manager trait.

This type should handle the file loading and saving, and manage the paths of the files.

Required Methods§

source

fn load_file<T: DeserializeOwned>(&self, path: impl AsRef<Path>) -> Result<T>

Load a file from specified path.

source

fn save_file<T: Serialize>( &self, path: impl AsRef<Path>, data: &T, pretty: bool ) -> Result<()>

Save a file to specified path.

source

fn settings_path(&self) -> Result<PathBuf>

Get the settings path.

source

fn global_record_path(&self, game: &str) -> Result<PathBuf>

Get the global record path.

source

fn records_path( &self, game: &str ) -> Result<impl Iterator<Item = Result<PathBuf>>>

Get an iterator of record paths.

source

fn record_path(&self, game: &str, i: usize) -> Result<PathBuf>

Get the record path from index.

Provided Methods§

source

fn load_settings(&self) -> Result<Settings>

Load Settings.

source

fn save_settings(&self, data: &Settings) -> Result<()>

Save Settings.

source

fn load_global_record(&self, game: &str) -> Result<GlobalRecord>

source

fn save_global_record(&self, game: &str, data: &GlobalRecord) -> Result<()>

source

fn load_records(&self, game: &str) -> Result<Vec<ActionRecord>>

Load all ActionRecord.

source

fn save_records(&self, game: &str, contexts: &[ActionRecord]) -> Result<()>

Save all ActionRecord.

Object Safety§

This trait is not object safe.

Implementors§