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 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.
Trait Implementations§
Auto Trait Implementations§
impl<D> Freeze for Config<D>where
D: Freeze,
impl<D> RefUnwindSafe for Config<D>where
D: RefUnwindSafe,
impl<D> Send for Config<D>where
D: Send,
impl<D> Sync for Config<D>where
D: Sync,
impl<D> Unpin for Config<D>where
D: Unpin,
impl<D> UnwindSafe for Config<D>where
D: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
RustType::from_proto
.source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
RustType::into_proto
.