Skip to content

Commit

Permalink
Adjust identify_algo_name_and_length to return Option<(String, Option…
Browse files Browse the repository at this point in the history
…<usize>)> instead of (String, Option<usize>)
  • Loading branch information
sylvestre committed Jun 26, 2024
1 parent adcc548 commit ff419a7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/uucore/src/lib/features/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ fn identify_algo_name_and_length(
algo_name_input: Option<&str>,
res: &mut ChecksumResult,
properly_formatted: &mut bool,
) -> (String, Option<usize>) {
) -> Option<(String, Option<usize>)> {
// When the algo-based format is matched, extract details from regex captures
let algorithm = caps.name("algo").map_or("", |m| m.as_str()).to_lowercase();

Expand All @@ -428,13 +428,13 @@ fn identify_algo_name_and_length(
if algo_name_input.is_some() && algo_name_input != Some(&algorithm) {
res.bad_format += 1;
*properly_formatted = false;
return (String::new(), None);
return None;
}

if !SUPPORTED_ALGORITHMS.contains(&algorithm.as_str()) {
// Not supported algo, leave early
*properly_formatted = false;
return (String::new(), None);
return None;
}

let bits = caps.name("bits").map_or(Some(None), |m| {
Expand All @@ -450,10 +450,10 @@ fn identify_algo_name_and_length(
if bits.is_none() {

Check failure on line 450 in src/uucore/src/lib/features/checksum.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo clippy`: this block may be rewritten with the `?` operator (file:'src/uucore/src/lib/features/checksum.rs', line:450)
// If bits is None, we have a parsing or divisibility issue
// Exit the loop outside of the closure
return (String::new(), None);
return None;
}

(algorithm, bits.unwrap())
Some((algorithm, bits.unwrap()))
}

/***
Expand Down Expand Up @@ -518,6 +518,7 @@ where
&mut res,
&mut properly_formatted,
)
.unwrap_or((String::new(), None))
} else if let Some(a) = algo_name_input {
// When a specific algorithm name is input, use it and use the provided bits
(a.to_lowercase(), length_input)
Expand Down

0 comments on commit ff419a7

Please sign in to comment.