Skip to content

Commit

Permalink
fixing according to suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Bijay Shrestha committed Sep 21, 2024
1 parent 2618c33 commit 5a848be
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl GlobalSettings {
let input = input.trim();
if let Some(number) = input.strip_suffix('%') {
let percent = Self::parse_percentage(number)?;
return Self::get_memory_size(percent);
return Ok(Self::get_memory_size(percent));
}
let size = Parser::default()
.with_allow_list(&[
Expand All @@ -359,24 +359,24 @@ impl GlobalSettings {

/// Parses percentage input from input string.
fn parse_percentage(number_str: &str) -> Result<usize, ParseSizeError> {
let Ok(percent) = number_str.parse::<u64>() else {
let Ok(percent) = number_str.parse::<usize>() else {
return Err(ParseSizeError::ParseFailure(format!(
"Invalid Buffer Percentage: {number_str}"
)));
};
match percent {
0..=100 => Ok(percent as usize),
0..=100 => Ok(percent),
_ => Err(ParseSizeError::ParseFailure(format!(
"Invalid Buffer Percentage: {number_str}"
))),
}
}
/// get memory size from percent
fn get_memory_size(percent: usize) -> Result<usize, ParseSizeError> {
fn get_memory_size(percent: usize) -> usize {
let system = System::new_with_specifics(RefreshKind::new().with_memory());
let total_memory_size = system.total_memory() as usize;
let size = (total_memory_size * percent) / 100;
Ok(size)
size

Check failure on line 379 in src/uu/sort/src/sort.rs

View workflow job for this annotation

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

ERROR: `cargo clippy`: returning the result of a `let` binding from a block (file:'src/uu/sort/src/sort.rs', line:379)
}

/// Precompute some data needed for sorting.
Expand Down

0 comments on commit 5a848be

Please sign in to comment.