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
use std::sync::Arc;

use crate::{ContextState, State};

/// Contains information about the extension
pub struct GlobalContext {
    version: String,
    state: Arc<State>,
}

impl GlobalContext {
    pub(crate) fn new(version: String, state: Arc<State>) -> Self {
        Self { version, state }
    }

    #[must_use]
    /// Version of the Arma extension
    pub fn version(&self) -> &str {
        &self.version
    }
}

impl ContextState for GlobalContext {
    fn get<T>(&self) -> Option<&T>
    where
        T: Send + Sync + 'static,
    {
        self.state.try_get()
    }

    fn set<T>(&self, value: T) -> bool
    where
        T: Send + Sync + 'static,
    {
        self.state.set(value)
    }
}