1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use super::{Config, Reader};
use arc_swap::ArcSwapOption;
use std::sync::Arc;
#[derive(Debug, Default)]
pub struct CfgCell<C: Config> {
inner: ArcSwapOption<C>,
}
impl<C> CfgCell<C>
where
C: Config,
{
pub fn set_once(&self, config: C) {
let old_config = self.inner.swap(Some(Arc::new(config)));
if old_config.is_some() {
panic!("can't reload Abscissa application config (yet)!");
}
}
pub fn read(&self) -> Reader<C> {
self.inner.load_full().unwrap_or_else(|| not_loaded())
}
}
fn not_loaded() -> ! {
panic!("Abscissa application state accessed before it has been initialized!")
}