arma_rs/context/
global.rs

1use std::sync::Arc;
2
3use crate::{ContextState, State};
4
5/// Contains information about the extension
6pub struct GlobalContext {
7    version: String,
8    state: Arc<State>,
9}
10
11impl GlobalContext {
12    pub(crate) fn new(version: String, state: Arc<State>) -> Self {
13        Self { version, state }
14    }
15
16    #[must_use]
17    /// Version of the Arma extension
18    pub fn version(&self) -> &str {
19        &self.version
20    }
21}
22
23impl ContextState for GlobalContext {
24    fn get<T>(&self) -> Option<&T>
25    where
26        T: Send + Sync + 'static,
27    {
28        self.state.try_get()
29    }
30
31    fn set<T>(&self, value: T) -> bool
32    where
33        T: Send + Sync + 'static,
34    {
35        self.state.set(value)
36    }
37}