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
impl ConfigManager
Sourcepub fn load<P: AsRef<Path>>(&self, name: &str, path: P) -> Result<()>
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.
Sourcepub fn get(&self, name: &str) -> Option<Arc<RwLock<Config>>>
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.
Sourcepub fn list(&self) -> Vec<String>
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.
Sourcepub fn remove(&self, name: &str) -> bool
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.