pub struct Settings {
pub block_write: bool,
pub bool: HashMap<String, bool>,
pub i32: HashMap<String, i32>,
pub f32: HashMap<String, f32>,
pub string: HashMap<String, String>,
pub raw_data: HashMap<String, Vec<u8>>,
pub vec_string: HashMap<String, Vec<String>>,
}Expand description
Snapshot of every persisted setting.
Each typed sub-map keeps its own keys; lookups never cross types, so
settings.bool("X") and settings.i32("X") are independent. Lookups for
a missing key return the type’s default (false, 0, "", …).
Values mutate through the typed set_* / initialize_* methods. Each
successful set persists to disk immediately, unless set_block_write
is set to true (used for batch updates via the set_batch! macro).
Fields§
§block_write: boolWhen true, Self::write becomes a no-op. Used by set_batch!
to coalesce many updates into a single disk write.
bool: HashMap<String, bool>Boolean settings.
i32: HashMap<String, i32>Signed 32-bit integer settings.
f32: HashMap<String, f32>32-bit floating-point settings.
string: HashMap<String, String>String settings (also used for path-shaped strings; see
Self::path_buf for PathBuf access on top of the same map).
raw_data: HashMap<String, Vec<u8>>Opaque byte-blob settings.
vec_string: HashMap<String, Vec<String>>Lists-of-strings settings.
Implementations§
Source§impl Settings
impl Settings
Sourcepub fn init(as_new: bool) -> Result<Self>
pub fn init(as_new: bool) -> Result<Self>
Build a fresh Settings instance, loading from disk and applying
per-key default initialisation.
If as_new is true the on-disk file is ignored and a fully default
settings struct is returned (still applying the per-key defaults).
If reading the on-disk file fails, the broken file is backed up to
settings.json.bak and defaults are used — protects against sporadic
read failures silently resetting every setting.
Sourcepub fn read() -> Result<Self>
pub fn read() -> Result<Self>
Read the on-disk settings file (settings.json under config_path).
Errors if the file is missing or cannot be parsed as JSON. Most callers
want Self::init instead, which falls back to defaults on failure.
Sourcepub fn write(&self) -> Result<()>
pub fn write(&self) -> Result<()>
Writes the settings to disk. Does nothing if the block write flag is set.
Sourcepub fn set_block_write(&mut self, status: bool)
pub fn set_block_write(&mut self, status: bool)
Disables save to disk when storing a setting. For batch operations.
Sourcepub fn bool(&self, setting: &str) -> bool
pub fn bool(&self, setting: &str) -> bool
Read a bool setting; returns false if setting isn’t set.
Sourcepub fn string(&self, setting: &str) -> String
pub fn string(&self, setting: &str) -> String
Read a String setting; returns an empty string if setting isn’t set.
Sourcepub fn path_buf(&self, setting: &str) -> PathBuf
pub fn path_buf(&self, setting: &str) -> PathBuf
Read a path-shaped string setting as a PathBuf; returns an empty
PathBuf if setting isn’t set. Backed by the same map as
Self::string.
Sourcepub fn raw_data(&self, setting: &str) -> Vec<u8> ⓘ
pub fn raw_data(&self, setting: &str) -> Vec<u8> ⓘ
Read a raw byte-blob setting; returns an empty Vec if setting isn’t set.
Sourcepub fn vec_string(&self, setting: &str) -> Vec<String>
pub fn vec_string(&self, setting: &str) -> Vec<String>
Read a Vec<String> setting; returns an empty Vec if setting isn’t set.
Sourcepub fn set_bool(&mut self, setting: &str, value: bool) -> Result<()>
pub fn set_bool(&mut self, setting: &str, value: bool) -> Result<()>
Set a bool setting and persist to disk (subject to block_write).
Sourcepub fn set_i32(&mut self, setting: &str, value: i32) -> Result<()>
pub fn set_i32(&mut self, setting: &str, value: i32) -> Result<()>
Set an i32 setting and persist to disk (subject to block_write).
Sourcepub fn set_f32(&mut self, setting: &str, value: f32) -> Result<()>
pub fn set_f32(&mut self, setting: &str, value: f32) -> Result<()>
Set an f32 setting and persist to disk (subject to block_write).
Sourcepub fn set_string(&mut self, setting: &str, value: &str) -> Result<()>
pub fn set_string(&mut self, setting: &str, value: &str) -> Result<()>
Set a String setting and persist to disk (subject to block_write).
Sourcepub fn set_path_buf(&mut self, setting: &str, value: &Path) -> Result<()>
pub fn set_path_buf(&mut self, setting: &str, value: &Path) -> Result<()>
Set a path setting (stored as a string) and persist to disk
(subject to block_write).
Sourcepub fn set_raw_data(&mut self, setting: &str, value: &[u8]) -> Result<()>
pub fn set_raw_data(&mut self, setting: &str, value: &[u8]) -> Result<()>
Set a raw byte-blob setting and persist to disk (subject to block_write).
Sourcepub fn set_vec_string(&mut self, setting: &str, value: &[String]) -> Result<()>
pub fn set_vec_string(&mut self, setting: &str, value: &[String]) -> Result<()>
Set a Vec<String> setting and persist to disk (subject to block_write).
Sourcepub fn initialize_bool(&mut self, setting: &str, value: bool)
pub fn initialize_bool(&mut self, setting: &str, value: bool)
Set a bool setting only if it isn’t already set. Used by
Self::init to seed defaults without clobbering user choices.
Sourcepub fn initialize_i32(&mut self, setting: &str, value: i32)
pub fn initialize_i32(&mut self, setting: &str, value: i32)
Set an i32 setting only if it isn’t already set. See Self::initialize_bool.
Sourcepub fn initialize_f32(&mut self, setting: &str, value: f32)
pub fn initialize_f32(&mut self, setting: &str, value: f32)
Set an f32 setting only if it isn’t already set. See Self::initialize_bool.
Sourcepub fn initialize_string(&mut self, setting: &str, value: &str)
pub fn initialize_string(&mut self, setting: &str, value: &str)
Set a String setting only if it isn’t already set. See Self::initialize_bool.
Sourcepub fn initialize_path_buf(&mut self, setting: &str, value: &Path)
pub fn initialize_path_buf(&mut self, setting: &str, value: &Path)
Set a path setting only if it isn’t already set. See Self::initialize_bool.
Sourcepub fn initialize_raw_data(&mut self, setting: &str, value: &[u8])
pub fn initialize_raw_data(&mut self, setting: &str, value: &[u8])
Set a raw byte-blob setting only if it isn’t already set. See Self::initialize_bool.
Sourcepub fn initialize_vec_string(&mut self, setting: &str, value: &[String])
pub fn initialize_vec_string(&mut self, setting: &str, value: &[String])
Set a Vec<String> setting only if it isn’t already set. See Self::initialize_bool.
Sourcepub fn optimizer_options(&self) -> OptimizerOptions
pub fn optimizer_options(&self) -> OptimizerOptions
Project the optimiser-related boolean settings into an
OptimizerOptions suitable for handing to
rpfm_extensions::optimizer.
Sourcepub fn assembly_kit_path(&self, game: &GameInfo) -> Result<PathBuf>
pub fn assembly_kit_path(&self, game: &GameInfo) -> Result<PathBuf>
This function returns the path where the db files from the assembly kit are stored.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Settings
impl<'de> Deserialize<'de> for Settings
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Settings
impl RefUnwindSafe for Settings
impl Send for Settings
impl Sync for Settings
impl Unpin for Settings
impl UnsafeUnpin for Settings
impl UnwindSafe for Settings
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.