pub struct ShadowSettings<T>where
    T: Format + Clone,
{ /* private fields */ }
Expand description

Complex settings that pulls data from 2 locations

The more complex Settings style struct that can be used, designed as a wrapper around Settings that allows for configuration ‘Shadowing’, which means you can override global settings with local settings.

ShadowSettings looks for two locations for configuration. First the configuration is defined with the ‘Configuration’ struct. Then ShadowSettings looks at the global location (the same location as Settings would look) and then looks for the same file in the current working directory.

ShadowSettings works the same as Settings except for the additional functions to get and set locally or globally. See Settings or the ron test to see how its used.

Example

If you defined your configuration as a toml at ~/.config/app/settings.toml then it will look for a local file in the current working directory called settings.toml.

You can use the Format trait to allow hidden files (i.e. “.settings.toml”) or even define an alternate name for the local file (“.myapp”). See Format for more information.

Implementations

Creates a new ShadowSetting with both global and local Settings empty.

A onliner to create a Settings and load from the config location.

Basically the same thing as .new() and .load(). The main difference is you don’t need to give your Settings mutability if you don’t need it.

Will return an empty setting if it fails loading the file for some reason. A warn!() (from the log crate) will be used if the loading fails.

Creates a new ShadowSetting and loads the file buffer into the global Setting.

attempts to load both local and global

Loads the global file, or errors

Usually not a breaking error, since it mostly errors because there isn’t a file.

Loads the local file, or errors

Usually not a breaking error, since it mostly errors because there isn’t a file.

Loads the file buffer over the existing global Settings, replacing it.

Will fail if it cannot read the buffer.

Loads the file buffer over the existing local Settings, replacing it.

Will fail if it cannot read the buffer.

saves the setting to a file, uses the save_to buffer function

Saves the global Setting to a file buffer.

Saves the global Setting to a file buffer.

Will return Ok even if there isn’t any local settings. I.E. if the Settings object never had any data in the local Settings it will return an Ok but it will not have written anything to the disk.

Gets the most accurate value from the key_path.

Since this is ‘shadowing’, Settings will look in both the local and global Settings to determine what value to return. The local value will always override the global value.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.