Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Hacksaar
rinx
Commits
9000a3e8
Commit
9000a3e8
authored
Feb 14, 2016
by
Constantin Berhard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rustfmt
parent
e8c9ffaf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
20 deletions
+31
-20
src/brain/mod.rs
src/brain/mod.rs
+31
-20
No files found.
src/brain/mod.rs
View file @
9000a3e8
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment