From cea5f840ef0281c8ccf9cc0250b2d07082847038 Mon Sep 17 00:00:00 2001 From: Andrew Aylett Date: Tue, 7 Jan 2025 20:15:53 +0000 Subject: [PATCH] style: Avoid calling `unwrap()` when we don't have to (#2519) Use `if let` rather than `is_some()` followed by `unwrap()`, and coerce errors instead of calling `unwrap()` when available. --- crates/atuin-client/src/settings.rs | 2 +- crates/atuin/src/command/client/search.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/atuin-client/src/settings.rs b/crates/atuin-client/src/settings.rs index 10c804fa5e5..4c2b10ab165 100644 --- a/crates/atuin-client/src/settings.rs +++ b/crates/atuin-client/src/settings.rs @@ -613,7 +613,7 @@ impl Settings { match parse_duration(self.sync_frequency.as_str()) { Ok(d) => { - let d = time::Duration::try_from(d).unwrap(); + let d = time::Duration::try_from(d)?; Ok(OffsetDateTime::now_utc() - Settings::last_sync()? >= d) } Err(e) => Err(eyre!("failed to check sync: {}", e)), diff --git a/crates/atuin/src/command/client/search.rs b/crates/atuin/src/command/client/search.rs index b8dfe659b0f..b0e503ad262 100644 --- a/crates/atuin/src/command/client/search.rs +++ b/crates/atuin/src/command/client/search.rs @@ -172,14 +172,14 @@ impl Cmd { return Ok(()); } - if self.search_mode.is_some() { - settings.search_mode = self.search_mode.unwrap(); + if let Some(search_mode) = self.search_mode { + settings.search_mode = search_mode; } - if self.filter_mode.is_some() { - settings.filter_mode = self.filter_mode; + if let Some(filter_mode) = self.filter_mode { + settings.filter_mode = Some(filter_mode); } - if self.inline_height.is_some() { - settings.inline_height = self.inline_height.unwrap(); + if let Some(inline_height) = self.inline_height { + settings.inline_height = inline_height; } settings.shell_up_key_binding = self.shell_up_key_binding;