Commit 6eb2f4e1 authored by Ralf's avatar Ralf
Browse files

rustfmt

parent 907836c4
......@@ -33,24 +33,22 @@ macro_rules! handle_events_timeout {
}
impl Environment {
pub fn handle_events(&mut self,
mut handlers: Vec<EventHandler>)
-> EventsResult {
pub fn handle_events(&mut self, mut handlers: Vec<EventHandler>) -> EventsResult {
for ev in self.events.clone() {
match self.handle_event(&mut handlers, ev) {
Some(result) => return result,
_ => {},
_ => {}
}
}
return EventsResult::ShuttingDown;
}
pub fn handle_events_timeout(&mut self,
d: Duration,
mut handlers: Vec<EventHandler>)
-> EventsResult {
d: Duration,
mut handlers: Vec<EventHandler>)
-> EventsResult {
let timeout_chan = timeout_chan(d);
loop {
let events = self.events.clone();
......@@ -71,12 +69,15 @@ impl Environment {
}
unreachable!()
}
fn handle_event(&mut self, handlers: &mut Vec<EventHandler>, ev: Event) -> Option<EventsResult> {
fn handle_event(&mut self,
handlers: &mut Vec<EventHandler>,
ev: Event)
-> Option<EventsResult> {
self.record_state(&ev);
for handler in handlers.iter_mut() {
match handler.run(ev) {
HandlerResult::Continue => {},
HandlerResult::Continue => {}
HandlerResult::QuitLoop => return Some(EventsResult::Quit),
}
}
......@@ -85,9 +86,8 @@ impl Environment {
fn record_state(&mut self, ev: &Event) {
match ev {
&Event::DoorLocked(b) =>
self.door_locked = b,
_ => {},
&Event::DoorLocked(b) => self.door_locked = b,
_ => {}
}
}
......
......@@ -43,7 +43,7 @@ impl<'a> EventHandler<'a> {
}),
}
}
#[inline]
pub fn run(&mut self, ev: Event) -> HandlerResult {
(self.run)(ev)
......
......@@ -43,19 +43,26 @@ impl State for UnLockingState {
let locking = self.locking;
for i in 0..3 {
let locker = Wakeable::new(move |t| {
lock_actor.act(if locking { LockAction::PressLock } else { LockAction::PressUnlock } );
lock_actor.act(if locking {
LockAction::PressLock
} else {
LockAction::PressUnlock
});
t.sleep(Duration::from_millis(100));
lock_actor.act(LockAction::Release);
lock_actor
});
let r = handle_events_timeout!(env, Duration::from_secs(1),
EventHandler::new_safe(user_command_reject_handler),
EventHandler::new(|ev| {
match ev {
Event::DoorLocked(b) if b == locking => HandlerResult::QuitLoop,
_ => HandlerResult::Continue,
}
}));
let r = handle_events_timeout!(env,
Duration::from_secs(1),
EventHandler::new_safe(user_command_reject_handler),
EventHandler::new(|ev| {
match ev {
Event::DoorLocked(b) if b == locking => {
HandlerResult::QuitLoop
}
_ => HandlerResult::Continue,
}
}));
// take back lock_actor to feel complete again
lock_actor = locker.terminate();
if r != EventsResult::Timeout {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment