SettingsIO trait, save/load settings to/from file

This commit is contained in:
Aleksander
2025-11-08 11:16:19 +01:00
parent 71898056f3
commit 6f41ffe59c
4 changed files with 71 additions and 9 deletions

View File

@@ -25,10 +25,18 @@ pub struct Settings {
impl Settings {
pub fn save(&self) -> String {
serde_json::to_string(&self).unwrap() /* want panic */
serde_json::to_string_pretty(&self).unwrap() /* want panic */
}
pub fn load(input: &str) -> anyhow::Result<Settings> {
Ok(serde_json::from_str::<Settings>(input)?)
}
}
pub trait SettingsIO {
fn get_mut(&mut self) -> &mut Settings;
fn get(&self) -> &Settings;
fn save_to_disk(&mut self);
fn read_from_disk(&mut self);
fn mark_as_dirty(&mut self);
}