Skip to main content

SettingsSchema

Trait SettingsSchema 

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

Source

const APP: Option<&'static str> = None

Provided Methods§

Source

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

Source

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.

Source

fn from_settings_value(value: Value) -> Result<Self>

The setting value holds, as JSON stores it. When value is not one.

Source

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

Implementors§