From 9b7875c0236f50352f1f495317b2b2ddbdd57553 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 8 Feb 2020 23:18:02 +0200 Subject: [PATCH] ui: change Component::get_status return type There was no reason to return Option, just return String::new() instead of Option::None --- src/components.rs | 4 +-- src/components/contacts/contact_list.rs | 10 +++--- src/components/mail/listing.rs | 43 +++++++++++-------------- src/components/utilities.rs | 8 ++--- 4 files changed, 28 insertions(+), 37 deletions(-) diff --git a/src/components.rs b/src/components.rs index dca1b6cd3..a4ec8dc40 100644 --- a/src/components.rs +++ b/src/components.rs @@ -75,7 +75,7 @@ pub trait Component: Display + Debug + Send { Default::default() } - fn get_status(&self, _context: &Context) -> Option { - None + fn get_status(&self, _context: &Context) -> String { + String::new() } } diff --git a/src/components/contacts/contact_list.rs b/src/components/contacts/contact_list.rs index 66063796d..95e660520 100644 --- a/src/components/contacts/contact_list.rs +++ b/src/components/contacts/contact_list.rs @@ -670,7 +670,7 @@ impl Component for ContactList { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.get_status(context).unwrap(), + self.get_status(context), ))); } @@ -707,7 +707,7 @@ impl Component for ContactList { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.get_status(context).unwrap(), + self.get_status(context), ))); } return true; @@ -894,10 +894,10 @@ impl Component for ContactList { .unwrap_or(true) } - fn get_status(&self, context: &Context) -> Option { - Some(format!( + fn get_status(&self, context: &Context) -> String { + format!( "{} entries", context.accounts[self.account_pos].address_book.len() - )) + ) } } diff --git a/src/components/mail/listing.rs b/src/components/mail/listing.rs index 60af1d8f7..6806f9ebc 100644 --- a/src/components/mail/listing.rs +++ b/src/components/mail/listing.rs @@ -545,7 +545,7 @@ impl Component for Listing { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.get_status(context).unwrap(), + self.get_status(context), ))); return true; } @@ -613,7 +613,7 @@ impl Component for Listing { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.get_status(context).unwrap(), + self.get_status(context), ))); return true; } @@ -798,7 +798,7 @@ impl Component for Listing { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.get_status(context).unwrap(), + self.get_status(context), ))); } UIEvent::MailboxUpdate(_) => { @@ -806,7 +806,7 @@ impl Component for Listing { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.get_status(context).unwrap(), + self.get_status(context), ))); } UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Alt('')) => { @@ -852,32 +852,27 @@ impl Component for Listing { self.component.set_id(id); } - fn get_status(&self, context: &Context) -> Option { - Some({ - let folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0] - .folders_order - .get(self.cursor_pos.1) - { - *h - } else { - return Some(String::new()); - }; - if !context.accounts[self.cursor_pos.0].folders[&folder_hash].is_available() { - return Some(String::new()); - } - let account = &context.accounts[self.cursor_pos.0]; - let m = if account[self.cursor_pos.1].is_available() { - account[self.cursor_pos.1].unwrap() - } else { - return Some(String::new()); - }; + fn get_status(&self, context: &Context) -> String { + let folder_hash = if let Some((_, folder_hash)) = self.accounts[self.cursor_pos.0] + .entries + .get(self.cursor_pos.1) + { + *folder_hash + } else { + return String::new(); + }; + + let account = &context.accounts[self.cursor_pos.0]; + if let Ok(m) = account[folder_hash].as_result() { format!( "Mailbox: {}, Messages: {}, New: {}", m.folder.name(), m.envelopes.len(), m.folder.count().ok().map(|(v, _)| v).unwrap_or(0), ) - }) + } else { + account[folder_hash].to_string() + } } } diff --git a/src/components/utilities.rs b/src/components/utilities.rs index 03c04290d..0d9ecd996 100644 --- a/src/components/utilities.rs +++ b/src/components/utilities.rs @@ -1619,9 +1619,7 @@ impl Component for Tabbed { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.children[self.cursor_pos] - .get_status(context) - .unwrap_or_default(), + self.children[self.cursor_pos].get_status(context), ))); self.set_dirty(true); } @@ -1632,9 +1630,7 @@ impl Component for Tabbed { context .replies .push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus( - self.children[self.cursor_pos] - .get_status(context) - .unwrap_or_default(), + self.children[self.cursor_pos].get_status(context), ))); self.set_dirty(true); return true;