Implement IntoIterator for LinearMap

This commit is contained in:
Felix Stegmaier 2024-05-22 13:54:04 +02:00
parent 329d733ab8
commit f3c6698dec
No known key found for this signature in database
GPG Key ID: 67AA4D4ECB976BCE

View File

@ -430,6 +430,20 @@ where
}
}
impl<K, V, const N: usize> IntoIterator for LinearMap<K, V, N>
where
K: Eq,
{
type Item = (K, V);
type IntoIter = IntoIter<K, V, N>;
fn into_iter(self) -> Self::IntoIter {
IntoIter {
inner: self.buffer.into_iter(),
}
}
}
impl<'a, K, V, const N: usize> IntoIterator for &'a LinearMap<K, V, N>
where
K: Eq,
@ -557,4 +571,17 @@ mod test {
assert_eq!(Droppable::count(), 0);
}
#[test]
fn into_iter() {
let mut src: LinearMap<_, _, 4> = LinearMap::new();
src.insert("k1", "v1").unwrap();
src.insert("k2", "v2").unwrap();
src.insert("k3", "v3").unwrap();
src.insert("k4", "v4").unwrap();
let clone = src.clone();
for (k, v) in clone.into_iter() {
assert_eq!(v, *src.get(k).unwrap());
}
}
}