Skip to content

Commit e581aa8

Browse files
authored
Implement IntoIterator for our OOM-handling PrimaryMap (#12605)
* Implement `IntoIterator` for our OOM-handling `PrimaryMap` * rustfmt
1 parent 102a393 commit e581aa8

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

cranelift/entity/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ mod set;
280280
mod sparse;
281281

282282
pub use self::boxed_slice::BoxedSlice;
283-
pub use self::iter::{Iter, IterMut};
283+
pub use self::iter::{IntoIter, Iter, IterMut};
284284
pub use self::keys::Keys;
285285
pub use self::list::{EntityList, ListPool};
286286
pub use self::map::SecondaryMap;

crates/environ/src/collections/primary_map.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,36 @@ where
255255
&mut self.inner[k]
256256
}
257257
}
258+
259+
impl<K, V> IntoIterator for PrimaryMap<K, V>
260+
where
261+
K: EntityRef,
262+
{
263+
type Item = (K, V);
264+
type IntoIter = cranelift_entity::IntoIter<K, V>;
265+
fn into_iter(self) -> Self::IntoIter {
266+
self.inner.into_iter()
267+
}
268+
}
269+
270+
impl<'a, K, V> IntoIterator for &'a PrimaryMap<K, V>
271+
where
272+
K: EntityRef,
273+
{
274+
type Item = (K, &'a V);
275+
type IntoIter = cranelift_entity::Iter<'a, K, V>;
276+
fn into_iter(self) -> Self::IntoIter {
277+
self.iter()
278+
}
279+
}
280+
281+
impl<'a, K, V> IntoIterator for &'a mut PrimaryMap<K, V>
282+
where
283+
K: EntityRef,
284+
{
285+
type Item = (K, &'a mut V);
286+
type IntoIter = cranelift_entity::IterMut<'a, K, V>;
287+
fn into_iter(self) -> Self::IntoIter {
288+
self.iter_mut()
289+
}
290+
}

0 commit comments

Comments
 (0)