Commit 9000a3e8 authored by Constantin Berhard's avatar Constantin Berhard
Browse files

rustfmt

parent e8c9ffaf
......@@ -43,7 +43,10 @@ struct Environment {
}
impl Environment {
pub fn handle_events(&mut self, d: Duration, mut handlers: Vec<EventHandler>) -> EventsHandledResult {
pub fn handle_events(&mut self,
d: Duration,
mut handlers: Vec<EventHandler>)
-> EventsHandledResult {
let timeout_chan = timeout_chan(d);
loop {
let events = self.events.clone();
......@@ -67,17 +70,16 @@ impl Environment {
}
unreachable!()
}
fn record_state(&mut self, ev: &Event) {
}
fn record_state(&mut self, ev: &Event) {}
pub fn door_locked(&self) -> bool {
true
}
}
struct EventHandler<'a> {
run: Box<FnMut(Event) -> EventHandlerResult + 'a>
run: Box<FnMut(Event) -> EventHandlerResult + 'a>,
}
impl<'a> EventHandler<'a> {
......@@ -86,33 +88,41 @@ impl<'a> EventHandler<'a> {
{
EventHandler { run: Box::new(f) }
}
fn new_boxed(f: Box<FnMut(Event) -> EventHandlerResult + 'a>) -> Self
{
fn new_boxed(f: Box<FnMut(Event) -> EventHandlerResult + 'a>) -> Self {
EventHandler { run: f }
}
fn new_safe<F>(mut f: F) -> Self
where F: FnMut(Event) + 'a
{
EventHandler { run: Box::new(move |ev| { f(ev); EventHandlerResult::Continue }) }
EventHandler {
run: Box::new(move |ev| {
f(ev);
EventHandlerResult::Continue
}),
}
}
fn new_safe_boxed(mut f: Box<FnMut(Event) + 'a>) -> Self
{
EventHandler { run: Box::new(move |ev| { f(ev); EventHandlerResult::Continue }) }
fn new_safe_boxed(mut f: Box<FnMut(Event) + 'a>) -> Self {
EventHandler {
run: Box::new(move |ev| {
f(ev);
EventHandlerResult::Continue
}),
}
}
}
fn user_command_reject_handler(ev: Event) {
}
fn user_command_reject_handler(ev: Event) {}
impl State {
fn new<F>(f: F) -> State
where F: FnOnce(Actors, &mut Environment) -> (Actors, Option<State>) + 'static {
where F: FnOnce(Actors, &mut Environment) -> (Actors, Option<State>) + 'static
{
State { run: Box::new(f) }
}
fn new_locking() -> Self {
Self::new(|mut actors, env| {
// TODO: abort if already locked
......@@ -124,7 +134,8 @@ impl State {
lock_actor.act(LockAction::Release);
lock_actor
});
let r = env.handle_events(Duration::from_secs(1), vec![
let r = env.handle_events(Duration::from_secs(1),
vec![
EventHandler::new_safe(user_command_reject_handler),
EventHandler::new(|ev| {
match ev {
......
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