Merge pull request #474 from XOSplicer/linear-map-into-iter

Implement IntoIterator for LinearMap
This commit is contained in:
Markus Reiter 2024-05-23 17:50:36 +00:00 committed by GitHub
commit c118d70d20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 0 deletions

View File

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added `Deque::make_contiguous`.
- Added `VecView`, the `!Sized` version of `Vec`.
- Added pool implementations for 64-bit architectures.
- Added `IntoIterator` implementation for `LinearMap`
### Changed

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.remove(k).unwrap());
}
}
}