summaryrefslogtreecommitdiff
path: root/src/context.rs
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2026-06-23 08:50:28 -0700
committerMike Buland <mike@xagasoft.com>2026-06-23 08:50:28 -0700
commit0c1429fd7e6e1432e480e59ffc5b0e86588cd26e (patch)
tree3f321764097f248f400f96347abd42d33d054541 /src/context.rs
parent5eedc8e9080afe1d7fa00d9577343fe5aa25a93d (diff)
downloadcrimtag-0c1429fd7e6e1432e480e59ffc5b0e86588cd26e.tar.gz
crimtag-0c1429fd7e6e1432e480e59ffc5b0e86588cd26e.tar.bz2
crimtag-0c1429fd7e6e1432e480e59ffc5b0e86588cd26e.tar.xz
crimtag-0c1429fd7e6e1432e480e59ffc5b0e86588cd26e.zip
Tweaked for generality.
Diffstat (limited to 'src/context.rs')
-rw-r--r--src/context.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/context.rs b/src/context.rs
index 0b51677..6f8e04f 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -21,6 +21,24 @@ pub trait MappedList<'a> {
21 fn get_index(&'a self, id: usize) -> Option<MappedValue<'a>>; 21 fn get_index(&'a self, id: usize) -> Option<MappedValue<'a>>;
22 fn for_each(&'a self, func: &dyn Fn(&MappedValue<'a>, &mut String) -> CrimResult<()>) -> CrimResult<String>; 22 fn for_each(&'a self, func: &dyn Fn(&MappedValue<'a>, &mut String) -> CrimResult<()>) -> CrimResult<String>;
23} 23}
24
25impl<'a, T: MappedStructure<'a>> MappedList<'a> for Vec<T> {
26 fn get_index(&'a self, id: usize) -> Option<MappedValue<'a>> {
27 if let Some(x) = self.get(id) {
28 Some(MappedValue::<'a>::Struct(x))
29 } else {
30 None
31 }
32 }
33
34 fn for_each(&'a self, func: &dyn Fn(&MappedValue<'a>, &mut String) -> CrimResult<()>) -> CrimResult<String> {
35 let mut buf = String::new();
36 for i in self {
37 func( &MappedValue::Struct(i), &mut buf )?;
38 }
39 Ok(buf)
40 }
41}
24 42
25impl<'a> MappedList<'a> for Vec<Value> { 43impl<'a> MappedList<'a> for Vec<Value> {
26 fn get_index(&'a self, id: usize) -> Option<MappedValue<'a>> { 44 fn get_index(&'a self, id: usize) -> Option<MappedValue<'a>> {