From eda6a357c5a9f0ea90b906e363d92b551972f819 Mon Sep 17 00:00:00 2001 From: Aria Shrimpton Date: Fri, 23 Feb 2024 20:49:41 +0000 Subject: add iter to mapping trait --- src/crates/library/src/btreemap.rs | 8 ++++++++ src/crates/library/src/hashmap.rs | 8 ++++++++ src/crates/library/src/profiler.rs | 8 ++++++++ src/crates/library/src/traits.rs | 6 ++++++ 4 files changed, 30 insertions(+) diff --git a/src/crates/library/src/btreemap.rs b/src/crates/library/src/btreemap.rs index 4cd490e..3943eee 100644 --- a/src/crates/library/src/btreemap.rs +++ b/src/crates/library/src/btreemap.rs @@ -84,6 +84,14 @@ impl Mapping for BTreeMap { fn clear(&mut self) { BTreeMap::clear(self) } + + fn iter<'a>(&'a self) -> impl Iterator + 'a + where + K: 'a, + V: 'a, + { + BTreeMap::iter(self) + } } #[cfg(test)] diff --git a/src/crates/library/src/hashmap.rs b/src/crates/library/src/hashmap.rs index e14074c..b26c5b0 100644 --- a/src/crates/library/src/hashmap.rs +++ b/src/crates/library/src/hashmap.rs @@ -84,6 +84,14 @@ impl Mapping for HashMap { fn clear(&mut self) { HashMap::clear(self) } + + fn iter<'a>(&'a self) -> impl Iterator + 'a + where + K: 'a, + V: 'a, + { + HashMap::iter(self) + } } #[cfg(test)] diff --git a/src/crates/library/src/profiler.rs b/src/crates/library/src/profiler.rs index 5391cb7..1b58a21 100644 --- a/src/crates/library/src/profiler.rs +++ b/src/crates/library/src/profiler.rs @@ -261,6 +261,14 @@ impl, K, V> Mapping self.n_clear += 1; self.inner.as_mut().unwrap().clear() } + + fn iter<'a>(&'a self) -> impl Iterator + 'a + where + K: 'a, + V: 'a, + { + self.inner.as_ref().unwrap().iter() + } } impl Drop for MappingProfilerWrapper { diff --git a/src/crates/library/src/traits.rs b/src/crates/library/src/traits.rs index 39a1874..8af7df6 100644 --- a/src/crates/library/src/traits.rs +++ b/src/crates/library/src/traits.rs @@ -54,4 +54,10 @@ pub trait Mapping: Default + IntoIterator + FromIterator<(K /// Remove all elements from the container fn clear(&mut self); + + /// Iterate over the elements in this container + fn iter<'a>(&'a self) -> impl Iterator + 'a + where + K: 'a, + V: 'a; } -- cgit v1.2.3