[−][src]Function spirit::extension::immutable_cfg
pub fn immutable_cfg<Ext, R, E, N>(extractor: E, name: N) -> impl Extension<Ext> where
Ext: Extensible,
E: for<'a> Fn(&'a Ext::Config) -> &R + Send + 'static,
R: Clone + PartialEq + Send + 'static,
N: Display + Send + 'static,
An extension 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
use serde::Deserialize; use spirit::{Empty, Spirit}; use spirit::prelude::*; use spirit::extension; #[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(extension::immutable_cfg(Cfg::msg, "message")) .run(|spirit| { println!("{}", spirit.config().msg); Ok(()) }); }