Browse Source

melib: add as_any() method to MailBackend trait

Cast the trait object into an &Any object. Then we can downcast it to
its actual type with downcast_ref().
sql
Manos Pitsidianakis 2 years ago
parent
commit
f56b89dde3
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 3
      melib/src/backends.rs
  2. 4
      melib/src/backends/imap.rs
  3. 4
      melib/src/backends/maildir/backend.rs
  4. 4
      melib/src/backends/mbox.rs

3
melib/src/backends.rs

@ -36,6 +36,7 @@ use self::maildir::MaildirType;
#[cfg(feature = "mbox_backend")]
use self::mbox::MboxType;
use super::email::{Envelope, EnvelopeHash, Flag};
use std::any::Any;
use std::fmt;
use std::fmt::Debug;
use std::ops::Deref;
@ -191,6 +192,8 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
fn folder_operation(&mut self, _path: &str, _op: FolderOperation) -> Result<()> {
Ok(())
}
fn as_any(&self) -> &dyn Any;
}
/// A `BackendOp` manages common operations for the various mail backends. They only live for the

4
melib/src/backends/imap.rs

@ -358,6 +358,10 @@ impl MailBackend for ImapType {
}
Ok(())
}
fn as_any(&self) -> &dyn::std::any::Any {
self
}
}
macro_rules! get_conf_val {

4
melib/src/backends/maildir/backend.rs

@ -552,6 +552,10 @@ impl MailBackend for MaildirType {
folder
)))
}
fn as_any(&self) -> &dyn::std::any::Any {
self
}
}
impl MaildirType {

4
melib/src/backends/mbox.rs

@ -548,6 +548,10 @@ impl MailBackend for MboxType {
fn save(&self, _bytes: &[u8], _folder: &str, _flags: Option<Flag>) -> Result<()> {
unimplemented!();
}
fn as_any(&self) -> &dyn::std::any::Any {
self
}
}
impl MboxType {

Loading…
Cancel
Save