Skip to main content

Settings

Struct Settings 

Source
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: bool

When 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

Source

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.

Source

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.

Source

pub fn write(&self) -> Result<()>

Writes the settings to disk. Does nothing if the block write flag is set.

Source

pub fn set_block_write(&mut self, status: bool)

Disables save to disk when storing a setting. For batch operations.

Source

pub fn bool(&self, setting: &str) -> bool

Read a bool setting; returns false if setting isn’t set.

Source

pub fn i32(&self, setting: &str) -> i32

Read an i32 setting; returns 0 if setting isn’t set.

Source

pub fn f32(&self, setting: &str) -> f32

Read an f32 setting; returns 0.0 if setting isn’t set.

Source

pub fn string(&self, setting: &str) -> String

Read a String setting; returns an empty string if setting isn’t set.

Source

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.

Source

pub fn raw_data(&self, setting: &str) -> Vec<u8>

Read a raw byte-blob setting; returns an empty Vec if setting isn’t set.

Source

pub fn vec_string(&self, setting: &str) -> Vec<String>

Read a Vec<String> setting; returns an empty Vec if setting isn’t set.

Source

pub fn set_bool(&mut self, setting: &str, value: bool) -> Result<()>

Set a bool setting and persist to disk (subject to block_write).

Source

pub fn set_i32(&mut self, setting: &str, value: i32) -> Result<()>

Set an i32 setting and persist to disk (subject to block_write).

Source

pub fn set_f32(&mut self, setting: &str, value: f32) -> Result<()>

Set an f32 setting and persist to disk (subject to block_write).

Source

pub fn set_string(&mut self, setting: &str, value: &str) -> Result<()>

Set a String setting and persist to disk (subject to block_write).

Source

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).

Source

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).

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn optimizer_options(&self) -> OptimizerOptions

Project the optimiser-related boolean settings into an OptimizerOptions suitable for handing to rpfm_extensions::optimizer.

Source

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 Clone for Settings

Source§

fn clone(&self) -> Settings

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Settings

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Settings

Source§

fn default() -> Settings

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Settings

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Settings

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,