use crate::{application::Application, component, thread};
use std::sync::RwLock;
const MUTEX_ERR_MSG: &str = "error acquiring mutex";
#[derive(Debug, Default)]
pub struct State<A: Application + 'static> {
components: RwLock<component::Registry<A>>,
paths: A::Paths,
threads: RwLock<thread::Manager>,
}
impl<A> State<A>
where
A: Application + 'static,
{
pub fn components(&self) -> component::registry::Reader<'_, A> {
self.components.read().expect(MUTEX_ERR_MSG)
}
pub fn components_mut(&self) -> component::registry::Writer<'_, A> {
self.components.write().expect(MUTEX_ERR_MSG)
}
pub fn paths(&self) -> &A::Paths {
&self.paths
}
pub fn threads(&self) -> thread::manager::Reader<'_> {
self.threads.read().expect(MUTEX_ERR_MSG)
}
pub fn threads_mut(&self) -> thread::manager::Writer<'_> {
self.threads.write().expect(MUTEX_ERR_MSG)
}
}