comparison rust/hg-core/src/utils.rs @ 49634:ec399ddf6764

rust: use `matches!` macro now that we're using Rust 1.42+
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 14 Nov 2022 15:34:51 +0100
parents 048f829a445a
children 5f1cd6839c69
comparison
equal deleted inserted replaced
49633:048f829a445a 49634:ec399ddf6764
196 } 196 }
197 } 197 }
198 198
199 #[cfg(unix)] 199 #[cfg(unix)]
200 pub fn shell_quote(value: &[u8]) -> Vec<u8> { 200 pub fn shell_quote(value: &[u8]) -> Vec<u8> {
201 // TODO: Use the `matches!` macro when we require Rust 1.42+ 201 if value.iter().all(|&byte| {
202 if value.iter().all(|&byte| match byte { 202 matches!(
203 b'a'..=b'z' 203 byte,
204 | b'A'..=b'Z' 204 b'a'..=b'z'
205 | b'0'..=b'9' 205 | b'A'..=b'Z'
206 | b'.' 206 | b'0'..=b'9'
207 | b'_' 207 | b'.'
208 | b'/' 208 | b'_'
209 | b'+' 209 | b'/'
210 | b'-' => true, 210 | b'+'
211 _ => false, 211 | b'-'
212 )
212 }) { 213 }) {
213 value.to_owned() 214 value.to_owned()
214 } else { 215 } else {
215 let mut quoted = Vec::with_capacity(value.len() + 2); 216 let mut quoted = Vec::with_capacity(value.len() + 2);
216 quoted.push(b'\''); 217 quoted.push(b'\'');