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).
pub fn is_empty(&self) -> bool
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.