From 482f3f7fb0d7d21e6a54e57156dc3fb92e21971c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sof=C3=ADa=20Aritz?= Date: Sat, 11 Mar 2023 20:51:25 +0100 Subject: [PATCH] Use a more idiomatic way to convert a `HashMap` to an `Option` --- src/main.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 68a42fd..110bd57 100644 --- a/src/main.rs +++ b/src/main.rs @@ -235,16 +235,11 @@ impl eframe::App for App { ui.add_space(10.0); if ui.button("add note").clicked() { - // FIXME(sofia@git.sofiaritz.com): Use a more idiomatic way - let metadata = if let Some(metadata) = self.metadata_buffer.clone() { - if metadata.is_empty() { - None - } else { - Some(metadata) - } - } else { - None - }; + let metadata = self.metadata_buffer.clone() + .and_then(|metadata| { + (!metadata.is_empty()) + .then_some(metadata) + }); let note = Note::Decrypted { id: SystemTime::now()