@ -155,7 +155,7 @@ pub trait MailBackend: ::std::fmt::Debug {
}
/// A `BackendOp` manages common operations for the various mail backends. They only live for the
/// duration of the operation. They are generated by `BackendOpGenerator` on demand .
/// duration of the operation. They are generated by the `operation` method of `Mailbackend` trait .
///
/// # Motivation
///
@ -171,7 +171,7 @@ pub trait MailBackend: ::std::fmt::Debug {
///
/// # Example
/// ```
/// use melib::mailbox::backends::{BackendOp , BackendOpGenerator };
/// use melib::mailbox::backends::{BackendOp };
/// use melib::Result;
/// use melib::{Envelope, Flag};
///
@ -196,8 +196,7 @@ pub trait MailBackend: ::std::fmt::Debug {
/// }
/// }
///
/// let foogen = BackendOpGenerator::new(Box::new(|| Box::new(FooOp {})));
/// let operation = foogen.generate();
/// let operation = Box::new(FooOp {});
/// assert_eq!("Foobar", &operation.description());
/// ```
pub trait BackendOp : ::std ::fmt ::Debug + ::std ::marker ::Send {
@ -211,26 +210,6 @@ pub trait BackendOp: ::std::fmt::Debug + ::std::marker::Send {
fn set_flag ( & mut self , envelope : & mut Envelope , flag : Flag ) -> Result < ( ) > ;
}
/// `BackendOpGenerator` is a wrapper for a closure that returns a `BackendOp` object
/// See `BackendOp` for details.
/*
* I know this sucks , but that ' s the best way I found that rustc deems safe .
* * /
pub struct BackendOpGenerator ( Box < Fn ( ) -> Box < BackendOp > > ) ;
impl BackendOpGenerator {
pub fn new ( b : Box < Fn ( ) -> Box < BackendOp > > ) -> Self {
BackendOpGenerator ( b )
}
pub fn generate ( & self ) -> Box < BackendOp > {
self . 0 ( )
}
}
unsafe impl Send for BackendOpGenerator { }
unsafe impl Sync for BackendOpGenerator { }
impl fmt ::Debug for BackendOpGenerator {
fn fmt ( & self , f : & mut fmt ::Formatter ) -> fmt ::Result {
let op = self . generate ( ) ;
write! ( f , "BackendOpGenerator: {}" , op . description ( ) )
}
}