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 std::path::PathBuf;

use crate::value_interpreter::VMIdentifier;

#[derive(Default, Clone)]
pub struct InterpreterContext {
    pub context_path: PathBuf,
    pub vm_type: VMIdentifier,
    pub allow_missing_files: bool,
}

impl InterpreterContext {
    pub fn new() -> Self {
        InterpreterContext::default()
    }

    pub fn with_dir(self, context_path: PathBuf) -> Self {
        InterpreterContext {
            context_path,
            ..self
        }
    }

    pub fn with_allowed_missing_files(self) -> Self {
        InterpreterContext {
            allow_missing_files: true,
            ..self
        }
    }
}

pub trait InterpretableFrom<T> {
    fn interpret_from(from: T, context: &InterpreterContext) -> Self;
}

impl<T> InterpretableFrom<T> for T {
    fn interpret_from(from: T, _context: &InterpreterContext) -> Self {
        from
    }
}

impl<T: Clone> InterpretableFrom<&T> for T {
    fn interpret_from(from: &T, _context: &InterpreterContext) -> Self {
        from.clone()
    }
}

pub trait IntoRaw<R> {
    fn into_raw(self) -> R;
}