Mercurial > public > mercurial-scm > hg-stable
comparison rust/hg-core/src/utils.rs @ 47989:4d2a5ca060e3
rust: Add a Filelog struct that wraps Revlog
Some filelog-specific logic is moved from code `rhg cat` into this struct
where it can better be reused.
Additionally, a missing end delimiter for metadata causes an error
to be returned instead of being silently ignored.
Differential Revision: https://phab.mercurial-scm.org/D11408
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 13 Sep 2021 15:42:39 +0200 |
parents | 696abab107b4 |
children | 5734b03ecf3e |
comparison
equal
deleted
inserted
replaced
47988:cfb6e6699b25 | 47989:4d2a5ca060e3 |
---|---|
72 fn trim_end_matches(&self, f: impl FnMut(u8) -> bool) -> &Self; | 72 fn trim_end_matches(&self, f: impl FnMut(u8) -> bool) -> &Self; |
73 fn trim_start_matches(&self, f: impl FnMut(u8) -> bool) -> &Self; | 73 fn trim_start_matches(&self, f: impl FnMut(u8) -> bool) -> &Self; |
74 fn trim(&self) -> &Self; | 74 fn trim(&self) -> &Self; |
75 fn drop_prefix(&self, needle: &Self) -> Option<&Self>; | 75 fn drop_prefix(&self, needle: &Self) -> Option<&Self>; |
76 fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])>; | 76 fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])>; |
77 fn split_2_by_slice(&self, separator: &[u8]) -> Option<(&[u8], &[u8])>; | |
77 } | 78 } |
78 | 79 |
79 impl SliceExt for [u8] { | 80 impl SliceExt for [u8] { |
80 fn trim_end(&self) -> &[u8] { | 81 fn trim_end(&self) -> &[u8] { |
81 self.trim_end_matches(|byte| byte.is_ascii_whitespace()) | 82 self.trim_end_matches(|byte| byte.is_ascii_whitespace()) |
131 fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])> { | 132 fn split_2(&self, separator: u8) -> Option<(&[u8], &[u8])> { |
132 let mut iter = self.splitn(2, |&byte| byte == separator); | 133 let mut iter = self.splitn(2, |&byte| byte == separator); |
133 let a = iter.next()?; | 134 let a = iter.next()?; |
134 let b = iter.next()?; | 135 let b = iter.next()?; |
135 Some((a, b)) | 136 Some((a, b)) |
137 } | |
138 | |
139 fn split_2_by_slice(&self, separator: &[u8]) -> Option<(&[u8], &[u8])> { | |
140 if let Some(pos) = find_slice_in_slice(self, separator) { | |
141 Some((&self[..pos], &self[pos + separator.len()..])) | |
142 } else { | |
143 None | |
144 } | |
136 } | 145 } |
137 } | 146 } |
138 | 147 |
139 pub trait Escaped { | 148 pub trait Escaped { |
140 /// Return bytes escaped for display to the user | 149 /// Return bytes escaped for display to the user |