(WIP) add an EnvIter that only goes through iter that would be in single hashmap
use std::cell::RefCell;
-use std::collections::HashMap;
+use std::collections::{hash_map, HashMap};
use std::hash::Hash;
use std::iter::FromIterator;
use std::marker::PhantomData;
@@ -78,6 +78,12 @@ impl<K: Hash + Eq, V: PartialEq> Environment<K, V> {
EnvElemIter { env, current_map }
}
+ pub fn iter(&self) -> EnvIter<'_, K, V> {
+ EnvIter {
+ collapsed_map: self.iter_elems().collect::<HashMap<_, _>>().into_iter(),
+ }
+ }
+
fn was_cloned(&self) -> bool {
Rc::strong_count(&self.current) > 1
}
@@ -171,6 +177,18 @@ impl<'a, K: 'a + Hash + Eq, V: 'a + PartialEq> Iterator for EnvElemIter<'a, K, V
}
}
+pub struct EnvIter<'a, K: 'a + Hash + Eq, V: 'a + PartialEq> {
+ collapsed_map: hash_map::IntoIter<&'a K, &'a V>,
+}
+
+impl<'a, K: 'a + Hash + Eq, V: 'a + PartialEq> Iterator for EnvIter<'a, K, V> {
+ type Item = (&'a K, &'a V);
+
+ fn next(&mut self) -> Option<Self::Item> {
+ self.collapsed_map.next()
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
