#[cfg(test)]
mod tests;
use {
crate::{
map::StableMap,
pos_vec::{
pos::{InUse, Pos},
PosVecRawAccess,
},
},
core::{
fmt::{Debug, Formatter},
iter::FusedIterator,
},
hashbrown::hash_map,
};
pub struct IterMut<'a, K, V> {
pub(crate) iter: hash_map::IterMut<'a, K, Pos<InUse>>,
pub(crate) entries: PosVecRawAccess<'a, V>,
}
impl<'a, K, V> Iterator for IterMut<'a, K, V> {
type Item = (&'a K, &'a mut V);
fn next(&mut self) -> Option<Self::Item> {
let (k, pos) = self.iter.next()?;
let value = unsafe { self.entries.get_unchecked_mut(pos) };
Some((k, value))
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}
impl<'a, K, V, S> IntoIterator for &'a mut StableMap<K, V, S> {
type Item = (&'a K, &'a mut V);
type IntoIter = IterMut<'a, K, V>;
fn into_iter(self) -> Self::IntoIter {
self.iter_mut()
}
}
impl<K, V> Debug for IterMut<'_, K, V> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_struct("IterMut").finish_non_exhaustive()
}
}
impl<K, V> FusedIterator for IterMut<'_, K, V> {}
impl<K, V> ExactSizeIterator for IterMut<'_, K, V> {
fn len(&self) -> usize {
self.iter.len()
}
}
unsafe impl<K, V> Send for IterMut<'_, K, V>
where
K: Send,
V: Send,
{
}
unsafe impl<K, V> Sync for IterMut<'_, K, V>
where
K: Sync,
V: Sync,
{
}