pub fn cfg_store<S, O, C>(storage: S) -> impl Helper<O, C>where
S: Borrow<ArcSwap<C>> + Send + Sync + 'static,
C: DeserializeOwned + Send + Sync + 'static,
O: Debug + StructOpt + Sync + Send + 'static,
Expand description
A helper to store configuration to some global-ish storage.
This makes sure every time a new config is loaded, it is made available inside the passed
parameter. Therefore, places without direct access to the Spirit
itself can look into the
configuration.
The parameter can be a lot of things, but usually:
Arc<ArcSwap<C>>
.- A reference to global
ArcSwap<C>
(for example insidelazy_static
oronce_cell
).
Examples
#[macro_use]
extern crate lazy_static;
extern crate spirit;
use std::sync::Arc;
use spirit::{ArcSwap, Empty, Spirit};
use spirit::helpers;
lazy_static! {
static ref CFG: ArcSwap<Empty> = ArcSwap::from(Arc::new(Empty {}));
}
Spirit::<Empty, Empty>::new()
// Will make sure CFG contains the newest config
.with(helpers::cfg_store(&*CFG))
.build(false);