multiversx_chain_scenario_format/
interpret_trait.rs

1use std::path::PathBuf;
2
3use crate::value_interpreter::VMIdentifier;
4
5#[derive(Default, Clone, Debug)]
6pub struct InterpreterContext {
7    pub context_path: PathBuf,
8    pub vm_type: VMIdentifier,
9    pub allow_missing_files: bool,
10}
11
12impl InterpreterContext {
13    pub fn new() -> Self {
14        InterpreterContext::default()
15    }
16
17    pub fn with_dir(self, context_path: PathBuf) -> Self {
18        InterpreterContext {
19            context_path,
20            ..self
21        }
22    }
23
24    pub fn with_allowed_missing_files(self) -> Self {
25        InterpreterContext {
26            allow_missing_files: true,
27            ..self
28        }
29    }
30}
31
32pub trait InterpretableFrom<T> {
33    fn interpret_from(from: T, context: &InterpreterContext) -> Self;
34}
35
36impl<T> InterpretableFrom<T> for T {
37    fn interpret_from(from: T, _context: &InterpreterContext) -> Self {
38        from
39    }
40}
41
42impl<T: Clone> InterpretableFrom<&T> for T {
43    fn interpret_from(from: &T, _context: &InterpreterContext) -> Self {
44        from.clone()
45    }
46}
47
48pub trait IntoRaw<R> {
49    fn into_raw(self) -> R;
50}