Commit b467360d authored by Ralf's avatar Ralf

cargo fmt

parent 54228363
Pipeline #269 skipped
......@@ -10,7 +10,7 @@ pub struct ForwardActor<T> {
}
// TODO keep a handle to the global book keeper in this struct
impl<T: Send+fmt::Debug> Actor<T> for ForwardActor<T> {
impl<T: Send + fmt::Debug> Actor<T> for ForwardActor<T> {
fn act(&mut self, t: T) {
println!("{:?}", t);
unimplemented!();
......
......@@ -7,7 +7,7 @@ pub mod fake;
/// The `Actor` trait defines the interface to act. It works for any
/// type `T` of the parameter describing the action.
pub trait Actor<T> : Send {
pub trait Actor<T>: Send {
/// Run the action described by `t`.
fn act(&mut self, t: T);
}
......
......@@ -43,7 +43,10 @@ pub fn mk_quitting_handler<'a, F>(f: F) -> EventHandler<'a>
pub fn mk_handler<'a, F>(mut f: F) -> EventHandler<'a>
where F: FnMut(Event) + 'a
{
Box::new(move |ev| { f(ev); HandlerResult::Continue })
Box::new(move |ev| {
f(ev);
HandlerResult::Continue
})
}
/// Stores the states of all our sensors. Notice that the state could be
......@@ -100,7 +103,7 @@ impl Environment {
cur_id: 0,
}
}
/// Return an EventSender matching this Environment
pub fn sender(&self) -> EventSender {
EventSender { sender: self.sender.clone() }
......@@ -128,7 +131,8 @@ impl Environment {
// spawn a thread that sends a timeout event with this id in [d] time
thread::spawn(move || {
thread::sleep(d);
// if sending fails, we just ignore that -- it means the timeout is not necessary any more
// if sending fails, we just ignore that -- it means the timeout
// is not necessary any more
let _ = sender.send(EventOrTimer::Timeout(id));
});
// now we are ready to listen for events
......
......@@ -23,7 +23,7 @@ pub struct Actors {
/// using the [Environment]. When done, it has to return back all the actors,
/// and it has to explain whta the next [Situation] is. Returning None will lead
/// to the program being terminated.
pub trait Situation : fmt::Debug {
pub trait Situation: fmt::Debug {
/// The core function of a situation: Run it, handle events, return what
/// happens next.
fn run(&mut self, Actors, &mut Environment) -> (Actors, Option<Box<Situation>>);
......
......@@ -15,7 +15,10 @@ pub struct UnLocking {
impl UnLocking {
pub fn new(locking: bool, remaining_retries: u32) -> UnLocking {
UnLocking { locking: locking, remaining_retries: remaining_retries }
UnLocking {
locking: locking,
remaining_retries: remaining_retries,
}
}
}
......@@ -38,31 +41,27 @@ impl Situation for UnLocking {
});
// for max. 1 second, handle whatever events we see
let r = handle_events_timeout!(env,
Duration::from_secs(1),
mk_handler(handlers::user_command_reject_handler),
mk_quitting_handler(|ev| {
match ev {
Event::DoorLocked(b) if b == locking => {
HandlerResult::QuitSituation
}
_ => HandlerResult::Continue,
}
}));
Duration::from_secs(1),
mk_handler(handlers::user_command_reject_handler),
mk_quitting_handler(|ev| {
match ev {
Event::DoorLocked(b) if b == locking => HandlerResult::QuitSituation,
_ => HandlerResult::Continue,
}
}));
// Either we timed out, or we succeeded in (un)locking
actors.lock = locker.terminate();
(actors,
match r {
EventsResult::ShuttingDown => None,
EventsResult::Timeout =>
{
EventsResult::Timeout => {
if self.remaining_retries > 0 {
Some(Box::new(UnLocking::new(self.locking, self.remaining_retries - 1)))
} else {
None /* FIXME: What do do when all attempts failed? */
}
}
EventsResult::QuitSituation =>
None /* FIXME: Which state to go in next? */
EventsResult::QuitSituation => None, /* FIXME: Which state to go in next? */
})
}
}
......
......@@ -4,4 +4,3 @@ use testing::TestableEvent;
struct BookKeeper {
receiver: Receiver<Box<TestableEvent>>,
}
......@@ -24,4 +24,3 @@ pub enum ActorType {
/// the actor which can buzz open the building door
Buzz,
}
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