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().
jmap
Manos Pitsidianakis 2019-11-06 14:53:12 +02:00
parent 8ba9500de6
commit f56b89dde3
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 15 additions and 0 deletions

View File

@ -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

View File

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

View File

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

View File

@ -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 {