pub struct Settings { /* private fields */ }Expand description
Typed access to the settings store.
Implementations§
Source§impl Settings
impl Settings
pub fn new(store: Arc<dyn SettingsStore>) -> Self
Sourcepub async fn get<T: DeserializeOwned>(&self, setting: &Setting<T>) -> Result<T>
pub async fn get<T: DeserializeOwned>(&self, setting: &Setting<T>) -> Result<T>
The stored value, or the declared default.
A stored value that no longer decodes — because the setting’s type changed between releases — falls back to the default and logs a warning. Refusing to start over a stale preference would be worse than ignoring it.
pub async fn set<T: Serialize>( &self, setting: &Setting<T>, value: &T, ) -> Result<()>
Sourcepub async fn reset<T>(&self, setting: &Setting<T>) -> Result<()>
pub async fn reset<T>(&self, setting: &Setting<T>) -> Result<()>
Drop the stored value so the next read returns the default.
Sourcepub async fn get_json(&self, key: &str) -> Result<Option<Value>>
pub async fn get_json(&self, key: &str) -> Result<Option<Value>>
Untyped read for generic settings UIs, which do not know the concrete types.
Prefer Settings::get wherever the setting is known at compile time.
Sourcepub async fn set_json(&self, key: &str, value: &Value) -> Result<()>
pub async fn set_json(&self, key: &str, value: &Value) -> Result<()>
Untyped write for generic settings UIs.
The value is not validated against the setting’s declared type — a generic
caller has no way to know it. A value that no longer decodes is ignored on read
(see Settings::get), so a bad write degrades to the default rather than
breaking startup.
Sourcepub async fn customised_keys(&self) -> Result<Vec<String>>
pub async fn customised_keys(&self) -> Result<Vec<String>>
Keys that currently have a stored value. Settings left at their default are not listed.