summaryrefslogtreecommitdiff
path: root/src/context.rs
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2026-06-14 07:09:59 -0700
committerMike Buland <mike@xagasoft.com>2026-06-14 07:09:59 -0700
commit68745e87a73ed7cfa305ee5319b85aeef85eb088 (patch)
tree0a18f2543571dd095eacf06c4c7141b6e22093f1 /src/context.rs
parent038884232b6efbabb414cb011fa0fc4e3b4c8fd6 (diff)
downloadcrimtag-68745e87a73ed7cfa305ee5319b85aeef85eb088.tar.gz
crimtag-68745e87a73ed7cfa305ee5319b85aeef85eb088.tar.bz2
crimtag-68745e87a73ed7cfa305ee5319b85aeef85eb088.tar.xz
crimtag-68745e87a73ed7cfa305ee5319b85aeef85eb088.zip
In progress...
Diffstat (limited to 'src/context.rs')
-rw-r--r--src/context.rs46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/context.rs b/src/context.rs
index d322411..2f12ea9 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -6,7 +6,10 @@ pub type Context = HashMap<String,Value>;
6 6
7pub trait MappedStructure { 7pub trait MappedStructure {
8 fn get_value(&self, id: &[IdentifierValue]) -> Option<Value>; 8 fn get_value(&self, id: &[IdentifierValue]) -> Option<Value>;
9 9 fn get_iterable<T>(&self, id: &[IdentifierValue]) -> Option<T>
10 where
11 T: IntoIterator,
12 T::Item: MappedStructure;
10} 13}
11 14
12impl MappedStructure for Context { 15impl MappedStructure for Context {
@@ -36,6 +39,40 @@ impl MappedStructure for Context {
36 39
37 return cur_val.cloned(); 40 return cur_val.cloned();
38 } 41 }
42
43 fn get_iter<T>(&self, id: &[IdentifierValue]) -> Option<T>
44 where
45 T: IntoIterator,
46 T::Item: MappedStructure, {
47 if id.len() == 0 {
48 return None;
49 }
50 let mut cur_val : Option<&Value> = if let IdentifierValue::Name(s) = &id[0] {
51 self.get(s)
52 } else {
53 return None;
54 };
55 if cur_val.is_none() {
56 return None;
57 }
58
59 for idx in 1..id.len() {
60 if let IdentifierValue::Name(s) = &id[idx] &&
61 let Some(Value::Dictionary(d)) = &cur_val {
62 cur_val.replace( if let Some(v) = d.get(s) {
63 v
64 } else {
65 return None;
66 });
67 }
68 }
69
70 if let Some(Value::List(l)) = cur_val {
71 return l.into
72 }
73
74 return cur_val.cloned();
75 }
39} 76}
40 77
41pub struct StatefulContext<'a, T: MappedStructure> { 78pub struct StatefulContext<'a, T: MappedStructure> {
@@ -75,6 +112,13 @@ impl<'a, T: MappedStructure> MappedStructure for StatefulContext<'a,T> {
75 self.local.get_value( id ) 112 self.local.get_value( id )
76 } 113 }
77 } 114 }
115
116 fn get_iter<U>(&self, id: &[IdentifierValue]) -> Option<U>
117 where
118 U: IntoIterator,
119 U::Item: MappedStructure, {
120 None
121 }
78} 122}
79 123
80#[derive(Debug,Clone)] 124#[derive(Debug,Clone)]