Available on crate features
config-reload and config only.Expand description
Generic thread-safe shared configuration with version tracking.
SharedConfig<T> wraps any config struct in an Arc<RwLock<T>> with a
monotonic version counter and a tokio watch channel for subscriber
notifications. This is the universal building block for hot-reload across
all DFE components (loader, receiver, archiver).
§Usage
use hyperi_rustlib::config::shared::SharedConfig;
#[derive(Clone, Debug, Default)]
struct AppConfig {
pub buffer_size: usize,
pub log_level: String,
}
// Create shared config
let shared = SharedConfig::new(AppConfig {
buffer_size: 1024,
log_level: "info".into(),
});
// Read config (zero-copy via read guard)
{
let cfg = shared.read();
assert_eq!(cfg.buffer_size, 1024);
}
// Subscribe to changes
let mut rx = shared.subscribe();
// Update config (notifies all subscribers)
let mut new_cfg = shared.get();
new_cfg.buffer_size = 2048;
shared.update(new_cfg);
assert_eq!(shared.version(), 1);
assert_eq!(*rx.borrow(), 1);Drop-in replacement for the per-component SharedConfig structs DFE
components used to hard-code to their own Config. Same method names
(read/get/with/update/version/subscribe); type is inferred
from the argument. The old clone_inner() is gone – clone the
SharedConfig itself.
Structs§
- Shared
Config - Thread-safe shared configuration with version tracking and change notification.