aboutsummaryrefslogtreecommitdiff
path: root/src/crates
diff options
context:
space:
mode:
authorAria Shrimpton <me@aria.rip>2024-02-23 20:49:41 +0000
committerAria Shrimpton <me@aria.rip>2024-02-23 20:49:41 +0000
commiteda6a357c5a9f0ea90b906e363d92b551972f819 (patch)
tree34fac541668fb3cbb5a3630c4372190e0daf0996 /src/crates
parentfaf8698cc5dd67f8ab7471f8c5ddb38a71a20391 (diff)
add iter to mapping trait
Diffstat (limited to 'src/crates')
-rw-r--r--src/crates/library/src/btreemap.rs8
-rw-r--r--src/crates/library/src/hashmap.rs8
-rw-r--r--src/crates/library/src/profiler.rs8
-rw-r--r--src/crates/library/src/traits.rs6
4 files changed, 30 insertions, 0 deletions
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<K: Ord + Hash, V> Mapping<K, V> for BTreeMap<K, V> {
fn clear(&mut self) {
BTreeMap::clear(self)
}
+
+ fn iter<'a>(&'a self) -> impl Iterator<Item = (&'a K, &'a V)> + '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<K: Ord + Hash, V> Mapping<K, V> for HashMap<K, V> {
fn clear(&mut self) {
HashMap::clear(self)
}
+
+ fn iter<'a>(&'a self) -> impl Iterator<Item = (&'a K, &'a V)> + '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<const ID: usize, T: Mapping<K, V>, K, V> Mapping<K, V>
self.n_clear += 1;
self.inner.as_mut().unwrap().clear()
}
+
+ fn iter<'a>(&'a self) -> impl Iterator<Item = (&'a K, &'a V)> + 'a
+ where
+ K: 'a,
+ V: 'a,
+ {
+ self.inner.as_ref().unwrap().iter()
+ }
}
impl<const ID: usize, T, E> Drop for MappingProfilerWrapper<ID, T, E> {
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<K, V>: Default + IntoIterator<Item = (K, V)> + 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<Item = (&'a K, &'a V)> + 'a
+ where
+ K: 'a,
+ V: 'a;
}