[][src]Function spirit::extension::cfg_store

pub fn cfg_store<S, E>(storage: S) -> impl Extension<E> where
    E: Extensible,
    S: Borrow<ArcSwap<E::Config>> + Send + Sync + 'static, 

An extension 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 inside lazy_static or once_cell).

Examples

#[macro_use]
extern crate lazy_static;
extern crate spirit;

use std::sync::Arc;

use arc_swap::ArcSwap;
use spirit::prelude::*;
use spirit::extension;

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(extension::cfg_store(&*CFG))
    .build(false);