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);§Migration from Component-Specific Implementations
All DFE components previously had their own SharedConfig hard-coded to
their specific Config struct. This generic version is a drop-in
replacement:
// Before (component-specific):
use crate::config::SharedConfig; // hard-coded to crate::Config
// After (generic from rustlib):
use hyperi_rustlib::config::SharedConfig; // SharedConfig<Config>
let shared = SharedConfig::new(config); // type inferred from argument§API Compatibility
| Component Method | rustlib Equivalent | Notes |
|---|---|---|
read() | read() | Returns RwLockReadGuard |
get() | get() | Clones current config |
with(f) | with(f) | Closure-based read |
update(cfg) | update(cfg) | Write + version bump + notify |
version() | version() | Atomic version counter |
subscribe() | subscribe() | watch::Receiver<u64> |
clone_inner() | Removed | Use Clone on SharedConfig instead |
Structs§
- Shared
Config - Thread-safe shared configuration with version tracking and change notification.