From f3c6698dec05274bb287414ac1d5d6a3537d4deb Mon Sep 17 00:00:00 2001 From: Felix Stegmaier Date: Wed, 22 May 2024 13:54:04 +0200 Subject: [PATCH 1/3] Implement IntoIterator for LinearMap --- src/linear_map.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/linear_map.rs b/src/linear_map.rs index a7a07198af..771befa5e7 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.get(k).unwrap()); + } + } } From a5f7a67f60f627af0e85000dc2f76f1dfdeb58f3 Mon Sep 17 00:00:00 2001 From: Felix Stegmaier Date: Thu, 23 May 2024 13:20:03 +0200 Subject: [PATCH 2/3] Update linear_map into_iter test --- src/linear_map.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/linear_map.rs b/src/linear_map.rs index 771befa5e7..2e376a521d 100644 --- a/src/linear_map.rs +++ b/src/linear_map.rs @@ -581,7 +581,7 @@ mod test { src.insert("k4", "v4").unwrap(); let clone = src.clone(); for (k, v) in clone.into_iter() { - assert_eq!(v, *src.get(k).unwrap()); + assert_eq!(v, src.remove(k).unwrap()); } } } From d4f7db31496daeb16a0c53d93fcfa769bba63799 Mon Sep 17 00:00:00 2001 From: Felix Stegmaier Date: Thu, 23 May 2024 13:22:49 +0200 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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