diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-09 11:54:47 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-15 13:21:14 +0300 |
commit | ecb3fd7f3d5bab2a6f0f7592d2f45928d90fdf56 (patch) | |
tree | 8565f9c9306a9c042b4e43bf5f804a578b86cadb /melib | |
parent | d1d11356db1b3ec261857fc33eb3073c0da097e4 (diff) |
Add dyn keyword to Trait objects
And fix some unused var warnings as well
Diffstat (limited to 'melib')
-rw-r--r-- | melib/src/backends.rs | 27 | ||||
-rw-r--r-- | melib/src/backends/imap.rs | 4 | ||||
-rw-r--r-- | melib/src/backends/imap/watch.rs | 7 | ||||
-rw-r--r-- | melib/src/backends/maildir/backend.rs | 4 | ||||
-rw-r--r-- | melib/src/backends/mbox.rs | 6 | ||||
-rw-r--r-- | melib/src/email.rs | 14 | ||||
-rw-r--r-- | melib/src/email/attachments.rs | 2 | ||||
-rw-r--r-- | melib/src/email/compose.rs | 2 | ||||
-rw-r--r-- | melib/src/email/parser.rs | 2 | ||||
-rw-r--r-- | melib/src/thread.rs | 3 |
10 files changed, 34 insertions, 37 deletions
diff --git a/melib/src/backends.rs b/melib/src/backends.rs index 94863652..fe7ee1a4 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<Fn(&AccountSettings, Box<Fn(&str) -> bool>) -> Box<MailBackend>>; +pub type BackendCreator = + Box<dyn Fn(&AccountSettings, Box<dyn Fn(&str) -> bool>) -> Box<dyn MailBackend>>; /// A hashmap containing all available mail backends. /// An abstraction over any available backends. pub struct Backends { - map: FnvHashMap<std::string::String, Box<Fn() -> BackendCreator>>, + map: FnvHashMap<std::string::String, Box<dyn Fn() -> BackendCreator>>, } impl Default for Backends { @@ -78,7 +79,7 @@ impl Backends { self.map[key]() } - pub fn register(&mut self, key: String, backend: Box<Fn() -> BackendCreator>) { + pub fn register(&mut self, key: String, backend: Box<dyn Fn() -> 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<Fn(RefreshEvent) -> () + Send + Sync>); +pub struct RefreshEventConsumer(Box<dyn Fn(RefreshEvent) -> () + Send + Sync>); impl RefreshEventConsumer { - pub fn new(b: Box<Fn(RefreshEvent) -> () + Send + Sync>) -> Self { + pub fn new(b: Box<dyn Fn(RefreshEvent) -> () + Send + Sync>) -> Self { RefreshEventConsumer(b) } pub fn send(&self, r: RefreshEvent) { @@ -126,7 +127,7 @@ impl RefreshEventConsumer { } } -pub struct NotifyFn(Box<Fn(FolderHash) -> () + Send + Sync>); +pub struct NotifyFn(Box<dyn Fn(FolderHash) -> () + 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<Box<Fn(FolderHash) -> () + Send + Sync>> for NotifyFn { - fn from(kind: Box<Fn(FolderHash) -> () + Send + Sync>) -> Self { +impl From<Box<dyn Fn(FolderHash) -> () + Send + Sync>> for NotifyFn { + fn from(kind: Box<dyn Fn(FolderHash) -> () + Send + Sync>) -> Self { NotifyFn(kind) } } impl NotifyFn { - pub fn new(b: Box<Fn(FolderHash) -> () + Send + Sync>) -> Self { + pub fn new(b: Box<dyn Fn(FolderHash) -> () + 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<Result<Vec<Envelope>>>; fn watch(&self, sender: RefreshEventConsumer) -> Result<()>; fn folders(&self) -> FnvHashMap<FolderHash, Folder>; - fn operation(&self, hash: EnvelopeHash, folder_hash: FolderHash) -> Box<BackendOp>; + fn operation(&self, hash: EnvelopeHash, folder_hash: FolderHash) -> Box<dyn BackendOp>; fn save(&self, bytes: &[u8], folder: &str, flags: Option<Flag>) -> 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<BackendOp>, + op: Box<dyn BackendOp>, } impl ReadOnlyOp { - pub fn new(op: Box<BackendOp>) -> Box<BackendOp> { + pub fn new(op: Box<dyn BackendOp>) -> Box<dyn BackendOp> { Box::new(ReadOnlyOp { op }) } } diff --git a/melib/src/backends/imap.rs b/melib/src/backends/imap.rs index 99a51d71..d68ff490 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<BackendOp> { + fn operation(&self, hash: EnvelopeHash, _folder_hash: FolderHash) -> Box<dyn BackendOp> { 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<Fn(&str) -> bool>) -> Self { + pub fn new(s: &AccountSettings, is_subscribed: Box<dyn Fn(&str) -> 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 8528549f..7819be07 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 9a7b50e7..46b51eec 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<BackendOp> { + fn operation(&self, hash: EnvelopeHash, folder_hash: FolderHash) -> Box<dyn BackendOp> { 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<Fn(&str) -> bool>) -> Self { + pub fn new(settings: &AccountSettings, is_subscribed: Box<dyn Fn(&str) -> bool>) -> Self { let mut folders: FnvHashMap<FolderHash, MaildirFolder> = Default::default(); fn recurse_folders<P: AsRef<Path>>( folders: &mut FnvHashMap<FolderHash, MaildirFolder>, diff --git a/melib/src/backends/mbox.rs b/melib/src/backends/mbox.rs index 84b7a4b4..51d6231f 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<BackendOp> { + fn operation(&self, hash: EnvelopeHash, _folder_hash: FolderHash) -> Box<dyn BackendOp> { 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<Fn(&str) -> bool>) -> Self { + pub fn new(s: &AccountSettings, _is_subscribed: Box<dyn Fn(&str) -> 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 4bfba2ca..1775cb5e 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<BackendOp>, hash: EnvelopeHash) -> Option<Envelope> { + pub fn from_token(mut operation: Box<dyn BackendOp>, hash: EnvelopeHash) -> Option<Envelope> { 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<BackendOp>) -> Result<()> { + pub fn populate_headers_from_token(&mut self, mut operation: Box<dyn BackendOp>) -> Result<()> { let headers = operation.fetch_headers()?; self.populate_headers(headers) } @@ -563,7 +563,7 @@ impl Envelope { let _strings: Vec<String> = self.to.iter().map(|a| format!("{}", a)).collect(); _strings.join(", ") } - pub fn bytes(&self, mut operation: Box<BackendOp>) -> Vec<u8> { + pub fn bytes(&self, mut operation: Box<dyn BackendOp>) -> Vec<u8> { operation .as_bytes() .map(|v| v.into()) @@ -608,7 +608,7 @@ impl Envelope { }) }) } - pub fn body(&self, mut operation: Box<BackendOp>) -> Attachment { + pub fn body(&self, mut operation: Box<dyn BackendOp>) -> 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<chrono::FixedOffset>) { self.timestamp = new_val.timestamp() as UnixTimestamp; } - pub fn set_flag(&mut self, f: Flag, mut operation: Box<BackendOp>) -> Result<()> { + pub fn set_flag(&mut self, f: Flag, mut operation: Box<dyn BackendOp>) -> 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<BackendOp>) -> Result<()> { + pub fn set_seen(&mut self, operation: Box<dyn BackendOp>) -> Result<()> { if !self.flags.contains(Flag::SEEN) { self.set_flag(Flag::SEEN, operation) } else { Ok(()) } } - pub fn set_unseen(&mut self, operation: Box<BackendOp>) -> Result<()> { + pub fn set_unseen(&mut self, operation: Box<dyn BackendOp>) -> 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 04fec24c..bea56b18 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<FnMut(&'a Attachment, &mut Vec<u8>) -> () + 'a>; +type Filter<'a> = Box<dyn FnMut(&'a Attachment, &mut Vec<u8>) -> () + 'a>; fn decode_rec_helper<'a>(a: &'a Attachment, filter: &mut Option<Filter<'a>>) -> Vec<u8> { match a.content_type { diff --git a/melib/src/email/compose.rs b/melib/src/email/compose.rs index b9d915e6..26ca3219 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<BackendOp>) -> Self { + pub fn edit(envelope: &Envelope, mut op: Box<dyn BackendOp>) -> 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 89ea8d4a..28a3c940 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 b0c5d8f6..9e76879d 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!( |