mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-10-02 14:54:30 +00:00
Merge pull request #474 from XOSplicer/linear-map-into-iter
Implement IntoIterator for LinearMap
This commit is contained in:
commit
c118d70d20
@ -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
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user