summaryrefslogtreecommitdiffstats
path: root/vendor/itertools/src/unique_impl.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/itertools/src/unique_impl.rs
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/itertools/src/unique_impl.rs')
-rw-r--r--vendor/itertools/src/unique_impl.rs81
1 files changed, 49 insertions, 32 deletions
diff --git a/vendor/itertools/src/unique_impl.rs b/vendor/itertools/src/unique_impl.rs
index 4e81e78ec..9b103a075 100644
--- a/vendor/itertools/src/unique_impl.rs
+++ b/vendor/itertools/src/unique_impl.rs
@@ -1,7 +1,7 @@
-use std::collections::HashMap;
use std::collections::hash_map::Entry;
-use std::hash::Hash;
+use std::collections::HashMap;
use std::fmt;
+use std::hash::Hash;
use std::iter::FusedIterator;
/// An iterator adapter to filter out duplicate elements.
@@ -19,17 +19,19 @@ pub struct UniqueBy<I: Iterator, V, F> {
}
impl<I, V, F> fmt::Debug for UniqueBy<I, V, F>
- where I: Iterator + fmt::Debug,
- V: fmt::Debug + Hash + Eq,
+where
+ I: Iterator + fmt::Debug,
+ V: fmt::Debug + Hash + Eq,
{
debug_fmt_fields!(UniqueBy, iter, used);
}
/// Create a new `UniqueBy` iterator.
pub fn unique_by<I, V, F>(iter: I, f: F) -> UniqueBy<I, V, F>
- where V: Eq + Hash,
- F: FnMut(&I::Item) -> V,
- I: Iterator,
+where
+ V: Eq + Hash,
+ F: FnMut(&I::Item) -> V,
+ I: Iterator,
{
UniqueBy {
iter,
@@ -40,8 +42,9 @@ pub fn unique_by<I, V, F>(iter: I, f: F) -> UniqueBy<I, V, F>
// count the number of new unique keys in iterable (`used` is the set already seen)
fn count_new_keys<I, K>(mut used: HashMap<K, ()>, iterable: I) -> usize
- where I: IntoIterator<Item=K>,
- K: Hash + Eq,
+where
+ I: IntoIterator<Item = K>,
+ K: Hash + Eq,
{
let iter = iterable.into_iter();
let current_used = used.len();
@@ -50,9 +53,10 @@ fn count_new_keys<I, K>(mut used: HashMap<K, ()>, iterable: I) -> usize
}
impl<I, V, F> Iterator for UniqueBy<I, V, F>
- where I: Iterator,
- V: Eq + Hash,
- F: FnMut(&I::Item) -> V
+where
+ I: Iterator,
+ V: Eq + Hash,
+ F: FnMut(&I::Item) -> V,
{
type Item = I::Item;
@@ -79,9 +83,10 @@ impl<I, V, F> Iterator for UniqueBy<I, V, F>
}
impl<I, V, F> DoubleEndedIterator for UniqueBy<I, V, F>
- where I: DoubleEndedIterator,
- V: Eq + Hash,
- F: FnMut(&I::Item) -> V
+where
+ I: DoubleEndedIterator,
+ V: Eq + Hash,
+ F: FnMut(&I::Item) -> V,
{
fn next_back(&mut self) -> Option<Self::Item> {
while let Some(v) = self.iter.next_back() {
@@ -95,14 +100,17 @@ impl<I, V, F> DoubleEndedIterator for UniqueBy<I, V, F>
}
impl<I, V, F> FusedIterator for UniqueBy<I, V, F>
- where I: FusedIterator,
- V: Eq + Hash,
- F: FnMut(&I::Item) -> V
-{}
+where
+ I: FusedIterator,
+ V: Eq + Hash,
+ F: FnMut(&I::Item) -> V,
+{
+}
impl<I> Iterator for Unique<I>
- where I: Iterator,
- I::Item: Eq + Hash + Clone
+where
+ I: Iterator,
+ I::Item: Eq + Hash + Clone,
{
type Item = I::Item;
@@ -129,8 +137,9 @@ impl<I> Iterator for Unique<I>
}
impl<I> DoubleEndedIterator for Unique<I>
- where I: DoubleEndedIterator,
- I::Item: Eq + Hash + Clone
+where
+ I: DoubleEndedIterator,
+ I::Item: Eq + Hash + Clone,
{
fn next_back(&mut self) -> Option<Self::Item> {
while let Some(v) = self.iter.iter.next_back() {
@@ -145,35 +154,43 @@ impl<I> DoubleEndedIterator for Unique<I>
}
impl<I> FusedIterator for Unique<I>
- where I: FusedIterator,
- I::Item: Eq + Hash + Clone
-{}
+where
+ I: FusedIterator,
+ I::Item: Eq + Hash + Clone,
+{
+}
/// An iterator adapter to filter out duplicate elements.
///
/// See [`.unique()`](crate::Itertools::unique) for more information.
#[derive(Clone)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
-pub struct Unique<I: Iterator> {
+pub struct Unique<I>
+where
+ I: Iterator,
+ I::Item: Eq + Hash + Clone,
+{
iter: UniqueBy<I, I::Item, ()>,
}
impl<I> fmt::Debug for Unique<I>
- where I: Iterator + fmt::Debug,
- I::Item: Hash + Eq + fmt::Debug,
+where
+ I: Iterator + fmt::Debug,
+ I::Item: Hash + Eq + fmt::Debug + Clone,
{
debug_fmt_fields!(Unique, iter);
}
pub fn unique<I>(iter: I) -> Unique<I>
- where I: Iterator,
- I::Item: Eq + Hash,
+where
+ I: Iterator,
+ I::Item: Eq + Hash + Clone,
{
Unique {
iter: UniqueBy {
iter,
used: HashMap::new(),
f: (),
- }
+ },
}
}