pub struct Config { /* private fields */ }Expand description
NEST-21: a service’s configuration — a capability handle, cheap to clone; every clone is the same store.
Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Self
pub fn new() -> Self
A store kept in memory, with plexus-core’s own settings declared
([settings::declare_core]).
Sourcepub fn with_file(file: impl AsRef<Path>) -> Result<Self, String>
pub fn with_file(file: impl AsRef<Path>) -> Result<Self, String>
A store kept in file (JSON, { "key": value }, 0600): read now —
its values the file layer of each key, as it is declared — and
written at every runtime set and reset. A missing file is an empty
one.
Sourcepub fn with_audit(self, sink: Arc<dyn ConfigAudit>) -> Self
pub fn with_audit(self, sink: Arc<dyn ConfigAudit>) -> Self
Also record to sink.
Sourcepub fn add_audit(&self, sink: Arc<dyn ConfigAudit>)
pub fn add_audit(&self, sink: Arc<dyn ConfigAudit>)
Also record to sink (on a shared handle).
Sourcepub fn declare<T: SettingValue>(&self, s: &Setting<T>)
pub fn declare<T: SettingValue>(&self, s: &Setting<T>)
Declare s here (once; again is nothing). A key declared with
another type, or not a key, is refused, said loudly, and the first
declaration kept.
Sourcepub fn try_declare<T: SettingValue>(&self, s: &Setting<T>) -> Result<(), String>
pub fn try_declare<T: SettingValue>(&self, s: &Setting<T>) -> Result<(), String>
Config::declare, saying why not.
Sourcepub fn get<T: SettingValue>(&self, s: &Setting<T>) -> T
pub fn get<T: SettingValue>(&self, s: &Setting<T>) -> T
What s is now (its default if its stored value no longer fits).
Sourcepub fn source<T: SettingValue>(&self, s: &Setting<T>) -> Source
pub fn source<T: SettingValue>(&self, s: &Setting<T>) -> Source
Where s’s value in effect comes from.
Sourcepub fn set<T: SettingValue>(
&self,
s: &Setting<T>,
value: T,
) -> Result<Previous<T>, ConfigError>
pub fn set<T: SettingValue>( &self, s: &Setting<T>, value: T, ) -> Result<Previous<T>, ConfigError>
Set s at runtime, as the running call’s caller (or the host).
Sourcepub fn seed<T: SettingValue>(
&self,
s: &Setting<T>,
source: Source,
value: Option<T>,
)
pub fn seed<T: SettingValue>( &self, s: &Setting<T>, source: Source, value: Option<T>, )
Give s a value from below the runtime: the file’s or a flag’s —
what the host read at start. None takes it away.
Sourcepub fn reset<T: SettingValue>(&self, s: &Setting<T>) -> Result<T, ConfigError>
pub fn reset<T: SettingValue>(&self, s: &Setting<T>) -> Result<T, ConfigError>
Back to below the runtime (the flag’s, the file’s, the default), as the running call’s caller.
Sourcepub fn watch<T: SettingValue>(&self, s: &Setting<T>) -> Watch<T>
pub fn watch<T: SettingValue>(&self, s: &Setting<T>) -> Watch<T>
Watch s: its value now, and every change to what is in effect.
Sourcepub fn on_change<T: SettingValue>(
&self,
s: &Setting<T>,
f: impl Fn(T) + Send + Sync + 'static,
)
pub fn on_change<T: SettingValue>( &self, s: &Setting<T>, f: impl Fn(T) + Send + Sync + 'static, )
Call f with s’s value now and at every change of it — inside the
set that made it, after the store is unlocked. For a subsystem whose
state follows a setting (the redactor’s keys).
Sourcepub fn changes(&self) -> Receiver<ConfigChange>
pub fn changes(&self) -> Receiver<ConfigChange>
Every change, as it is made.
Sourcepub fn flags(&self, key: &str) -> Option<(bool, bool)>
pub fn flags(&self, key: &str) -> Option<(bool, bool)>
The facts the config activation decides on: (remote, critical).
Sourcepub fn set_value(
&self,
key: &str,
value: Value,
confirm_within: Option<Duration>,
actor: Actor,
) -> Result<(Value, Source), ConfigError>
pub fn set_value( &self, key: &str, value: Value, confirm_within: Option<Duration>, actor: Actor, ) -> Result<(Value, Source), ConfigError>
The untyped set the config activation makes: value checked
against the key’s type, applied, stored, audited, said; with
confirm_within, reverted unless Config::confirm comes in time.
Answers the value in effect before and where it came from.
Sourcepub fn reset_key(&self, key: &str, actor: Actor) -> Result<(), ConfigError>
pub fn reset_key(&self, key: &str, actor: Actor) -> Result<(), ConfigError>
Take a key’s runtime value away, as actor.