replace match by if let statements if possible

This commit is contained in:
Julien Levesy 2016-12-30 17:17:21 +01:00
parent 608511ddc3
commit b78979d692
7 changed files with 39 additions and 58 deletions

View file

@ -131,9 +131,8 @@ pub fn str_join<I, T>(strs: I, join: &str) -> String
/// Like AsciiExt::to_ascii_lowercase, but avoids allocating when the input is already lower-case.
pub fn cow_into_ascii_lowercase<'a, S: Into<Cow<'a, str>>>(s: S) -> Cow<'a, str> {
let mut cow = s.into();
match cow.bytes().position(|byte| byte >= b'A' && byte <= b'Z') {
Some(first_uppercase) => cow.to_mut()[first_uppercase..].make_ascii_lowercase(),
None => {}
if let Some(first_uppercase) = cow.bytes().position(|byte| byte >= b'A' && byte <= b'Z') {
cow.to_mut()[first_uppercase..].make_ascii_lowercase();
}
cow
}