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§
sourcefn load_file<T: DeserializeOwned>(&self, path: impl AsRef<Path>) -> Result<T>
fn load_file<T: DeserializeOwned>(&self, path: impl AsRef<Path>) -> Result<T>
Load a file from specified path.
sourcefn save_file<T: Serialize>(
&self,
path: impl AsRef<Path>,
data: &T,
pretty: bool,
) -> Result<()>
fn save_file<T: Serialize>( &self, path: impl AsRef<Path>, data: &T, pretty: bool, ) -> Result<()>
Save a file to specified path.
sourcefn settings_path(&self) -> Result<PathBuf>
fn settings_path(&self) -> Result<PathBuf>
Get the settings path.
sourcefn global_record_path(&self, game: &str) -> Result<PathBuf>
fn global_record_path(&self, game: &str) -> Result<PathBuf>
Get the global record path.
Provided Methods§
sourcefn load_settings(&self) -> Result<Settings>
fn load_settings(&self) -> Result<Settings>
Load Settings
.
sourcefn load_global_record(&self, game: &str) -> Result<GlobalRecord>
fn load_global_record(&self, game: &str) -> Result<GlobalRecord>
Load GlobalRecord
.
sourcefn save_global_record(&self, game: &str, data: &GlobalRecord) -> Result<()>
fn save_global_record(&self, game: &str, data: &GlobalRecord) -> Result<()>
Save GlobalRecord
.
sourcefn load_records(&self, game: &str) -> Result<Vec<ActionRecord>>
fn load_records(&self, game: &str) -> Result<Vec<ActionRecord>>
Load all ActionRecord
.
sourcefn save_records(&self, game: &str, contexts: &[ActionRecord]) -> Result<()>
fn save_records(&self, game: &str, contexts: &[ActionRecord]) -> Result<()>
Save all ActionRecord
.
Object Safety§
This trait is not object safe.