Skip to content

Commit 87d7f9a

Browse files
committed
Better size_hint and documentation
1 parent 7d9b058 commit 87d7f9a

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

library/core/src/iter/adapters/dedup.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ where
5050
}
5151

5252
fn size_hint(&self) -> (usize, Option<usize>) {
53-
(0, self.inner.size_hint().1)
53+
let min = self.last.as_ref().map(|_| 1).unwrap_or(0);
54+
let max = self.inner.size_hint().1;
55+
(min, max)
5456
}
5557
}
5658

@@ -105,7 +107,9 @@ where
105107
}
106108

107109
fn size_hint(&self) -> (usize, Option<usize>) {
108-
(0, self.inner.size_hint().1)
110+
let min = self.last.as_ref().map(|_| 1).unwrap_or(0);
111+
let max = self.inner.size_hint().1;
112+
(min, max)
109113
}
110114
}
111115

@@ -161,6 +165,8 @@ where
161165
}
162166

163167
fn size_hint(&self) -> (usize, Option<usize>) {
164-
(0, self.inner.size_hint().1)
168+
let min = self.last.as_ref().map(|_| 1).unwrap_or(0);
169+
let max = self.inner.size_hint().1;
170+
(min, max)
165171
}
166172
}

library/core/src/iter/traits/iterator.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,9 @@ pub trait Iterator {
16931693
/// Removes all but the first of consecutive elements in the iterator according to the
16941694
/// [`PartialEq`] trait implementation.
16951695
///
1696+
/// For an iterator yielding infinitely many consecutive duplicates,
1697+
/// this may result in an infinite loop.
1698+
///
16961699
/// If the iterator is sorted, this removes all duplicates.
16971700
///
16981701
/// # Examples
@@ -1726,6 +1729,9 @@ pub trait Iterator {
17261729
/// The `same_bucket` function is passed a references to two elements from the iterator and
17271730
/// must determine if the elements compare equal.
17281731
///
1732+
/// For an iterator yielding infinitely many consecutive duplicates,
1733+
/// this may result in an infinite loop.
1734+
///
17291735
/// If the iterator is sorted, this removes all duplicates.
17301736
///
17311737
/// # Examples
@@ -1756,6 +1762,9 @@ pub trait Iterator {
17561762
/// Removes all but the first of consecutive elements in the iterator that
17571763
/// resolve to the same key.
17581764
///
1765+
/// For an iterator yielding infinitely many consecutive duplicates,
1766+
/// this may result in an infinite loop.
1767+
///
17591768
/// If the iterator is sorted, this removes all duplicates.
17601769
///
17611770
/// # Examples

0 commit comments

Comments
 (0)