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!")
}