Skip to main content

SubSettings

Struct SubSettings 

Source
pub struct SubSettings<S: StorageBackend = JsonStorage> { /* private fields */ }
Expand description

Sub-settings for per-entity configuration. Handler for a single sub-settings type

Implementations§

Source§

impl<S: StorageBackend + Clone + 'static> SubSettings<S>

Source

pub fn new( config_dir: &Path, config: SubSettingsConfig, storage: S, credential_manager: Option<CredentialManager>, ) -> Result<Self>

Create a new SubSettings instance

§Arguments
  • config_dir - The directory where the configuration files are stored
  • config - The configuration for the sub-settings
  • storage - The storage backend to use
§Errors

Returns an error if:

  • The cache strategy is invalid
  • Profile migration fails
  • File operations fail
Source

pub fn root_path(&self) -> PathBuf

Source

pub fn is_single_file(&self) -> bool

Source

pub fn profiles_enabled(&self) -> bool

Source

pub fn extension(&self) -> &str

Source

pub fn schema_metadata(&self) -> Option<Arc<HashMap<String, SettingMetadata>>>

Source

pub fn storage(&self) -> &S

Source

pub fn invalidate_cache(&self)

Source

pub fn profiles(&self) -> Result<&ProfileManager<S>>

Get the profile manager if enabled

§Errors

Returns an error if profiles are not enabled for this sub-settings type.

Source

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

Switch to a different profile

§Arguments
  • name - The name of the profile to switch to
§Errors

Returns an error if:

  • Profiles are not enabled
  • Profile switch fails
  • Store re-creation fails
Source

pub fn set_on_change<F>(&self, callback: F) -> Result<()>
where F: Fn(&str, SubSettingsAction) + Send + Sync + 'static,

Set the change callback

§Arguments
  • callback - The callback to set
§Errors

Returns an error if the internal lock is poisoned.

Source

pub fn set_field<T: Serialize + Sync>( &self, name: &str, field_path: &str, value: &T, ) -> Result<()>

Update a single field in a sub-settings entry.

This performs a read-modify-write on one entry:

  • Loads existing entry (or {} if missing)
  • Sets the provided field path (supports dot notation)
  • Saves through set(), so schema validation and secret handling still apply
§Errors

Returns an error if serialization fails, schema validation fails, or store write fails.

Source

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

Get a raw Value from the store

§Arguments
  • name - The name of the setting to retrieve
§Errors

Returns an error if the setting is not found or store access fails.

Source

pub fn get<T: DeserializeOwned>(&self, name: &str) -> Result<T>

Get and deserialize a value from the store

§Arguments
  • name - The name of the setting to retrieve
§Errors

Returns an error if:

  • The setting is not found
  • Deserialization fails
  • Store access fails
Source

pub fn set<T: Serialize + Sync>(&self, name: &str, value: &T) -> Result<()>

Serialize and set a value in the store

§Arguments
  • name - The name of the setting to set
  • value - The value to set
§Errors

Returns an error if:

  • Serialization fails
  • Store write fails
Source

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

Delete a value from the store

§Arguments
  • name - The name of the setting to delete
§Errors

Returns an error if store write fails.

Source

pub fn list(&self) -> Result<Vec<String>>

List all sub-setting keys

§Errors

Returns an error if the store cannot be read.

Source

pub fn get_all_values(&self) -> Result<HashMap<String, Value>>

Get all sub-setting entries as a map

Returns a HashMap<String, Value> with all entry names as keys and their deserialized values. Entries that fail to load are silently skipped.

§Errors

Returns an error if the store cannot be read.

Source

pub fn exists(&self, name: &str) -> Result<bool>

Check if a sub-setting key exists

§Arguments
  • name - The name of the setting to check
§Errors

Returns an error if the store cannot be read or if an unexpected error occurs during lookup.

Source

pub fn directory(&self) -> PathBuf

Source

pub fn file_path(&self) -> Option<PathBuf>

Auto Trait Implementations§

§

impl<S = JsonStorage> !Freeze for SubSettings<S>

§

impl<S = JsonStorage> !RefUnwindSafe for SubSettings<S>

§

impl<S> Send for SubSettings<S>

§

impl<S> Sync for SubSettings<S>

§

impl<S> Unpin for SubSettings<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for SubSettings<S>
where S: UnsafeUnpin,

§

impl<S = JsonStorage> !UnwindSafe for SubSettings<S>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.