##// END OF EJS Templates
rust-utils: use new find_dirs iterator...
rust-utils: use new find_dirs iterator In cad3dde7a573, the `find_dirs` util was introduced, but the second changeset that made use of it didn't apply. This change fixes the issue. Differential Revision: https://phab.mercurial-scm.org/D6639

File last commit:

r42630:9609430d default
r42814:717686c5 default
Show More
mod.rs
45 lines | 1.0 KiB | application/rls-services+xml | RustLexer
Raphaël Gomès
rust-filepatterns: use bytes instead of String...
r42630 pub mod files;
pub fn replace_slice<T>(buf: &mut [T], from: &[T], to: &[T])
where
T: Clone + PartialEq,
{
if buf.len() < from.len() || from.len() != to.len() {
return;
}
for i in 0..=buf.len() - from.len() {
if buf[i..].starts_with(from) {
buf[i..(i + from.len())].clone_from_slice(to);
}
}
}
pub trait SliceExt {
fn trim(&self) -> &Self;
fn trim_end(&self) -> &Self;
}
fn is_not_whitespace(c: &u8) -> bool {
!(*c as char).is_whitespace()
}
impl SliceExt for [u8] {
fn trim(&self) -> &[u8] {
if let Some(first) = self.iter().position(is_not_whitespace) {
if let Some(last) = self.iter().rposition(is_not_whitespace) {
&self[first..last + 1]
} else {
unreachable!();
}
} else {
&[]
}
}
fn trim_end(&self) -> &[u8] {
if let Some(last) = self.iter().rposition(is_not_whitespace) {
&self[..last + 1]
} else {
&[]
}
}
}