diff --git a/CHANGELOG.md b/CHANGELOG.md index 875f40baf0..0bea10baa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/linear_map.rs b/src/linear_map.rs index a7a07198af..2e376a521d 100644 --- a/src/linear_map.rs +++ b/src/linear_map.rs @@ -430,6 +430,20 @@ where } } +impl IntoIterator for LinearMap +where + K: Eq, +{ + type Item = (K, V); + type IntoIter = IntoIter; + + fn into_iter(self) -> Self::IntoIter { + IntoIter { + inner: self.buffer.into_iter(), + } + } +} + impl<'a, K, V, const N: usize> IntoIterator for &'a LinearMap 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()); + } + } }