Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed unsoundness in `IndexMap:insert`.
- Limited max size of `IndexMap` to u16::MAX + 1.
The implementation for sizes higher than u16::MAX were unsound anyway.
- Implemented `IntoIterator` for `&mut LinearMap` and `&mut LinearMapView`.

## [v0.9.3] 2025-04-15

Expand Down
32 changes: 32 additions & 0 deletions src/linear_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,18 @@ where
}
}

impl<'a, K, V, S: LinearMapStorage<K, V> + ?Sized> IntoIterator for &'a mut LinearMapInner<K, V, S>
where
K: Eq,
{
type Item = (&'a K, &'a mut V);
type IntoIter = IterMut<'a, K, V>;

fn into_iter(self) -> Self::IntoIter {
self.iter_mut()
}
}

/// An iterator over the items of a [`LinearMap`]
///
/// This struct is created by calling the [`iter`](LinearMap::iter) method on [`LinearMap`].
Expand Down Expand Up @@ -1159,4 +1171,24 @@ mod test {
};
assert_eq!(MAP_SLOTS - 1, src.len());
}

#[test]
fn into_iter_mut() {
let mut map = LinearMap::<_, _, 8>::new();
map.insert(1, 10).unwrap();
map.insert(2, 20).unwrap();

for (_, v) in &mut map {
*v += 1;
}
assert_eq!(map.get(&1), Some(&11));
assert_eq!(map.get(&2), Some(&21));

let view: &mut LinearMapView<_, _> = &mut map;
for (_, v) in view {
*v *= 2;
}
assert_eq!(map.get(&1), Some(&22));
assert_eq!(map.get(&2), Some(&42));
}
}
Loading