chain.rs: attempts at more elegant impl
@@ -14,11 +14,11 @@ impl Chain {
pub fn new(handlers: Vec<Box<Handler>>) -> Chain {
// @TODO more elegant implementation?
// perhaps this might be helpful to remove the unwraps: https://www.reddit.com/r/rust/comments/64f9c8/idea_replace_with_is_it_safe/
- let mut dispatcher: Option<DispatcherFn> = None;
+ let mut dispatcher: Option<DispatcherFn> = Some(Box::new(|_| ()));
let mut handlers_rev = handlers;
handlers_rev.reverse();
for h_taken in handlers_rev {
- let d_taken = Rc::new(dispatcher.take().unwrap_or_else(|| Box::new(|_| ())));
+ let d_taken = Rc::new(dispatcher.take().unwrap());
dispatcher = Some(Box::new(move |action| {
d_taken(&action);
h_taken.handle(&action, d_taken.clone());
