melib: remove BackendOpGenerator

embed
Manos Pitsidianakis 2019-07-18 20:14:14 +03:00
parent cfb6fd3fde
commit 14f1527e61
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 3 additions and 25 deletions

View File

@ -2,7 +2,6 @@
//extern crate melib;
//
//use melib::mailbox::backends::maildir::MaildirOp;
//use melib::mailbox::backends::BackendOpGenerator;
//use melib::mailbox::email::Envelope;
//
//extern crate test;

View File

@ -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())
}
}