Skip to main content

SettingsRepository

Struct SettingsRepository 

Source
pub struct SettingsRepository<T: SettingsSchema> { /* private fields */ }
Expand description

Repository for reading/writing settings via a pluggable backend.

Implementations§

Source§

impl<T: SettingsSchema + PartialEq> SettingsRepository<T>

Source

pub fn new(backend: Box<dyn SettingsBackend>) -> Self

Source

pub fn get(&self) -> T

Get the current settings value.

Source

pub fn update(&self, f: impl FnOnce(&mut T)) -> Result<(), SettingsError>

Update settings with a mutation function. Validates all fields after mutation - if validation fails, the mutation is not persisted.

Source

pub fn set_field(&self, name: &str, value: Value) -> Result<(), SettingsError>

Set a single field by name from a JSON value.

Source

pub fn get_field(&self, name: &str) -> Result<Value, SettingsError>

Get a single field value by name as JSON.

Source

pub fn subscribe(&self) -> Receiver<T>

Subscribe to changes (returns a watch receiver).

Source

pub fn add_change_listener(&self, listener: ChangeListener<T>)

Add a change listener.

Source

pub fn reload(&self) -> Result<(), SettingsError>

Reload settings from the backend.

Source

pub fn reset_all(&self) -> Result<(), SettingsError>

Reset all settings to defaults and persist.

Source

pub fn reset_field(&self, name: &str) -> Result<(), SettingsError>

Reset a single field to its default.

Source

pub fn backend(&self) -> &dyn SettingsBackend

Get the backend reference (for backup manager, etc.).

Auto Trait Implementations§

§

impl<T> !Freeze for SettingsRepository<T>

§

impl<T> !RefUnwindSafe for SettingsRepository<T>

§

impl<T> !UnwindSafe for SettingsRepository<T>

§

impl<T> Send for SettingsRepository<T>
where Mutex<T>: Send, Sender<T>: Send, Receiver<T>: Send, Arc<RwLock<Vec<Box<dyn Fn(&str, &T, &T) + Send + Sync>>>>: Send,

§

impl<T> Sync for SettingsRepository<T>
where Mutex<T>: Sync, Sender<T>: Sync, Receiver<T>: Sync, Arc<RwLock<Vec<Box<dyn Fn(&str, &T, &T) + Send + Sync>>>>: Sync,

§

impl<T> Unpin for SettingsRepository<T>
where Mutex<T>: Unpin, Sender<T>: Unpin, Receiver<T>: Unpin, Arc<RwLock<Vec<Box<dyn Fn(&str, &T, &T) + Send + Sync>>>>: Unpin,

§

impl<T> UnsafeUnpin for SettingsRepository<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.