Skip to main content

ConfigManager

Struct ConfigManager 

Source
pub struct ConfigManager { /* private fields */ }
Expand description

Configuration manager for multiple named instances.

ConfigManager is the multi-instance primitive: each Config it holds is identified by a name, accessible by name through ConfigManager::get, and shared across threads via Arc<RwLock<Config>>. The typical use case is a runtime that maintains several independent configurations within one process — for example, one per database, one per service, plus a global — and wants to load and look them up by name.

History. Through v0.9.4 – v0.9.8 this type was marked #[deprecated] because its get method was scheduled to change return type when Config absorbed the cached/thread-safe surface of EnterpriseConfig. That migration landed in v0.9.9, the deprecation has therefore been cleared, and ConfigManager is part of the stable v1.0 contract.

Implementations§

Source§

impl ConfigManager

Source

pub fn new() -> Self

Create a new empty config manager.

Source

pub fn load<P: AsRef<Path>>(&self, name: &str, path: P) -> Result<()>

Load a named configuration from a file.

Inserts (or replaces) the entry under name. Subsequent calls to ConfigManager::get with the same name return an Arc<RwLock<Config>> referencing the loaded configuration.

§Errors

Returns an error if the file cannot be read or parsed, or if the internal map lock is poisoned.

Source

pub fn get(&self, name: &str) -> Option<Arc<RwLock<Config>>>

Get a handle to a named configuration.

Returns Some(Arc<RwLock<Config>>) if a configuration was previously loaded under name, None otherwise. Multiple callers of get(name) share the same underlying Config — writes through one handle are visible to all the others.

Source

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

List the names of all currently-loaded configurations.

Returns an empty Vec if the internal map lock is poisoned.

Source

pub fn remove(&self, name: &str) -> bool

Remove a named configuration.

Returns true if an entry was removed, false if no entry existed under name or if the internal map lock is poisoned. Other callers still holding an Arc<RwLock<Config>> from a previous get continue to see the configuration; only the name-to-config mapping is removed.

Trait Implementations§

Source§

impl Debug for ConfigManager

Source§

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

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

impl Default for ConfigManager

Source§

fn default() -> ConfigManager

Returns the “default value” for a type. Read more

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> 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, 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.