Browse Source

melib: remove BackendOpGenerator

tags/pre-alpha-0.2.0
Manos Pitsidianakis 4 months ago
parent
commit
14f1527e61
No known key found for this signature in database
2 changed files with 3 additions and 25 deletions
  1. 0
    1
      benches/parse.rs
  2. 3
    24
      melib/src/backends.rs

+ 0
- 1
benches/parse.rs 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;

+ 3
- 24
melib/src/backends.rs 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())
}
}


Loading…
Cancel
Save