rust/hg-core/src/utils.rs
branchstable
changeset 48796 c00d3ce4e94b
parent 48417 5734b03ecf3e
child 49631 29cf3167e459
child 50214 8e0d823ef182
--- a/rust/hg-core/src/utils.rs	Fri Feb 18 12:55:39 2022 +0100
+++ b/rust/hg-core/src/utils.rs	Fri Feb 18 14:27:43 2022 +0100
@@ -145,6 +145,21 @@
     }
 }
 
+pub trait StrExt {
+    // TODO: Use https://doc.rust-lang.org/nightly/std/primitive.str.html#method.split_once
+    // once we require Rust 1.52+
+    fn split_2(&self, separator: char) -> Option<(&str, &str)>;
+}
+
+impl StrExt for str {
+    fn split_2(&self, separator: char) -> Option<(&str, &str)> {
+        let mut iter = self.splitn(2, separator);
+        let a = iter.next()?;
+        let b = iter.next()?;
+        Some((a, b))
+    }
+}
+
 pub trait Escaped {
     /// Return bytes escaped for display to the user
     fn escaped_bytes(&self) -> Vec<u8>;