Skip to content

Commit 88ab4a6

Browse files
jtakakuraricochet
authored andcommitted
refactor: simplify duration parsing and remove unnecessary variable assignment
Signed-off-by: Junji Takakura <j.takakura@gmail.com>
1 parent e376b01 commit 88ab4a6

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

crates/wash/src/cli/util.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ const fn empty_table_style() -> TableStyle {
192192
}
193193

194194
mod test {
195-
use std::time::Duration;
196-
197195
#[test]
198196
fn test_safe_base64_parse_option() {
199197
let base64_option = "config_b64=eyJhZGRyZXNzIjogIjAuMC4wLjA6ODA4MCJ9Cg==".to_string();
@@ -211,25 +209,25 @@ mod test {
211209
// Test humantime format
212210
assert_eq!(
213211
crate::util::parse_duration_fallback_ms("5s").unwrap(),
214-
Duration::from_secs(5)
212+
std::time::Duration::from_secs(5)
215213
);
216214
assert_eq!(
217215
crate::util::parse_duration_fallback_ms("100ms").unwrap(),
218-
Duration::from_millis(100)
216+
std::time::Duration::from_millis(100)
219217
);
220218
assert_eq!(
221219
crate::util::parse_duration_fallback_ms("2m").unwrap(),
222-
Duration::from_secs(120)
220+
std::time::Duration::from_secs(120)
223221
);
224222

225223
// Test milliseconds fallback
226224
assert_eq!(
227225
crate::util::parse_duration_fallback_ms("1000").unwrap(),
228-
Duration::from_millis(1000)
226+
std::time::Duration::from_millis(1000)
229227
);
230228
assert_eq!(
231229
crate::util::parse_duration_fallback_ms("500").unwrap(),
232-
Duration::from_millis(500)
230+
std::time::Duration::from_millis(500)
233231
);
234232

235233
// Test error cases

src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -759,13 +759,12 @@ fn parse_duration_fallback_ms(arg: &str) -> anyhow::Result<Duration> {
759759
/// the argument provided by the user.
760760
/// This function should be removed once the older duration options are fully deprecated.
761761
fn get_preferred_arg(old: Duration, new: Duration, default: Duration) -> Duration {
762-
let return_value = match (old, new) {
762+
match (old, new) {
763763
(a, b) if a == b => a,
764764
(a, b) if a == default => b,
765765
(a, b) if b == default => a,
766766
_ => default,
767-
};
768-
return return_value;
767+
}
769768
}
770769

771770
/// Validates that a subject string (e.g. secrets-topic and policy-topic) adheres to the rules and conventions

0 commit comments

Comments
 (0)