diff rust/hg-core/src/utils.rs @ 48463:5734b03ecf3e

rhg: Initial repository locking Initial Rust implementation of locking based on the `.hg/wlock` symlink (or file), with lock breaking when the recorded pid and hostname show that a lock was left by a local process that is not running anymore (as it might have been killed). Differential Revision: https://phab.mercurial-scm.org/D11835
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 22 Mar 2021 09:07:10 +0100
parents 4d2a5ca060e3
children 8e0d823ef182 29cf3167e459
line wrap: on
line diff
--- a/rust/hg-core/src/utils.rs	Mon Nov 29 17:37:08 2021 +0100
+++ b/rust/hg-core/src/utils.rs	Mon Mar 22 09:07:10 2021 +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>;