diff --git a/ffi/src/helpers.rs b/ffi/src/helpers.rs index 88ec77b..b9399fd 100644 --- a/ffi/src/helpers.rs +++ b/ffi/src/helpers.rs @@ -64,7 +64,7 @@ where } else { slice::from_raw_parts(array, array_size) .iter() - .map(|c| mapper(c)) + .map(mapper) .collect() } } diff --git a/src/function/eval.rs b/src/function/eval.rs index 410f948..34a1e07 100644 --- a/src/function/eval.rs +++ b/src/function/eval.rs @@ -96,7 +96,7 @@ fn evaluate_is_master(state: &State, file_path: &Path) -> Result { fn evaluate_many_active(state: &State, regex: &Regex) -> Result { let mut found_one = false; for active_plugin in &state.active_plugins { - if regex.is_match(&active_plugin) { + if regex.is_match(active_plugin) { if found_one { return Ok(true); } else { @@ -256,10 +256,10 @@ impl Function { /// the operation is simple. fn is_slow(&self) -> bool { use Function::*; - match self { - ActivePath(_) | ActiveRegex(_) | ManyActive(_) | Checksum(_, _) => false, - _ => true, - } + !matches!( + self, + ActivePath(_) | ActiveRegex(_) | ManyActive(_) | Checksum(_, _) + ) } } diff --git a/src/function/parse.rs b/src/function/parse.rs index 1d29062..33238da 100644 --- a/src/function/parse.rs +++ b/src/function/parse.rs @@ -134,7 +134,7 @@ fn parse_regex_path(input: &str) -> ParsingResult<(PathBuf, Regex)> { let (parent_path_slice, regex_slice) = string .rfind('/') .map(|i| (&string[..i], &string[i + 1..])) - .unwrap_or_else(|| (".", &string)); + .unwrap_or_else(|| (".", string)); let parent_path = PathBuf::from(parent_path_slice); diff --git a/src/function/path.rs b/src/function/path.rs index 1f80559..16b6244 100644 --- a/src/function/path.rs +++ b/src/function/path.rs @@ -45,9 +45,8 @@ fn add_ghost_extension(path: PathBuf) -> PathBuf { } } -pub fn normalise_file_name<'a>(game_type: GameType, name: &'a str) -> &'a str { - if name.ends_with(GHOST_EXTENSION_WITH_PERIOD) { - let stem = &name[..name.len() - GHOST_EXTENSION_WITH_PERIOD.len()]; +pub fn normalise_file_name(game_type: GameType, name: &str) -> &str { + if let Some(stem) = name.strip_suffix(GHOST_EXTENSION_WITH_PERIOD) { if has_unghosted_plugin_file_extension(game_type, Path::new(stem)) { return stem; } diff --git a/src/function/version.rs b/src/function/version.rs index a333083..28e0d5c 100644 --- a/src/function/version.rs +++ b/src/function/version.rs @@ -15,7 +15,9 @@ enum ReleaseId { impl<'a> From<&'a str> for ReleaseId { fn from(string: &'a str) -> Self { - u32::from_str_radix(string.trim(), 10) + string + .trim() + .parse() .map(ReleaseId::Numeric) .unwrap_or_else(|_| ReleaseId::NonNumeric(string.to_lowercase())) } @@ -24,7 +26,7 @@ impl<'a> From<&'a str> for ReleaseId { fn are_numeric_values_equal(n: u32, s: &str) -> bool { // The values can only be equal if the trimmed string can be wholly // converted to the same u32 value. - match u32::from_str_radix(s.trim(), 10) { + match s.trim().parse() { Ok(n2) => n == n2, Err(_) => false, } @@ -55,11 +57,8 @@ fn u32_from_str(id: &str) -> (Option, usize) { // If the first byte is not a digit, there is no number to parse (this // ignores + and - signs). Some(0) => (None, id.len()), - Some(index) => ( - u32::from_str_radix(id[..index].trim(), 10).ok(), - id.len() - index, - ), - None => (u32::from_str_radix(id.trim(), 10).ok(), 0), + Some(index) => (id[..index].trim().parse().ok(), id.len() - index), + None => (id.trim().parse().ok(), 0), } } @@ -100,7 +99,9 @@ enum PreReleaseId { impl<'a> From<&'a str> for PreReleaseId { fn from(string: &'a str) -> Self { - u32::from_str_radix(string.trim(), 10) + string + .trim() + .parse() .map(PreReleaseId::Numeric) .unwrap_or_else(|_| PreReleaseId::NonNumeric(string.to_lowercase())) }