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
51
52
use std::{
    path::{Path, PathBuf},
    sync::Arc,
};

use indexmap::IndexMap;
use parking_lot::Mutex;

use crate::{IncludeAdaptor, VarsStack, WildDocValue};

pub struct WildDocState {
    stack: Mutex<VarsStack>,
    global: Mutex<IndexMap<String, WildDocValue>>,
    cache_dir: PathBuf,
    include_adaptor: Arc<Mutex<Box<dyn IncludeAdaptor + Send>>>,
}

impl WildDocState {
    pub fn new(
        initial_stack: VarsStack,
        global: Mutex<IndexMap<String, WildDocValue>>,
        cache_dir: PathBuf,
        include_adaptor: Arc<Mutex<Box<dyn IncludeAdaptor + Send>>>,
    ) -> Self {
        Self {
            stack: Mutex::new(initial_stack),
            global,
            cache_dir,
            include_adaptor,
        }
    }

    #[inline(always)]
    pub fn cache_dir(&self) -> &Path {
        &self.cache_dir
    }

    #[inline(always)]
    pub fn stack(&self) -> &Mutex<VarsStack> {
        &self.stack
    }

    #[inline(always)]
    pub fn global(&self) -> &Mutex<IndexMap<String, WildDocValue>> {
        &self.global
    }

    #[inline(always)]
    pub fn include_adaptor(&self) -> &Mutex<Box<dyn IncludeAdaptor + Send>> {
        &self.include_adaptor
    }
}