mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-01 07:13:24 +03:00
HashMap/HashSet: forward fold implementations of iterators
This commit is contained in:
@@ -2232,6 +2232,14 @@ fn next(&mut self) -> Option<(&'a K, &'a V)> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.base.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.base.fold(init, f)
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<K, V> ExactSizeIterator for Iter<'_, K, V> {
|
||||
@@ -2256,6 +2264,14 @@ fn next(&mut self) -> Option<(&'a K, &'a mut V)> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.base.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.base.fold(init, f)
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<K, V> ExactSizeIterator for IterMut<'_, K, V> {
|
||||
@@ -2290,6 +2306,14 @@ fn next(&mut self) -> Option<(K, V)> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.base.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.base.fold(init, f)
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<K, V> ExactSizeIterator for IntoIter<K, V> {
|
||||
@@ -2320,6 +2344,14 @@ fn next(&mut self) -> Option<&'a K> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.inner.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, mut f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.inner.fold(init, |acc, (k, _)| f(acc, k))
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<K, V> ExactSizeIterator for Keys<'_, K, V> {
|
||||
@@ -2343,6 +2375,14 @@ fn next(&mut self) -> Option<&'a V> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.inner.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, mut f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.inner.fold(init, |acc, (_, v)| f(acc, v))
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<K, V> ExactSizeIterator for Values<'_, K, V> {
|
||||
@@ -2366,6 +2406,14 @@ fn next(&mut self) -> Option<&'a mut V> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.inner.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, mut f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.inner.fold(init, |acc, (_, v)| f(acc, v))
|
||||
}
|
||||
}
|
||||
#[stable(feature = "map_values_mut", since = "1.10.0")]
|
||||
impl<K, V> ExactSizeIterator for ValuesMut<'_, K, V> {
|
||||
@@ -2396,6 +2444,14 @@ fn next(&mut self) -> Option<K> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.inner.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, mut f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.inner.fold(init, |acc, (k, _)| f(acc, k))
|
||||
}
|
||||
}
|
||||
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
|
||||
impl<K, V> ExactSizeIterator for IntoKeys<K, V> {
|
||||
@@ -2426,6 +2482,14 @@ fn next(&mut self) -> Option<V> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.inner.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, mut f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.inner.fold(init, |acc, (_, v)| f(acc, v))
|
||||
}
|
||||
}
|
||||
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
|
||||
impl<K, V> ExactSizeIterator for IntoValues<K, V> {
|
||||
@@ -2456,6 +2520,14 @@ fn next(&mut self) -> Option<(K, V)> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.base.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.base.fold(init, f)
|
||||
}
|
||||
}
|
||||
#[stable(feature = "drain", since = "1.6.0")]
|
||||
impl<K, V> ExactSizeIterator for Drain<'_, K, V> {
|
||||
|
||||
@@ -1500,6 +1500,14 @@ fn next(&mut self) -> Option<&'a K> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.base.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.base.fold(init, f)
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<K> ExactSizeIterator for Iter<'_, K> {
|
||||
@@ -1530,6 +1538,14 @@ fn next(&mut self) -> Option<K> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.base.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.base.fold(init, f)
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<K> ExactSizeIterator for IntoIter<K> {
|
||||
@@ -1560,6 +1576,14 @@ fn next(&mut self) -> Option<K> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.base.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.base.fold(init, f)
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<K> ExactSizeIterator for Drain<'_, K> {
|
||||
@@ -1639,6 +1663,15 @@ fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let (_, upper) = self.iter.size_hint();
|
||||
(0, upper)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, mut f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.iter.fold(init, |acc, elt| if self.other.contains(elt) { f(acc, elt) } else { acc })
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "std_debug", since = "1.16.0")]
|
||||
@@ -1691,6 +1724,15 @@ fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let (_, upper) = self.iter.size_hint();
|
||||
(0, upper)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, mut f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.iter.fold(init, |acc, elt| if self.other.contains(elt) { acc } else { f(acc, elt) })
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "fused", since = "1.26.0")]
|
||||
@@ -1736,6 +1778,14 @@ fn next(&mut self) -> Option<&'a T> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.iter.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.iter.fold(init, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "fused", since = "1.26.0")]
|
||||
@@ -1800,6 +1850,14 @@ fn next(&mut self) -> Option<&'a T> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.iter.size_hint()
|
||||
}
|
||||
#[inline]
|
||||
fn fold<B, F>(self, init: B, f: F) -> B
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(B, Self::Item) -> B,
|
||||
{
|
||||
self.iter.fold(init, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
Reference in New Issue
Block a user