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::Application;
use std::{ops::Deref, sync::RwLockReadGuard};
pub(crate) type Guard<T> = RwLockReadGuard<'static, Option<T>>;
pub struct Reader<A>(Guard<A>)
where
A: 'static + Application;
impl<A> Reader<A>
where
A: 'static + Application,
{
pub(super) fn new(guard: Guard<A>) -> Self {
Reader(guard)
}
}
impl<A> Deref for Reader<A>
where
A: 'static + Application,
{
type Target = A;
fn deref(&self) -> &A {
self.0.deref().as_ref().unwrap_or_else(|| not_loaded())
}
}
fn not_loaded() -> ! {
panic!("Abscissa application state accessed before it has been initialized!")
}