ConfigScope

Enum ConfigScope 

Source
pub enum ConfigScope {
    Preferences,
    UserGlobal,
    ProjectLocal,
    LocalData,
    PersistentData,
    Runtime,
}
Expand description

Configuration scope representing different layers of configuration sources.

The scope system allows applications to organize configuration across multiple layers with clear precedence: defaults → user prefs → global config → project config → local data → persistent data → runtime overrides.

§Scopes

  • Preferences: User application preferences (via BaseDirs::preference_dir())
  • UserGlobal: User configuration applying across all projects (via ProjectDirs::config_dir())
  • ProjectLocal: Project-specific configuration (current directory)
  • LocalData: Machine-local data not synced across machines (via BaseDirs::data_local_dir())
  • PersistentData: Cross-machine persistent application state (via BaseDirs::data_dir())
  • Runtime: Dynamic configuration from environment variables and CLI (not file-based)

§Precedence Order

When using MultiScopeConfig, scopes are typically loaded in this order:

  1. Preferences
  2. UserGlobal
  3. ProjectLocal
  4. LocalData
  5. PersistentData
  6. Runtime (env vars + CLI, handled separately)

Later scopes override earlier ones during configuration merging.

§Example

use settings_loader::ConfigScope;

let scopes = vec![
    ConfigScope::Preferences,
    ConfigScope::UserGlobal,
    ConfigScope::ProjectLocal,
];

// Use in collections
let mut scope_map = std::collections::HashMap::new();
scope_map.insert(ConfigScope::Preferences, "user prefs");

Variants§

§

Preferences

User application preferences

Platform-specific locations:

  • Linux: ~/.config/APP_NAME (or XDG_CONFIG_HOME/APP_NAME)
  • macOS: ~/Library/Preferences/APP_NAME
  • Windows: %APPDATA%/APP_NAME
§

UserGlobal

User configuration applying across all projects

Platform-specific locations:

  • Linux: ~/.config/APP_NAME (or XDG_CONFIG_HOME/APP_NAME)
  • macOS: ~/Library/Application Support/ORG_NAME.APP_NAME
  • Windows: %APPDATA%/ORG_NAME/APP_NAME
§

ProjectLocal

Project-specific configuration in current directory

Location: ./settings.{ext} (any supported format) Searchable with find_config_in().

§

LocalData

Machine-local data not synced across machines

Platform-specific locations:

  • Linux: ~/.cache/APP_NAME (or XDG_CACHE_HOME/APP_NAME)
  • macOS: ~/Library/Caches/ORG_NAME.APP_NAME
  • Windows: %LOCALAPPDATA%/ORG_NAME/APP_NAME

Use for ephemeral data, caches, runtime state.

§

PersistentData

Cross-machine persistent application state

Platform-specific locations:

  • Linux: ~/.local/share/APP_NAME (or XDG_DATA_HOME/APP_NAME)
  • macOS: ~/Library/Application Support/ORG_NAME.APP_NAME
  • Windows: %APPDATA%/ORG_NAME/APP_NAME

Use for persistent data that should sync across machines.

§

Runtime

Dynamic configuration from environment variables and CLI

Not file-based. Resolved separately via environment variables and command-line arguments. resolve_path() returns None for this scope.

Implementations§

Source§

impl ConfigScope

Source

pub fn name(self) -> &'static str

Returns a human-readable name for this scope

§Example
assert_eq!(ConfigScope::Preferences.name(), "Preferences");
assert_eq!(ConfigScope::UserGlobal.name(), "UserGlobal");
Source

pub fn is_file_based(self) -> bool

Returns true if this scope is file-based

Returns false for Runtime scope which is handled via env vars + CLI.

§Example
assert!(ConfigScope::Preferences.is_file_based());
assert!(!ConfigScope::Runtime.is_file_based());

Trait Implementations§

Source§

impl Clone for ConfigScope

Source§

fn clone(&self) -> ConfigScope

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ConfigScope

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ConfigScope

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for ConfigScope

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ConfigScope

Source§

fn eq(&self, other: &ConfigScope) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ConfigScope

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for ConfigScope

Source§

impl Eq for ConfigScope

Source§

impl StructuralPartialEq for ConfigScope

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
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> 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> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,