pub struct HotConfig { /* private fields */ }Expand description
Hot-reloadable configuration object.
Internally holds an Arc<RwLock<ConfigSnapshot>> and a
[watch::Sender<u64>] channel. Call start_watcher
to spawn a background Tokio task that polls the file for mtime changes.
Implementations§
Source§impl HotConfig
impl HotConfig
Sourcepub fn new(path: &str, poll_interval: Duration) -> Self
pub fn new(path: &str, poll_interval: Duration) -> Self
Create a HotConfig backed by a file path.
The file is loaded immediately. If loading fails the config starts with an empty snapshot (version 0).
Sourcepub fn from_defaults() -> Self
pub fn from_defaults() -> Self
Create an in-memory HotConfig with no backing file.
Useful for tests and programmatic configuration.
Sourcepub fn set(&self, key: &str, value: ConfigValue)
pub fn set(&self, key: &str, value: ConfigValue)
Programmatically set a key/value in the current snapshot.
Increments the version counter and notifies all subscribers.
Sourcepub fn get(&self, key: &str) -> Option<ConfigValue>
pub fn get(&self, key: &str) -> Option<ConfigValue>
Read the value for key from the current snapshot.
Sourcepub fn get_or_default<T: FromConfigValue>(&self, key: &str, default: T) -> T
pub fn get_or_default<T: FromConfigValue>(&self, key: &str, default: T) -> T
Read key, coerce it to T, or return default on miss/type error.
Sourcepub fn subscribe(&self) -> Receiver<u64>
pub fn subscribe(&self) -> Receiver<u64>
Subscribe to version-change notifications.
The receiver yields the new version number each time the config is
reloaded (or set is called).
Sourcepub fn start_watcher(&self) -> JoinHandle<()>
pub fn start_watcher(&self) -> JoinHandle<()>
Spawn a background Tokio task that polls the backing file for changes.
Returns a [tokio::task::JoinHandle] that the caller can abort or
await. If no file path was configured (e.g. created via
from_defaults), the spawned task exits
immediately.
Auto Trait Implementations§
impl !RefUnwindSafe for HotConfig
impl !UnwindSafe for HotConfig
impl Freeze for HotConfig
impl Send for HotConfig
impl Sync for HotConfig
impl Unpin for HotConfig
impl UnsafeUnpin for HotConfig
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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