#[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 Values<'a, K, V> {
pub(crate) iter: hash_map::Values<'a, K, Pos<InUse>>,
pub(crate) storage: &'a LinearStorage<V>,
}
impl<'a, K, V> Iterator for Values<'a, K, V> {
type Item = &'a V;
fn next(&mut self) -> Option<Self::Item> {
let pos = self.iter.next()?;
let value = unsafe { self.storage.get_unchecked(pos) };
Some(value)
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}
impl<K, V> Clone for Values<'_, K, V> {
fn clone(&self) -> Self {
Self {
iter: self.iter.clone(),
storage: self.storage,
}
}
}
impl<K, V> Debug for Values<'_, K, V>
where
K: Debug,
V: Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_list().entries(self.clone()).finish()
}
}
impl<K, V> FusedIterator for Values<'_, K, V> {}
impl<K, V> ExactSizeIterator for Values<'_, K, V> {
fn len(&self) -> usize {
self.iter.len()
}
}
unsafe impl<K, V> Send for Values<'_, K, V>
where
K: Send,
V: Send,
{
}
unsafe impl<K, V> Sync for Values<'_, K, V>
where
K: Sync,
V: Sync,
{
}