comparison rust/hg-core/src/utils.rs @ 48417: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 29cf3167e459 8e0d823ef182
comparison
equal deleted inserted replaced
48416:c1b633db67fc 48417:5734b03ecf3e
140 if let Some(pos) = find_slice_in_slice(self, separator) { 140 if let Some(pos) = find_slice_in_slice(self, separator) {
141 Some((&self[..pos], &self[pos + separator.len()..])) 141 Some((&self[..pos], &self[pos + separator.len()..]))
142 } else { 142 } else {
143 None 143 None
144 } 144 }
145 }
146 }
147
148 pub trait StrExt {
149 // TODO: Use https://doc.rust-lang.org/nightly/std/primitive.str.html#method.split_once
150 // once we require Rust 1.52+
151 fn split_2(&self, separator: char) -> Option<(&str, &str)>;
152 }
153
154 impl StrExt for str {
155 fn split_2(&self, separator: char) -> Option<(&str, &str)> {
156 let mut iter = self.splitn(2, separator);
157 let a = iter.next()?;
158 let b = iter.next()?;
159 Some((a, b))
145 } 160 }
146 } 161 }
147 162
148 pub trait Escaped { 163 pub trait Escaped {
149 /// Return bytes escaped for display to the user 164 /// Return bytes escaped for display to the user