[][src]Function spirit_cfg_helpers::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

use arc_swap::ArcSwap;
use once_cell::sync::Lazy;
use spirit::{Empty, Spirit};
use spirit::prelude::*;

static CFG: Lazy<ArcSwap<Empty>> = Lazy::new(Default::default);

Spirit::<Empty, Empty>::new()
    // Will make sure CFG contains the newest config
    .with(spirit_cfg_helpers::cfg_store(&*CFG))
    .build(false);