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
42
43
44
45
46
47
48
49
50
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)
}
}