pub struct Config<D: ConfigDefault> { /* private fields */ }Expand description
A handle to a dynamically updatable configuration value.
This represents a strongly-typed named config of type T. It may be
registered to a set of such configs with ConfigSet::add and then later
used to retrieve the latest value at any time with Self::get.
The supported types are bool, usize, Duration, and String, as well as Option variants of these as necessary.
Implementations§
Source§impl<D: ConfigDefault> Config<D>
impl<D: ConfigDefault> Config<D>
Sourcepub const fn new(name: &'static str, default: D, desc: &'static str) -> Self
pub const fn new(name: &'static str, default: D, desc: &'static str) -> Self
Constructs a handle for a config of type T.
It is best practice, but not strictly required, for the name to be globally unique within a process.
TODO(cfg): Add some sort of categorization of config purpose here: e.g.
limited-lifetime rollout flag, CYA, magic number that we never expect to
tune, magic number that we DO expect to tune, etc. This could be used to
power something like a --future-default-flags for CI, to replace part
or all of the manually maintained list.
TODO(cfg): See if we can make this more Rust-y and take these params as a struct (the obvious thing hits some issues with const combined with Drop).
Sourcepub const fn scoped(self, scope: ParameterScope) -> Self
pub const fn scoped(self, scope: ParameterScope) -> Self
Declares the ParameterScope of this config, overriding the
default.
Use this to mark a config as cluster-coherent or replica-local so the LaunchDarkly sync loop evaluates the appropriate scoped contexts and resolution applies the override at the right boundary.
Sourcepub fn scope(&self) -> ParameterScope
pub fn scope(&self) -> ParameterScope
The ParameterScope of this config.
Sourcepub fn get(&self, set: &ConfigSet) -> D::ConfigType
pub fn get(&self, set: &ConfigSet) -> D::ConfigType
Returns the latest value of this config within the given set.
Panics if this config was not previously registered to the set.
TODO(cfg): Decide if this should be a method on ConfigSet instead to
match the precedent of BTreeMap/HashMap::get taking a key. It’s like
this initially because it was thought that the Config definition was
the more important “noun” and also that rustfmt would maybe work better
on this ordering.
Sourcepub fn handle(&self, set: &ConfigSet) -> ConfigValHandle<D::ConfigType>
pub fn handle(&self, set: &ConfigSet) -> ConfigValHandle<D::ConfigType>
Returns a handle to the value of this config in the given set.
This allows users to amortize the cost of the name lookup.