Skip to content

Commit c118d70

Browse files
authored
Merge pull request #474 from XOSplicer/linear-map-into-iter
Implement IntoIterator for LinearMap
2 parents 804fa58 + d4f7db3 commit c118d70

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1818
- Added `Deque::make_contiguous`.
1919
- Added `VecView`, the `!Sized` version of `Vec`.
2020
- Added pool implementations for 64-bit architectures.
21+
- Added `IntoIterator` implementation for `LinearMap`
2122

2223
### Changed
2324

src/linear_map.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,20 @@ where
430430
}
431431
}
432432

433+
impl<K, V, const N: usize> IntoIterator for LinearMap<K, V, N>
434+
where
435+
K: Eq,
436+
{
437+
type Item = (K, V);
438+
type IntoIter = IntoIter<K, V, N>;
439+
440+
fn into_iter(self) -> Self::IntoIter {
441+
IntoIter {
442+
inner: self.buffer.into_iter(),
443+
}
444+
}
445+
}
446+
433447
impl<'a, K, V, const N: usize> IntoIterator for &'a LinearMap<K, V, N>
434448
where
435449
K: Eq,
@@ -557,4 +571,17 @@ mod test {
557571

558572
assert_eq!(Droppable::count(), 0);
559573
}
574+
575+
#[test]
576+
fn into_iter() {
577+
let mut src: LinearMap<_, _, 4> = LinearMap::new();
578+
src.insert("k1", "v1").unwrap();
579+
src.insert("k2", "v2").unwrap();
580+
src.insert("k3", "v3").unwrap();
581+
src.insert("k4", "v4").unwrap();
582+
let clone = src.clone();
583+
for (k, v) in clone.into_iter() {
584+
assert_eq!(v, src.remove(k).unwrap());
585+
}
586+
}
560587
}

0 commit comments

Comments
 (0)