abscissa_core/application/
state.rs1use crate::{application::Application, component, thread};
4use std::sync::RwLock;
5
6const MUTEX_ERR_MSG: &str = "error acquiring mutex";
8
9#[derive(Debug, Default)]
11pub struct State<A: Application + 'static> {
12 components: RwLock<component::Registry<A>>,
14
15 paths: A::Paths,
17
18 threads: RwLock<thread::Manager>,
20}
21
22impl<A> State<A>
23where
24 A: Application + 'static,
25{
26 pub fn components(&self) -> component::registry::Reader<'_, A> {
28 self.components.read().expect(MUTEX_ERR_MSG)
29 }
30
31 pub fn components_mut(&self) -> component::registry::Writer<'_, A> {
33 self.components.write().expect(MUTEX_ERR_MSG)
34 }
35
36 pub fn paths(&self) -> &A::Paths {
38 &self.paths
39 }
40
41 pub fn threads(&self) -> thread::manager::Reader<'_> {
43 self.threads.read().expect(MUTEX_ERR_MSG)
44 }
45
46 pub fn threads_mut(&self) -> thread::manager::Writer<'_> {
48 self.threads.write().expect(MUTEX_ERR_MSG)
49 }
50}