Function spirit::helpers::immutable_cfg
source · pub fn immutable_cfg<O, C, R, E, N>(extractor: E, name: N) -> impl Helper<O, C>where
E: for<'a> Fn(&'a C) -> &R + Send + 'static,
R: Clone + PartialEq + Send + 'static,
C: DeserializeOwned + Send + Sync + 'static,
O: Debug + StructOpt + Sync + Send + 'static,
N: Display + Send + 'static,
Expand description
A helper to warn about changes to configuration that can’t be updated at runtime.
This is similar to immutable_cfg_init
, except that there’s no
callback called at the first load.
Examples
#[macro_use]
extern crate serde_derive;
extern crate spirit;
use spirit::{Empty, Spirit};
use spirit::helpers;
#[derive(Clone, Debug, Default, Deserialize)]
struct Cfg {
#[serde(default)]
msg: String,
}
impl Cfg {
fn msg(&self) -> &String {
&self.msg
}
}
fn main() {
Spirit::<Empty, Cfg>::new()
// This prints a warning if the message is ever changed during runtime ‒ we can't take
// it back and change it after it got printed in the body.
.with(helpers::immutable_cfg(Cfg::msg, "message"))
.run(|spirit| {
println!("{}", spirit.config().msg);
Ok(())
});
}