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>
impl<T: SettingsSchema + PartialEq> SettingsRepository<T>
pub fn new(backend: Box<dyn SettingsBackend>) -> Self
Sourcepub fn update(&self, f: impl FnOnce(&mut T)) -> Result<(), SettingsError>
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.
Sourcepub fn set_field(&self, name: &str, value: Value) -> Result<(), SettingsError>
pub fn set_field(&self, name: &str, value: Value) -> Result<(), SettingsError>
Set a single field by name from a JSON value.
Sourcepub fn get_field(&self, name: &str) -> Result<Value, SettingsError>
pub fn get_field(&self, name: &str) -> Result<Value, SettingsError>
Get a single field value by name as JSON.
Sourcepub fn add_change_listener(&self, listener: ChangeListener<T>)
pub fn add_change_listener(&self, listener: ChangeListener<T>)
Add a change listener.
Sourcepub fn reload(&self) -> Result<(), SettingsError>
pub fn reload(&self) -> Result<(), SettingsError>
Reload settings from the backend.
Sourcepub fn reset_all(&self) -> Result<(), SettingsError>
pub fn reset_all(&self) -> Result<(), SettingsError>
Reset all settings to defaults and persist.
Sourcepub fn reset_field(&self, name: &str) -> Result<(), SettingsError>
pub fn reset_field(&self, name: &str) -> Result<(), SettingsError>
Reset a single field to its default.
Sourcepub fn backend(&self) -> &dyn SettingsBackend
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>
impl<T> Sync for SettingsRepository<T>
impl<T> Unpin for SettingsRepository<T>
impl<T> UnsafeUnpin for SettingsRepository<T>where
Mutex<T>: UnsafeUnpin,
Sender<T>: UnsafeUnpin,
Receiver<T>: UnsafeUnpin,
Arc<RwLock<Vec<Box<dyn Fn(&str, &T, &T) + Send + Sync>>>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more