From da7f1eb756ba849b70ccb7e6c961ccf233e19099 Mon Sep 17 00:00:00 2001 From: Lukas Tobias Wirth Date: Thu, 20 May 2021 17:27:51 +0200 Subject: Don't compare ast::Visibility by stringifying --- crates/stdx/src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'crates/stdx') diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 340fcacfa..18d5fadb9 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -140,6 +140,34 @@ impl JodChild { } } +// feature: iter_order_by +// Iterator::eq_by +pub fn iter_eq_by(this: I2, other: I, mut eq: F) -> bool +where + I: IntoIterator, + I2: IntoIterator, + F: FnMut(I2::Item, I::Item) -> bool, +{ + let mut other = other.into_iter(); + let mut this = this.into_iter(); + + loop { + let x = match this.next() { + None => return other.next().is_none(), + Some(val) => val, + }; + + let y = match other.next() { + None => return false, + Some(val) => val, + }; + + if !eq(x, y) { + return false; + } + } +} + #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3