Trait SettingsSchema
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, Error> { ... }
fn to_settings_value(&self) -> Result<Value, Error> { ... }
}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§
const APP: Option<&'static str> = None
const APP: Option<&'static str> = None
The app whose own settings these are when another app keeps them
for it, as Settings keeps the on-screen keyboard’s layouts: a
Scope::Personal or Scope::DeviceLocal value is that app’s,
whichever app reads or writes it. None: the app that holds them.
Provided Methods§
fn 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).
fn 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.
fn from_settings_value(value: Value) -> Result<Self, Error>
fn from_settings_value(value: Value) -> Result<Self, Error>
The setting value holds, as JSON stores it. Generic code reading
a setting compiles this, and serde’s whole decoder for the type,
into each crate that names the type; a large type’s own crate can
compile it once instead with settings_codec!.
§Errors
When value is not one.
fn to_settings_value(&self) -> Result<Value, Error>
fn to_settings_value(&self) -> Result<Value, Error>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.