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::collections::BTreeMap;
use serde_json::value::Value as Json;
#[derive(Default, Debug, Clone)]
pub(crate) struct LocalVars {
first: Option<Json>,
last: Option<Json>,
index: Option<Json>,
key: Option<Json>,
extra: BTreeMap<String, Json>,
}
impl LocalVars {
pub fn put(&mut self, key: &str, value: Json) {
match key {
"first" => self.first = Some(value),
"last" => self.last = Some(value),
"index" => self.index = Some(value),
"key" => self.key = Some(value),
_ => {
self.extra.insert(key.to_owned(), value);
}
}
}
pub fn get(&self, key: &str) -> Option<&Json> {
match key {
"first" => self.first.as_ref(),
"last" => self.last.as_ref(),
"index" => self.index.as_ref(),
"key" => self.key.as_ref(),
_ => self.extra.get(key),
}
}
}
|