use std::error; use std::result; use session::{Request, Object}; pub enum Realize { OneItem(Object), OneItemAndDone(Object), Reject(String), Empty, Done, } impl<'a> From<&'a str> for Realize { fn from(s: &'a str) -> Self { Realize::Reject(s.to_owned()) } } impl From for Realize { fn from(s: String) -> Self { Realize::Reject(s) } } pub enum Shortcut { Tuned, Reject(String), Done, } impl<'a> From<&'a str> for Shortcut { fn from(s: &'a str) -> Self { Shortcut::Reject(s.to_owned()) } } impl From for Shortcut { fn from(s: String) -> Self { Shortcut::Reject(s) } } pub type Result = result::Result>; pub trait Worker { fn prepare(&mut self, _: &mut T, _: Request) -> Result { Ok(Shortcut::Tuned) } fn realize(&mut self, _: &mut T, _: Option) -> Result { unimplemented!(); } } pub struct RejectWorker { reason: String, } impl RejectWorker { pub fn new(reason: String) -> Self { RejectWorker {reason: reason} } } impl Worker for RejectWorker { fn realize(&mut self, _: &mut T, _: Option) -> Result { Ok(Realize::Reject(self.reason.clone())) } }