#[cfg(test)]
mod tests;
use {
crate::{
linear_storage::LinearStorage,
pos_vec::pos::{InUse, Pos},
},
core::{
fmt::{Debug, Formatter},
iter::FusedIterator,
},
hashbrown::hash_map,
};
pub struct IntoValues<K, V> {
pub(crate) iter: hash_map::IntoValues<K, Pos<InUse>>,
pub(crate) storage: LinearStorage<V>,
}
impl<K, V> Iterator for IntoValues<K, V> {
type Item = V;
fn next(&mut self) -> Option<Self::Item> {
let pos = self.iter.next()?;
let value = unsafe { self.storage.take_unchecked(pos) };
Some(value)
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}
impl<K, V> Debug for IntoValues<K, V> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_struct("IntoValues").finish_non_exhaustive()
}
}
impl<K, V> FusedIterator for IntoValues<K, V> {}
impl<K, V> ExactSizeIterator for IntoValues<K, V> {
fn len(&self) -> usize {
self.iter.len()
}
}
impl<K, V> Default for IntoValues<K, V> {
fn default() -> Self {
Self {
iter: Default::default(),
storage: LinearStorage::with_capacity(0),
}
}
}
unsafe impl<K, V> Send for IntoValues<K, V>
where
K: Send,
V: Send,
{
}
unsafe impl<K, V> Sync for IntoValues<K, V>
where
K: Sync,
V: Sync,
{
}