pub struct SharedCfg(/* private fields */);Expand description
An immutable collection of typed configuration values.
Implementations§
Sourcepub fn new(tag: &'static str) -> SharedCfgBuilder
pub fn new(tag: &'static str) -> SharedCfgBuilder
Starts building a shared configuration with the given tag.
Sourcepub fn get<T>(&self) -> Cfg<T>where
T: Configuration,
pub fn get<T>(&self) -> Cfg<T>where
T: Configuration,
Returns the configuration value of type T, or its default.
A value added with SharedCfgBuilder::add is the same instance on
every thread. When T was not added, the first lookup on a thread
creates T::default(), logs it at info level, and caches it for this
shared configuration on that thread. Later lookups on the same thread,
including through CfgContext::get and Cfg::get_shared, return
the cached value; other threads create their own.
A missing value is not an error, and the returned handle does not show
whether the value was added or defaulted. Framework components rely on
this to fall back to their defaults. Add configuration your application
requires explicitly, and validate it where you build the
SharedCfg.
§Panics
A panic in T::default() or Configuration::set_ctx while creating
the default propagates to the caller, and nothing is cached.