diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/handlebars/src/local_vars.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/handlebars/src/local_vars.rs')
-rw-r--r-- | vendor/handlebars/src/local_vars.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/vendor/handlebars/src/local_vars.rs b/vendor/handlebars/src/local_vars.rs new file mode 100644 index 000000000..2a34b1f16 --- /dev/null +++ b/vendor/handlebars/src/local_vars.rs @@ -0,0 +1,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), + } + } +} |