From ecb3fd7f3d5bab2a6f0f7592d2f45928d90fdf56 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 9 Sep 2019 11:54:47 +0300 Subject: [PATCH] Add dyn keyword to Trait objects And fix some unused var warnings as well --- melib/src/backends.rs | 27 +++++++++++----------- melib/src/backends/imap.rs | 4 ++-- melib/src/backends/imap/watch.rs | 7 +----- melib/src/backends/maildir/backend.rs | 4 ++-- melib/src/backends/mbox.rs | 6 ++--- melib/src/email.rs | 14 +++++------ melib/src/email/attachments.rs | 2 +- melib/src/email/compose.rs | 2 +- melib/src/email/parser.rs | 2 +- melib/src/thread.rs | 3 ++- ui/src/components/contacts/contact_list.rs | 2 +- ui/src/components/indexer/index.rs | 3 +-- ui/src/components/mail/listing/compact.rs | 6 ----- ui/src/components/mail/listing/thread.rs | 8 ++----- ui/src/components/mail/view.rs | 4 ++-- ui/src/components/mail/view/envelope.rs | 4 ++-- ui/src/components/utilities.rs | 26 ++++++++++----------- ui/src/components/utilities/widgets.rs | 2 +- ui/src/conf/accounts.rs | 4 ++-- ui/src/execute/actions.rs | 2 +- ui/src/state.rs | 6 ++--- 21 files changed, 62 insertions(+), 76 deletions(-) diff --git a/melib/src/backends.rs b/melib/src/backends.rs index 948636527..fe7ee1a4d 100644 --- a/melib/src/backends.rs +++ b/melib/src/backends.rs @@ -37,12 +37,13 @@ use std::ops::Deref; use fnv::FnvHashMap; use std; -pub type BackendCreator = Box bool>) -> Box>; +pub type BackendCreator = + Box bool>) -> Box>; /// A hashmap containing all available mail backends. /// An abstraction over any available backends. pub struct Backends { - map: FnvHashMap BackendCreator>>, + map: FnvHashMap BackendCreator>>, } impl Default for Backends { @@ -78,7 +79,7 @@ impl Backends { self.map[key]() } - pub fn register(&mut self, key: String, backend: Box BackendCreator>) { + pub fn register(&mut self, key: String, backend: Box BackendCreator>) { if self.map.contains_key(&key) { panic!("{} is an already registered backend", key); } @@ -116,9 +117,9 @@ impl RefreshEvent { /// A `RefreshEventConsumer` is a boxed closure that must be used to consume a `RefreshEvent` and /// send it to a UI provided channel. We need this level of abstraction to provide an interface for /// all users of mailbox refresh events. -pub struct RefreshEventConsumer(Box () + Send + Sync>); +pub struct RefreshEventConsumer(Box () + Send + Sync>); impl RefreshEventConsumer { - pub fn new(b: Box () + Send + Sync>) -> Self { + pub fn new(b: Box () + Send + Sync>) -> Self { RefreshEventConsumer(b) } pub fn send(&self, r: RefreshEvent) { @@ -126,7 +127,7 @@ impl RefreshEventConsumer { } } -pub struct NotifyFn(Box () + Send + Sync>); +pub struct NotifyFn(Box () + Send + Sync>); impl fmt::Debug for NotifyFn { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -134,14 +135,14 @@ impl fmt::Debug for NotifyFn { } } -impl From () + Send + Sync>> for NotifyFn { - fn from(kind: Box () + Send + Sync>) -> Self { +impl From () + Send + Sync>> for NotifyFn { + fn from(kind: Box () + Send + Sync>) -> Self { NotifyFn(kind) } } impl NotifyFn { - pub fn new(b: Box () + Send + Sync>) -> Self { + pub fn new(b: Box () + Send + Sync>) -> Self { NotifyFn(b) } pub fn notify(&self, f: FolderHash) { @@ -164,10 +165,10 @@ pub trait MailBackend: ::std::fmt::Debug { fn get(&mut self, folder: &Folder) -> Async>>; fn watch(&self, sender: RefreshEventConsumer) -> Result<()>; fn folders(&self) -> FnvHashMap; - fn operation(&self, hash: EnvelopeHash, folder_hash: FolderHash) -> Box; + fn operation(&self, hash: EnvelopeHash, folder_hash: FolderHash) -> Box; fn save(&self, bytes: &[u8], folder: &str, flags: Option) -> Result<()>; - fn folder_operation(&mut self, path: &str, op: FolderOperation) -> Result<()> { + fn folder_operation(&mut self, _path: &str, _op: FolderOperation) -> Result<()> { Ok(()) } } @@ -234,11 +235,11 @@ pub trait BackendOp: ::std::fmt::Debug + ::std::marker::Send { /// Seen flag when fetching an envelope) #[derive(Debug)] pub struct ReadOnlyOp { - op: Box, + op: Box, } impl ReadOnlyOp { - pub fn new(op: Box) -> Box { + pub fn new(op: Box) -> Box { Box::new(ReadOnlyOp { op }) } } diff --git a/melib/src/backends/imap.rs b/melib/src/backends/imap.rs index 99a51d719..d68ff4908 100644 --- a/melib/src/backends/imap.rs +++ b/melib/src/backends/imap.rs @@ -245,7 +245,7 @@ impl MailBackend for ImapType { .collect() } - fn operation(&self, hash: EnvelopeHash, _folder_hash: FolderHash) -> Box { + fn operation(&self, hash: EnvelopeHash, _folder_hash: FolderHash) -> Box { let (uid, folder_hash) = self.hash_index.lock().unwrap()[&hash]; Box::new(ImapOp::new( uid, @@ -400,7 +400,7 @@ macro_rules! exit_on_error { } } impl ImapType { - pub fn new(s: &AccountSettings, is_subscribed: Box bool>) -> Self { + pub fn new(s: &AccountSettings, is_subscribed: Box bool>) -> Self { use std::io::prelude::*; use std::net::TcpStream; debug!(s); diff --git a/melib/src/backends/imap/watch.rs b/melib/src/backends/imap/watch.rs index 8528549ff..7819be072 100644 --- a/melib/src/backends/imap/watch.rs +++ b/melib/src/backends/imap/watch.rs @@ -57,7 +57,7 @@ pub fn poll_with_examine(kit: ImapWatchKit) { let mut response = String::with_capacity(8 * 1024); loop { std::thread::sleep(std::time::Duration::from_millis(5 * 60 * 1000)); - for (hash, folder) in &folders { + for folder in folders.values() { examine_updates(folder, &sender, &mut conn, &hash_index, &uid_index); } let mut main_conn = main_conn.lock().unwrap(); @@ -318,11 +318,6 @@ pub fn idle(kit: ImapWatchKit) { } } } - debug!("failure"); - sender.send(RefreshEvent { - hash: folder_hash, - kind: RefreshEventKind::Failure(MeliError::new("conn_error")), - }); } fn examine_updates( diff --git a/melib/src/backends/maildir/backend.rs b/melib/src/backends/maildir/backend.rs index 9a7b50e73..46b51eece 100644 --- a/melib/src/backends/maildir/backend.rs +++ b/melib/src/backends/maildir/backend.rs @@ -460,7 +460,7 @@ impl MailBackend for MaildirType { Ok(()) } - fn operation(&self, hash: EnvelopeHash, folder_hash: FolderHash) -> Box { + fn operation(&self, hash: EnvelopeHash, folder_hash: FolderHash) -> Box { Box::new(MaildirOp::new(hash, self.hash_indexes.clone(), folder_hash)) } @@ -529,7 +529,7 @@ impl MailBackend for MaildirType { } impl MaildirType { - pub fn new(settings: &AccountSettings, is_subscribed: Box bool>) -> Self { + pub fn new(settings: &AccountSettings, is_subscribed: Box bool>) -> Self { let mut folders: FnvHashMap = Default::default(); fn recurse_folders>( folders: &mut FnvHashMap, diff --git a/melib/src/backends/mbox.rs b/melib/src/backends/mbox.rs index 84b7a4b4e..51d6231f0 100644 --- a/melib/src/backends/mbox.rs +++ b/melib/src/backends/mbox.rs @@ -242,7 +242,7 @@ impl BackendOp for MboxOp { flags } - fn set_flag(&mut self, envelope: &mut Envelope, flag: Flag) -> Result<()> { + fn set_flag(&mut self, _envelope: &mut Envelope, _flag: Flag) -> Result<()> { Ok(()) } } @@ -526,7 +526,7 @@ impl MailBackend for MboxType { .map(|(h, f)| (*h, f.clone() as Folder)) .collect() } - fn operation(&self, hash: EnvelopeHash, _folder_hash: FolderHash) -> Box { + fn operation(&self, hash: EnvelopeHash, _folder_hash: FolderHash) -> Box { let (offset, length) = { let index = self.index.lock().unwrap(); index[&hash] @@ -540,7 +540,7 @@ impl MailBackend for MboxType { } impl MboxType { - pub fn new(s: &AccountSettings, _is_subscribed: Box bool>) -> Self { + pub fn new(s: &AccountSettings, _is_subscribed: Box bool>) -> Self { let path = Path::new(s.root_folder.as_str()); if !path.exists() { panic!( diff --git a/melib/src/email.rs b/melib/src/email.rs index 4bfba2ca8..1775cb5e6 100644 --- a/melib/src/email.rs +++ b/melib/src/email.rs @@ -387,7 +387,7 @@ impl Envelope { } Err(MeliError::new("Couldn't parse mail.")) } - pub fn from_token(mut operation: Box, hash: EnvelopeHash) -> Option { + pub fn from_token(mut operation: Box, hash: EnvelopeHash) -> Option { let mut e = Envelope::new(hash); e.flags = operation.fetch_flags(); if let Ok(bytes) = operation.as_bytes() { @@ -522,7 +522,7 @@ impl Envelope { Ok(()) } - pub fn populate_headers_from_token(&mut self, mut operation: Box) -> Result<()> { + pub fn populate_headers_from_token(&mut self, mut operation: Box) -> Result<()> { let headers = operation.fetch_headers()?; self.populate_headers(headers) } @@ -563,7 +563,7 @@ impl Envelope { let _strings: Vec = self.to.iter().map(|a| format!("{}", a)).collect(); _strings.join(", ") } - pub fn bytes(&self, mut operation: Box) -> Vec { + pub fn bytes(&self, mut operation: Box) -> Vec { operation .as_bytes() .map(|v| v.into()) @@ -608,7 +608,7 @@ impl Envelope { }) }) } - pub fn body(&self, mut operation: Box) -> Attachment { + pub fn body(&self, mut operation: Box) -> Attachment { debug!("searching body for {:?}", self.message_id_display()); let file = operation.as_bytes(); self.body_bytes(file.unwrap()) @@ -781,7 +781,7 @@ impl Envelope { pub fn set_datetime(&mut self, new_val: chrono::DateTime) { self.timestamp = new_val.timestamp() as UnixTimestamp; } - pub fn set_flag(&mut self, f: Flag, mut operation: Box) -> Result<()> { + pub fn set_flag(&mut self, f: Flag, mut operation: Box) -> Result<()> { self.flags.toggle(f); operation.set_flag(self, f)?; Ok(()) @@ -792,14 +792,14 @@ impl Envelope { pub fn flags(&self) -> Flag { self.flags } - pub fn set_seen(&mut self, operation: Box) -> Result<()> { + pub fn set_seen(&mut self, operation: Box) -> Result<()> { if !self.flags.contains(Flag::SEEN) { self.set_flag(Flag::SEEN, operation) } else { Ok(()) } } - pub fn set_unseen(&mut self, operation: Box) -> Result<()> { + pub fn set_unseen(&mut self, operation: Box) -> Result<()> { if self.flags.contains(Flag::SEEN) { self.set_flag(Flag::SEEN, operation) } else { diff --git a/melib/src/email/attachments.rs b/melib/src/email/attachments.rs index 04fec24cf..bea56b181 100644 --- a/melib/src/email/attachments.rs +++ b/melib/src/email/attachments.rs @@ -441,7 +441,7 @@ fn decode_rfc822(_raw: &[u8]) -> Attachment { builder.build() } -type Filter<'a> = Box) -> () + 'a>; +type Filter<'a> = Box) -> () + 'a>; fn decode_rec_helper<'a>(a: &'a Attachment, filter: &mut Option>) -> Vec { match a.content_type { diff --git a/melib/src/email/compose.rs b/melib/src/email/compose.rs index b9d915e6c..26ca32193 100644 --- a/melib/src/email/compose.rs +++ b/melib/src/email/compose.rs @@ -113,7 +113,7 @@ impl str::FromStr for Draft { } impl Draft { - pub fn edit(envelope: &Envelope, mut op: Box) -> Self { + pub fn edit(envelope: &Envelope, mut op: Box) -> Self { let mut ret = Draft::default(); //TODO: Inform user if error { diff --git a/melib/src/email/parser.rs b/melib/src/email/parser.rs index 89ea8d4ab..28a3c9401 100644 --- a/melib/src/email/parser.rs +++ b/melib/src/email/parser.rs @@ -247,7 +247,7 @@ pub fn headers_raw(input: &[u8]) -> IResult<&[u8], &[u8]> { if input.is_empty() { return IResult::Incomplete(Needed::Unknown); } - for (i, x) in input.iter().enumerate() { + for i in 0..input.len() { if input[i..].starts_with(b"\n\n") { return IResult::Done(&input[(i + 1)..], &input[0..=i]); } else if input[i..].starts_with(b"\r\n\r\n") { diff --git a/melib/src/thread.rs b/melib/src/thread.rs index b0c5d8f64..9e76879da 100644 --- a/melib/src/thread.rs +++ b/melib/src/thread.rs @@ -1107,6 +1107,7 @@ impl Threads { } } + /* fn link_envelope(&mut self, envelope: &mut Envelope) { let t_idx: ThreadHash = { let m_id = envelope.message_id().raw(); @@ -1215,7 +1216,7 @@ impl Threads { } ref_ptr = parent_id; } - } + }*/ fn tree_insert_root(&mut self, new_id: ThreadHash, envelopes: &Envelopes) { debug_assert!( diff --git a/ui/src/components/contacts/contact_list.rs b/ui/src/components/contacts/contact_list.rs index 3807bc12a..a718ef0f1 100644 --- a/ui/src/components/contacts/contact_list.rs +++ b/ui/src/components/contacts/contact_list.rs @@ -22,7 +22,7 @@ pub struct ContactList { mode: ViewMode, dirty: bool, - view: Option>, + view: Option>, id: ComponentId, } diff --git a/ui/src/components/indexer/index.rs b/ui/src/components/indexer/index.rs index 0472e67a1..585b37038 100644 --- a/ui/src/components/indexer/index.rs +++ b/ui/src/components/indexer/index.rs @@ -33,7 +33,7 @@ pub struct Index { dirty: bool, state: IndexState, - content: Box, + content: Box, id: ComponentId, } @@ -117,7 +117,6 @@ impl Component for Index { IndexState::Unfocused => { self.content.draw(grid, area, context); } - //IndexState::Search => unreachable!(), } self.dirty = false; diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index 72a7a1fa5..c557e1d7e 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -112,11 +112,6 @@ impl ListingTrait for CompactListing { return; } let i = self.get_envelope_under_cursor(idx, context); - let account = &context.accounts[self.cursor_pos.0]; - let is_seen = { - let root_envelope: &Envelope = &account.get_env(&i); - root_envelope.is_seen() - }; let fg_color = self.data_columns.columns[0][(0, idx)].fg(); let bg_color = if self.cursor_pos.2 == idx { @@ -128,7 +123,6 @@ impl ListingTrait for CompactListing { }; let (upper_left, bottom_right) = area; - let (width, height) = self.data_columns.columns[3].size(); change_colors(grid, area, fg_color, bg_color); let mut x = get_x(upper_left) + self.data_columns.widths[0] diff --git a/ui/src/components/mail/listing/thread.rs b/ui/src/components/mail/listing/thread.rs index e9fb9d29d..6a1169e22 100644 --- a/ui/src/components/mail/listing/thread.rs +++ b/ui/src/components/mail/listing/thread.rs @@ -502,12 +502,8 @@ impl Component for ThreadListing { false } else { let account = &mut context.accounts[self.cursor_pos.0]; - let (hash, is_seen) = { - let envelope: &Envelope = - &account.get_env(&self.locations[self.cursor_pos.2]); - (envelope.hash(), envelope.is_seen()) - }; - is_seen + let envelope: &Envelope = &account.get_env(&self.locations[self.cursor_pos.2]); + envelope.is_seen() } }; diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index 0e7a24beb..a8cc3d804 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -68,7 +68,7 @@ impl ViewMode { pub struct MailView { coordinates: (usize, usize, EnvelopeHash), pager: Option, - subview: Option>, + subview: Option>, dirty: bool, mode: ViewMode, expand_headers: bool, @@ -89,7 +89,7 @@ impl MailView { pub fn new( coordinates: (usize, usize, EnvelopeHash), pager: Option, - subview: Option>, + subview: Option>, ) -> Self { MailView { coordinates, diff --git a/ui/src/components/mail/view/envelope.rs b/ui/src/components/mail/view/envelope.rs index 3cb4a5162..58e49a6d3 100644 --- a/ui/src/components/mail/view/envelope.rs +++ b/ui/src/components/mail/view/envelope.rs @@ -48,7 +48,7 @@ impl ViewMode { #[derive(Debug)] pub struct EnvelopeView { pager: Option, - subview: Option>, + subview: Option>, dirty: bool, mode: ViewMode, wrapper: EnvelopeWrapper, @@ -69,7 +69,7 @@ impl EnvelopeView { pub fn new( wrapper: EnvelopeWrapper, pager: Option, - subview: Option>, + subview: Option>, account_pos: usize, ) -> Self { EnvelopeView { diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index b150627af..d1eb7409c 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -30,8 +30,8 @@ pub use self::widgets::*; /// A horizontally split in half container. #[derive(Debug)] pub struct HSplit { - top: Box, - bottom: Box, + top: Box, + bottom: Box, show_divider: bool, ratio: usize, // bottom/whole height * 100 id: ComponentId, @@ -46,8 +46,8 @@ impl fmt::Display for HSplit { impl HSplit { pub fn new( - top: Box, - bottom: Box, + top: Box, + bottom: Box, ratio: usize, show_divider: bool, ) -> Self { @@ -125,8 +125,8 @@ impl Component for HSplit { /// A vertically split in half container. #[derive(Debug)] pub struct VSplit { - left: Box, - right: Box, + left: Box, + right: Box, show_divider: bool, prev_visibility: (bool, bool), /// This is the width of the right container to the entire width. @@ -143,8 +143,8 @@ impl fmt::Display for VSplit { impl VSplit { pub fn new( - left: Box, - right: Box, + left: Box, + right: Box, ratio: usize, show_divider: bool, ) -> Self { @@ -602,7 +602,7 @@ impl Component for Pager { /// Status bar. #[derive(Debug)] pub struct StatusBar { - container: Box, + container: Box, status: String, notifications: VecDeque, ex_buffer: Field, @@ -624,7 +624,7 @@ impl fmt::Display for StatusBar { } impl StatusBar { - pub fn new(container: Box) -> Self { + pub fn new(container: Box) -> Self { StatusBar { container, status: String::with_capacity(256), @@ -1120,7 +1120,7 @@ impl Component for Progress { #[derive(Debug)] pub struct Tabbed { pinned: usize, - children: Vec>, + children: Vec>, cursor_pos: usize, show_shortcuts: bool, @@ -1130,7 +1130,7 @@ pub struct Tabbed { } impl Tabbed { - pub fn new(children: Vec>) -> Self { + pub fn new(children: Vec>) -> Self { let pinned = children.len(); Tabbed { pinned, @@ -1194,7 +1194,7 @@ impl Tabbed { context.dirty_areas.push_back(area); } - pub fn add_component(&mut self, new: Box) { + pub fn add_component(&mut self, new: Box) { self.children.push(new); } } diff --git a/ui/src/components/utilities/widgets.rs b/ui/src/components/utilities/widgets.rs index b84f0ea23..387fd906b 100644 --- a/ui/src/components/utilities/widgets.rs +++ b/ui/src/components/utilities/widgets.rs @@ -1,7 +1,7 @@ use super::*; use fnv::FnvHashMap; -type AutoCompleteFn = Box Vec + Send>; +type AutoCompleteFn = Box Vec + Send>; #[derive(Debug, PartialEq)] enum FormFocus { diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index 4f84f8ebe..3a0525ba3 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -317,7 +317,7 @@ impl Account { } fn new_worker( folder: Folder, - backend: &mut Box, + backend: &mut Box, notify_fn: Arc, ) -> Worker { let mailbox_handle = backend.get(&folder); @@ -617,7 +617,7 @@ impl Account { pub fn contains_key(&self, h: EnvelopeHash) -> bool { self.collection.contains_key(&h) } - pub fn operation(&self, h: EnvelopeHash) -> Box { + pub fn operation(&self, h: EnvelopeHash) -> Box { for mailbox in self.folders.values() { match mailbox { MailboxEntry::Available(ref m) | MailboxEntry::Parsing(ref m, _, _) => { diff --git a/ui/src/execute/actions.rs b/ui/src/execute/actions.rs index ec62db907..02074bef2 100644 --- a/ui/src/execute/actions.rs +++ b/ui/src/execute/actions.rs @@ -45,7 +45,7 @@ pub enum ListingAction { #[derive(Debug)] pub enum TabAction { - New(Option>), + New(Option>), NewDraft(usize, Option), Reply((usize, usize, usize), ThreadHash), // thread coordinates (account, mailbox, root_set idx) and thread hash Close, diff --git a/ui/src/state.rs b/ui/src/state.rs index 9fd5ae470..270846084 100644 --- a/ui/src/state.rs +++ b/ui/src/state.rs @@ -21,7 +21,7 @@ /*! The application's state. -The UI crate has an Box-Component-System design. The System part, is also the application's state, so they're both merged in the `State` struct. +The UI crate has an Box-Component-System design. The System part, is also the application's state, so they're both merged in the `State` struct. `State` owns all the Components of the UI. In the application's main event loop, input is handed to the state in the form of `UIEvent` objects which traverse the component graph. Components decide to handle each input or not. @@ -128,7 +128,7 @@ pub struct State { stdout: Option, child: Option, pub mode: UIMode, - components: Vec>, + components: Vec>, pub context: Context, threads: FnvHashMap, thread::JoinHandle<()>)>, work_controller: WorkController, @@ -477,7 +477,7 @@ impl State { ); } } - pub fn register_component(&mut self, component: Box) { + pub fn register_component(&mut self, component: Box) { self.components.push(component); } /// Convert user commands to actions/method calls.