comparison rust/hg-core/src/utils.rs @ 46505:a25033eb43b5

rhg: add limited support for the `config` sub-command Only with one argument and no flag. This is mostly for testing. Differential Revision: https://phab.mercurial-scm.org/D9972
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 08 Feb 2021 23:41:58 +0100
parents 2845892dd489
children 435d9fc72646
comparison
equal deleted inserted replaced
46504:2e5dd18d6dc3 46505:a25033eb43b5
65 pub trait SliceExt { 65 pub trait SliceExt {
66 fn trim_end(&self) -> &Self; 66 fn trim_end(&self) -> &Self;
67 fn trim_start(&self) -> &Self; 67 fn trim_start(&self) -> &Self;
68 fn trim(&self) -> &Self; 68 fn trim(&self) -> &Self;
69 fn drop_prefix(&self, needle: &Self) -> Option<&Self>; 69 fn drop_prefix(&self, needle: &Self) -> Option<&Self>;
70 fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])>;
70 } 71 }
71 72
72 #[allow(clippy::trivially_copy_pass_by_ref)] 73 #[allow(clippy::trivially_copy_pass_by_ref)]
73 fn is_not_whitespace(c: &u8) -> bool { 74 fn is_not_whitespace(c: &u8) -> bool {
74 !(*c as char).is_whitespace() 75 !(*c as char).is_whitespace()
114 Some(&self[needle.len()..]) 115 Some(&self[needle.len()..])
115 } else { 116 } else {
116 None 117 None
117 } 118 }
118 } 119 }
120
121 fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])> {
122 let mut iter = self.splitn(2, |&byte| byte == separator);
123 let a = iter.next()?;
124 let b = iter.next()?;
125 Some((a, b))
126 }
119 } 127 }
120 128
121 pub trait Escaped { 129 pub trait Escaped {
122 /// Return bytes escaped for display to the user 130 /// Return bytes escaped for display to the user
123 fn escaped_bytes(&self) -> Vec<u8>; 131 fn escaped_bytes(&self) -> Vec<u8>;