summaryrefslogtreecommitdiff
path: root/src/context.rs
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2026-06-22 09:22:25 -0700
committerMike Buland <mike@xagasoft.com>2026-06-22 09:22:25 -0700
commit5eedc8e9080afe1d7fa00d9577343fe5aa25a93d (patch)
tree4f1b1fb7a7dad482af54b1d07e5252d7f85ed313 /src/context.rs
parentdd2f66f2fe7ee687d8c0b7ca6e60ef7221223fb2 (diff)
downloadcrimtag-5eedc8e9080afe1d7fa00d9577343fe5aa25a93d.tar.gz
crimtag-5eedc8e9080afe1d7fa00d9577343fe5aa25a93d.tar.bz2
crimtag-5eedc8e9080afe1d7fa00d9577343fe5aa25a93d.tar.xz
crimtag-5eedc8e9080afe1d7fa00d9577343fe5aa25a93d.zip
Attempted fixes. Maybe made it too C++ish
Diffstat (limited to 'src/context.rs')
-rw-r--r--src/context.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/context.rs b/src/context.rs
index 4501a0a..0b51677 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -40,6 +40,33 @@ impl<'a> MappedList<'a> for Vec<Value> {
40 } 40 }
41} 41}
42 42
43impl<'a> MappedList<'a> for Vec<MappedValue<'a>> {
44 fn get_index(&'a self, id: usize) -> Option<MappedValue<'a>> {
45 if let Some(x) = self.get(id) {
46 Some(*x)
47 } else {
48 None
49 }
50 }
51
52 fn for_each(&'a self, func: &dyn Fn(&MappedValue<'a>, &mut String) -> CrimResult<()>) -> CrimResult<String> {
53 let mut buf = String::new();
54 for i in self {
55 func( i, &mut buf )?;
56 }
57 Ok(buf)
58 }
59}
60
61pub type MappedHash<'a> = HashMap<String, MappedValue<'a>>;
62
63impl<'a> MappedStructure<'a> for MappedHash<'a> {
64 fn get_value(&'a self, id: &str) -> Option<MappedValue<'a>> {
65 self.get(id).copied()
66 }
67}
68
69#[derive(Copy,Clone)]
43pub enum MappedValue<'a> { 70pub enum MappedValue<'a> {
44 Struct(&'a dyn MappedStructure<'a>), 71 Struct(&'a dyn MappedStructure<'a>),
45 List(&'a dyn MappedList<'a>), 72 List(&'a dyn MappedList<'a>),