Apply changes suggested by clippy lints

This commit is contained in:
Oliver Hamlet
2022-01-23 22:17:35 +00:00
parent 1ca8bb1e49
commit aa3dabab8d
5 changed files with 18 additions and 18 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ where
} else {
slice::from_raw_parts(array, array_size)
.iter()
.map(|c| mapper(c))
.map(mapper)
.collect()
}
}
+5 -5
View File
@@ -96,7 +96,7 @@ fn evaluate_is_master(state: &State, file_path: &Path) -> Result<bool, Error> {
fn evaluate_many_active(state: &State, regex: &Regex) -> Result<bool, Error> {
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(_, _)
)
}
}
+1 -1
View File
@@ -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);
+2 -3
View File
@@ -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;
}
+9 -8
View File
@@ -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<u32>, 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()))
}