From 5eedc8e9080afe1d7fa00d9577343fe5aa25a93d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 22 Jun 2026 09:22:25 -0700 Subject: Attempted fixes. Maybe made it too C++ish --- src/context.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/context.rs') 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 { } } +impl<'a> MappedList<'a> for Vec> { + fn get_index(&'a self, id: usize) -> Option> { + if let Some(x) = self.get(id) { + Some(*x) + } else { + None + } + } + + fn for_each(&'a self, func: &dyn Fn(&MappedValue<'a>, &mut String) -> CrimResult<()>) -> CrimResult { + let mut buf = String::new(); + for i in self { + func( i, &mut buf )?; + } + Ok(buf) + } +} + +pub type MappedHash<'a> = HashMap>; + +impl<'a> MappedStructure<'a> for MappedHash<'a> { + fn get_value(&'a self, id: &str) -> Option> { + self.get(id).copied() + } +} + +#[derive(Copy,Clone)] pub enum MappedValue<'a> { Struct(&'a dyn MappedStructure<'a>), List(&'a dyn MappedList<'a>), -- cgit v1.2.3