From 206abdf496aae4a56936a00c34ea7565facf433d Mon Sep 17 00:00:00 2001 From: Severin Siffert Date: Thu, 23 Nov 2023 11:55:54 +0100 Subject: [PATCH] clippy --- src/dfx/src/util/clap/parsers.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dfx/src/util/clap/parsers.rs b/src/dfx/src/util/clap/parsers.rs index 0dbe392116..9b7184dffc 100644 --- a/src/dfx/src/util/clap/parsers.rs +++ b/src/dfx/src/util/clap/parsers.rs @@ -4,7 +4,7 @@ use std::{path::PathBuf, str::FromStr}; /// Removes `_`, interprets `k`, `m`, `b`, `t` suffix (case-insensitive) fn decimal_with_suffix_parser(input: &str) -> Result { - let input = input.replace("_", "").to_lowercase(); + let input = input.replace('_', "").to_lowercase(); let (number, suffix) = if input .chars() .last() @@ -58,10 +58,10 @@ pub fn memo_parser(memo: &str) -> Result { } pub fn cycle_amount_parser(input: &str) -> Result { - let removed_cycle_suffix = if input.to_lowercase().chars().last() == Some('c') { + let removed_cycle_suffix = if input.to_lowercase().ends_with('c') { &input[..input.len() - 1] } else { - &input[..] + input }; decimal_with_suffix_parser(removed_cycle_suffix)?.try_into().map_err(|_| "Failed to parse amount. Please use digits only or something like 3.5TC, 2t, or 5_000_000.".to_string()) @@ -86,7 +86,7 @@ pub fn file_or_stdin_parser(path: &str) -> Result { } pub fn trillion_cycle_amount_parser(input: &str) -> Result { - if let Ok(cycles) = format!("{}000000000000", input.replace("_", "")).parse::() { + if let Ok(cycles) = format!("{}000000000000", input.replace('_', "")).parse::() { Ok(cycles) } else { decimal_with_suffix_parser(input)? @@ -191,7 +191,7 @@ fn test_cycle_amount_parser() { #[test] fn test_trillion_cycle_amount_parser() { const TRILLION: u128 = 1_000_000_000_000; - assert_eq!(trillion_cycle_amount_parser("1"), Ok(1 * TRILLION)); + assert_eq!(trillion_cycle_amount_parser("3"), Ok(3 * TRILLION)); assert_eq!(trillion_cycle_amount_parser("5_555"), Ok(5_555 * TRILLION)); assert_eq!(trillion_cycle_amount_parser("1k"), Ok(1_000 * TRILLION)); assert_eq!(trillion_cycle_amount_parser("0.3"), Ok(300_000_000_000));