pub trait SettingsSchema:
Serialize
+ DeserializeOwned
+ Default
+ 'static {
const SCOPE: Scope;
const APP: Option<&'static str> = None;
// Provided methods
fn defaults_on(device: DeviceClass) -> Self { ... }
fn available_on(device: DeviceClass) -> bool { ... }
fn from_settings_value(value: Value) -> Result<Self> { ... }
fn to_settings_value(&self) -> Result<Value> { ... }
}Expand description
A typed settings value with a declared Scope.
Reads never fail: a missing document reads as Default, and a key
that is missing or does not decode reads as its default while every
other key keeps its stored value. An app’s types of one scope share
its section, so their field names must not collide.
#[derive(Clone, Default, PartialEq, Serialize, Deserialize)]
struct Preferences { confirm_kill: bool }
impl SettingsSchema for Preferences {
const SCOPE: Scope = Scope::Personal;
}
let prefs = context.settings::<Preferences>().get();Required Associated Constants§
Provided Associated Constants§
Provided Methods§
Sourcefn defaults_on(device: DeviceClass) -> Self
fn defaults_on(device: DeviceClass) -> Self
What a person who changed nothing has on a device: Default everywhere,
unless the setting costs what one class of device should not spend unasked (a copy
kept on the device, work in the background).
Sourcefn available_on(device: DeviceClass) -> bool
fn available_on(device: DeviceClass) -> bool
Whether the setting means anything on a device: one whose effect a class of
device cannot have (a copy kept on a device that keeps none) is not offered there,
neither shown nor published.
Sourcefn from_settings_value(value: Value) -> Result<Self>
fn from_settings_value(value: Value) -> Result<Self>
The setting value holds, as JSON stores it. When value is not one.
Sourcefn to_settings_value(&self) -> Result<Value>
fn to_settings_value(&self) -> Result<Value>
The setting as JSON stores it; see Self::from_settings_value. When it does not
serialize.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".