pub struct Config { /* private fields */ }Expand description
A key/value configuration file backed by <game_dir>/yog-config/<mod_id>.cfg.
Implementations§
Source§impl Config
impl Config
Sourcepub fn load(game_dir: &str, mod_id: &str) -> Config
pub fn load(game_dir: &str, mod_id: &str) -> Config
Load (or create) a config file for mod_id under game_dir.
The file lives at <game_dir>/yog-config/<mod_id>.cfg.
: and / in mod_id are replaced with _ in the filename.
Sourcepub fn get_or<'a>(&'a self, key: &str, default: &'a str) -> &'a str
pub fn get_or<'a>(&'a self, key: &str, default: &'a str) -> &'a str
Get a string value, or default if the key is absent.
Sourcepub fn get_int_or(&self, key: &str, default: i64) -> i64
pub fn get_int_or(&self, key: &str, default: i64) -> i64
Get an integer value, or default if absent or unparseable.
Sourcepub fn get_float_or(&self, key: &str, default: f64) -> f64
pub fn get_float_or(&self, key: &str, default: f64) -> f64
Get a float value, or default if absent or unparseable.
Sourcepub fn get_bool(&self, key: &str) -> Option<bool>
pub fn get_bool(&self, key: &str) -> Option<bool>
Get a value parsed as bool.
Truthy: true, yes, 1, on. Falsy: false, no, 0, off.
Sourcepub fn get_bool_or(&self, key: &str, default: bool) -> bool
pub fn get_bool_or(&self, key: &str, default: bool) -> bool
Get a bool value, or default if absent or unrecognised.
Sourcepub fn set(&mut self, key: impl Into<String>, value: impl ToString)
pub fn set(&mut self, key: impl Into<String>, value: impl ToString)
Set (or overwrite) a key. Call [save] to persist.
Sourcepub fn remove(&mut self, key: &str) -> Option<String>
pub fn remove(&mut self, key: &str) -> Option<String>
Remove a key. Returns the old value if present.
Sourcepub fn save(&self) -> Result<(), Error>
pub fn save(&self) -> Result<(), Error>
Persist the current state to disk. Creates yog-config/ if needed.
Comments from the original file are not preserved; keys are written in alphabetical order for determinism.
Sourcepub fn save_defaults(&self) -> Result<(), Error>
pub fn save_defaults(&self) -> Result<(), Error>
Save only if the config file does not yet exist (write defaults on first run).