use core::fmt;
type Delegate<K, V> = std::vec::IntoIter<(K, V)>;
pub struct IntoValues<K, V> {
delegate: Delegate<K, V>,
}
impl<K, V> IntoValues<K, V> {
pub(super) fn from_delegate(delegate: Delegate<K, V>) -> Self {
Self { delegate }
}
}
impl<K, V> Iterator for IntoValues<K, V> {
type Item = V;
fn next(&mut self) -> Option<Self::Item> {
self.delegate.next().map(|(_, v)| v)
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.delegate.size_hint()
}
fn count(self) -> usize
where
Self: Sized,
{
self.delegate.count()
}
fn last(self) -> Option<Self::Item>
where
Self: Sized,
{
self.delegate.last().map(|(_, v)| v)
}
fn nth(&mut self, n: usize) -> Option<Self::Item> {
self.delegate.nth(n).map(|(_, v)| v)
}
}
impl<K, V> std::iter::FusedIterator for IntoValues<K, V> {}
impl<K, V> ExactSizeIterator for IntoValues<K, V> {
fn len(&self) -> usize {
self.delegate.len()
}
}
impl<K, V> DoubleEndedIterator for IntoValues<K, V> {
fn next_back(&mut self) -> Option<Self::Item> {
self.delegate.next_back().map(|(_, v)| v)
}
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
self.delegate.nth_back(n).map(|(_, v)| v)
}
}
impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IntoValues<K, V> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("IntoValues")
.field(&self.delegate.as_slice())
.finish()
}
}
impl<K: Clone, V: Clone> Clone for IntoValues<K, V> {
#[inline]
fn clone(&self) -> Self {
Self {
delegate: self.delegate.clone(),
}
}
}