summaryrefslogtreecommitdiffstats
path: root/vendor/itertools/src/diff.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/diff.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/diff.rs')
-rw-r--r--vendor/itertools/src/diff.rs30
1 files changed, 17 insertions, 13 deletions
diff --git a/vendor/itertools/src/diff.rs b/vendor/itertools/src/diff.rs
index 1731f0639..0d3d358b5 100644
--- a/vendor/itertools/src/diff.rs
+++ b/vendor/itertools/src/diff.rs
@@ -13,8 +13,9 @@ use crate::structs::PutBack;
/// `Diff` represents the way in which the elements yielded by the iterator `I` differ to some
/// iterator `J`.
pub enum Diff<I, J>
- where I: Iterator,
- J: Iterator
+where
+ I: Iterator,
+ J: Iterator,
{
/// The index of the first non-matching element along with both iterator's remaining elements
/// starting with the first mis-match.
@@ -37,11 +38,11 @@ pub enum Diff<I, J>
///
/// If `i` becomes exhausted before `j` becomes exhausted, the number of elements in `i` along with
/// the remaining `j` elements will be returned as `Diff::Longer`.
-pub fn diff_with<I, J, F>(i: I, j: J, is_equal: F)
- -> Option<Diff<I::IntoIter, J::IntoIter>>
- where I: IntoIterator,
- J: IntoIterator,
- F: Fn(&I::Item, &J::Item) -> bool
+pub fn diff_with<I, J, F>(i: I, j: J, is_equal: F) -> Option<Diff<I::IntoIter, J::IntoIter>>
+where
+ I: IntoIterator,
+ J: IntoIterator,
+ F: Fn(&I::Item, &J::Item) -> bool,
{
let mut i = i.into_iter();
let mut j = j.into_iter();
@@ -49,13 +50,16 @@ pub fn diff_with<I, J, F>(i: I, j: J, is_equal: F)
while let Some(i_elem) = i.next() {
match j.next() {
None => return Some(Diff::Shorter(idx, put_back(i).with_value(i_elem))),
- Some(j_elem) => if !is_equal(&i_elem, &j_elem) {
- let remaining_i = put_back(i).with_value(i_elem);
- let remaining_j = put_back(j).with_value(j_elem);
- return Some(Diff::FirstMismatch(idx, remaining_i, remaining_j));
- },
+ Some(j_elem) => {
+ if !is_equal(&i_elem, &j_elem) {
+ let remaining_i = put_back(i).with_value(i_elem);
+ let remaining_j = put_back(j).with_value(j_elem);
+ return Some(Diff::FirstMismatch(idx, remaining_i, remaining_j));
+ }
+ }
}
idx += 1;
}
- j.next().map(|j_elem| Diff::Longer(idx, put_back(j).with_value(j_elem)))
+ j.next()
+ .map(|j_elem| Diff::Longer(idx, put_back(j).with_value(j_elem)))
}