]> git.lizzy.rs Git - rust.git/blobdiff - crates/stdx/src/lib.rs
Don't compare ast::Visibility by stringifying
[rust.git] / crates / stdx / src / lib.rs
index 340fcacfa3fa05f1e1ee265471f3412b15684770..18d5fadb9c52a428aa5d2bc80bee5ef9ea7676c1 100644 (file)
@@ -140,6 +140,34 @@ pub fn into_inner(self) -> std::process::Child {
     }
 }
 
+// feature: iter_order_by
+// Iterator::eq_by
+pub fn iter_eq_by<I, I2, F>(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::*;