Skip to main content

SettingsConfigBuilder

Struct SettingsConfigBuilder 

Source
pub struct SettingsConfigBuilder<S: StorageBackend = JsonStorage, Schema: SettingsSchema = ()> { /* private fields */ }
Expand description

Core configuration types and traits for settings management. Builder for creating SettingsConfig with a fluent API.

This is the recommended way to create a settings manager.

§Type Parameters

  • Schema: Settings schema type (defaults to () for dynamic usage)

§Examples

Type-Safe (With Schema):

use rcman::{SettingsConfig, SettingsSchema, SettingMetadata, settings};
use serde::{Serialize, Deserialize};
use std::collections::HashMap;

#[derive(Default, Serialize, Deserialize)]
struct MySettings { theme: String }

impl SettingsSchema for MySettings {
    fn get_metadata() -> HashMap<String, SettingMetadata> {
        settings! { "ui.theme" => SettingMetadata::text("dark").meta_str("label", "Theme") }
    }
}

let config = SettingsConfig::builder("my-app", "1.0.0")
    .with_schema::<MySettings>()
    .with_config_dir("~/.config/my-app")
    .build();

Dynamic (Without Schema):

use rcman::SettingsConfig;

let config = SettingsConfig::builder("my-app", "1.0.0")
    .with_config_dir("~/.config/my-app")
    .build();

Implementations§

Source§

impl SettingsConfigBuilder

Source

pub fn new(app_name: impl Into<String>, app_version: impl Into<String>) -> Self

Create a new builder with required app name and version

Source§

impl<S: StorageBackend, Schema: SettingsSchema> SettingsConfigBuilder<S, Schema>

Source

pub fn with_pretty_json(self, pretty: bool) -> Self

Use compact JSON (no pretty printing)

Note: This method is only available when using JsonStorage.

§Example
use rcman::SettingsConfig;

let config = SettingsConfig::builder("my-app", "1.0.0")
    .build();
Source

pub fn with_config_dir(self, path: impl Into<PathBuf>) -> Self

Set the configuration directory

Supports ~ expansion for home directory.

Source

pub fn settings_file(self, filename: impl Into<String>) -> Self

Set the settings filename (default: “settings.{ext}”)

Source

pub fn with_credentials(self) -> Self

Enable credential management for secret settings with default behavior.

When enabled, settings marked as secret: true in metadata will be stored in the primary OS keychain instead of the settings file.

Source

pub fn with_credential_config(self, config: CredentialConfig) -> Self

Extensively configure how credential secrets should be stored, enabling advanced scenarios like custom proxy backends or keychain fallbacks.

§Example
use rcman::{SettingsConfig, CredentialConfig, SecretPasswordSource};

let config = SettingsConfig::builder("my-app", "1.0.0")
    .with_credential_config(CredentialConfig::WithFallback {
        fallback_path: "/tmp/secrets.enc.json".into(),
        password: SecretPasswordSource::Environment("APP_KEY".into()),
    })
    .build();
Source

pub fn with_encrypted_fallback( self, path: impl Into<PathBuf>, password_source: SecretPasswordSource, ) -> Self

Enable credential management with an encrypted file fallback triggered by a password source.

This is the recommended way to support CI/Docker environments securely.

Source

pub fn with_env_credentials(self) -> Self

Source

pub fn with_custom_env_credentials(self, var_name: impl Into<String>) -> Self

Enable credentials with a custom environment variable password source (Keychain + Encrypted File fallback).

The fallback file will be stored at the default path in the config directory.

Source

pub fn with_file_credentials(self, path: impl Into<PathBuf>) -> Self

Enable credentials with file password source (Keychain + Encrypted File fallback).

The fallback file will be stored at the default path in the config directory.

Source

pub fn with_password_credentials(self, password: impl Into<String>) -> Self

Enable credentials with provided password string (Keychain + Encrypted File fallback).

The fallback file will be stored at the default path in the config directory.

Source

pub fn with_external_config(self, config: ExternalConfig) -> Self

Register an external configuration file for backup

External configs are files managed outside of rcman (like rclone.conf) that can be included in backups.

§Example
use rcman::SettingsConfig;
use rcman::backup::ExternalConfig;

let config = SettingsConfig::builder("my-app", "1.0.0")
    .with_external_config(ExternalConfig::new("rclone", "/path/to/rclone.conf")
        .display_name("Rclone Configuration"))
    .build();
Source

pub fn with_env_prefix(self, prefix: impl Into<String>) -> Self

Enable environment variable overrides

When set, settings can be overridden by environment variables. The format is: {PREFIX}_{CATEGORY}_{KEY} (all uppercase, dots become underscores)

§Example
use rcman::SettingsConfig;

let config = SettingsConfig::builder("my-app", "1.0.0")
    .with_env_prefix("MYAPP")
    .build();

// Now MYAPP_UI_THEME=dark will override the "ui.theme" setting
Source

pub fn env_overrides_secrets(self, allow: bool) -> Self

Allow environment variables to override secret settings

By default, secrets stored in the OS keychain are NOT affected by env vars. Enable this for Docker/CI environments where secrets are passed via env.

§Example
use rcman::SettingsConfig;

let config = SettingsConfig::builder("my-app", "1.0.0")
    .with_env_prefix("MYAPP")
    .env_overrides_secrets(true)  // MYAPP_API_KEY will override keychain
    .build();
Source

pub fn with_env_source(self, source: Arc<dyn EnvSource>) -> Self

Set a custom environment variable source

Useful for testing or injecting env vars procedurally.

Source

pub fn with_migrator<F>(self, migrator: F) -> Self
where F: Fn(Value) -> Value + Send + Sync + 'static,

Set a migration function for schema changes (lazy migration)

The migrator function is called automatically when loading settings. If the function modifies the value, the migrated version is saved back.

Use this to upgrade old data formats to new ones transparently.

§Example
use rcman::SettingsConfig;
use serde_json::json;

let config = SettingsConfig::builder("my-app", "1.0.0")
    .with_migrator(|mut value| {
        // Migrate v1 to v2: rename "color" to "theme"
        if let Some(obj) = value.as_object_mut() {
            if let Some(ui) = obj.get_mut("ui").and_then(|v| v.as_object_mut()) {
                if let Some(color) = ui.remove("color") {
                    ui.insert("theme".to_string(), color);
                }
            }
        }
        value
    })
    .build();
Source

pub fn with_hot_reload(self) -> Self

Enable hot-reload with default configuration.

Source

pub fn with_hot_reload_config(self, config: HotReloadConfig) -> Self

Enable hot-reload with a custom configuration.

Source

pub fn with_profiles(self) -> Self

Enable profiles for main settings

When enabled, the main settings file is stored per-profile, allowing completely different configurations (e.g., “work” vs “personal”).

§Example
use rcman::SettingsManager;

let manager = SettingsManager::builder("my-app", "1.0.0")
    .with_profiles()  // Enable profiles for main settings
    .build()?;

// Now you can switch profiles
manager.switch_profile("work")?;
Source

pub fn with_schema<NewSchema: SettingsSchema>( self, ) -> SettingsConfigBuilder<S, NewSchema>

Specify the schema type for compile-time type safety.

This binds your settings struct to the manager, enabling:

  • Type-safe get_all() method returning your struct
  • Compile-time validation of setting keys
  • Better IDE autocomplete and refactoring support
§Example
use rcman::{SettingsConfig, SettingsSchema, SettingMetadata, settings};
use serde::{Serialize, Deserialize};
use std::collections::HashMap;

#[derive(Default, Serialize, Deserialize)]
struct AppSettings {
    theme: String,
    font_size: f64,
}

impl SettingsSchema for AppSettings {
    fn get_metadata() -> HashMap<String, SettingMetadata> {
        settings! {
            "ui.theme" => SettingMetadata::text("dark").meta_str("label", "Theme"),
            "ui.font_size" => SettingMetadata::number(14.0).meta_str("label", "Font Size")
        }
    }
}

let config = SettingsConfig::builder("my-app", "1.0.0")
    .with_schema::<AppSettings>()  // Bind the schema
    .build();
Source

pub fn with_storage<NewS: StorageBackend + Default>( self, ) -> SettingsConfigBuilder<NewS, Schema>

Specify the storage backend type.

This transforms the builder to use the specified storage backend. The settings filename will automatically be updated to match the format.

§Example
use rcman::{SettingsConfig, JsonStorage};

let config = SettingsConfig::builder("my-app", "1.0.0")
    .with_storage::<JsonStorage>()
    .build();
Source

pub fn build(self) -> SettingsConfig<S, Schema>
where S: Default,

Build the SettingsConfig

If config_dir is not set, uses the system config directory for the app.

Trait Implementations§

Source§

impl<S: Clone + StorageBackend, Schema: Clone + SettingsSchema> Clone for SettingsConfigBuilder<S, Schema>

Source§

fn clone(&self) -> SettingsConfigBuilder<S, Schema>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: StorageBackend, Schema: SettingsSchema> Debug for SettingsConfigBuilder<S, Schema>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, Schema> Freeze for SettingsConfigBuilder<S, Schema>

§

impl<S = JsonStorage, Schema = ()> !RefUnwindSafe for SettingsConfigBuilder<S, Schema>

§

impl<S, Schema> Send for SettingsConfigBuilder<S, Schema>
where Schema: Send,

§

impl<S, Schema> Sync for SettingsConfigBuilder<S, Schema>
where Schema: Sync,

§

impl<S, Schema> Unpin for SettingsConfigBuilder<S, Schema>
where Schema: Unpin, S: Unpin,

§

impl<S, Schema> UnsafeUnpin for SettingsConfigBuilder<S, Schema>

§

impl<S = JsonStorage, Schema = ()> !UnwindSafe for SettingsConfigBuilder<S, Schema>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Fruit for T
where T: Send + Downcast,