/
action.rs
53 lines (43 loc) 路 1.02 KB
/
action.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::{fmt::Debug, time::Duration};
pub use crate::action::{
change_color_to::ChangeColorTo, empty::Empty, fork::Fork, hide::Hide, move_by::MoveBy,
sequence::Sequence, set_color::SetColor, set_facing::SetFacing, show::Show, sleep::Sleep,
};
mod change_color_to;
mod empty;
mod fork;
mod hide;
mod move_by;
mod sequence;
mod set_color;
mod set_facing;
mod show;
mod sleep;
pub trait Action: Debug {
fn begin(&mut self) {}
fn update(&mut self, _dtime: Duration) {}
fn end(&mut self) {}
fn duration(&self) -> Duration {
Duration::new(0, 0)
}
fn try_fork(&mut self) -> Option<Box<dyn Action>> {
None
}
fn is_finished(&self) -> bool {
true
}
}
/// Just a helper trait to replace
/// `Box::new(action::Empty::new())`
/// with
/// `action::Empty::new().boxed()`.
pub trait Boxed {
type Out;
fn boxed(self) -> Self::Out;
}
impl<T: 'static + Action> Boxed for T {
type Out = Box<dyn Action>;
fn boxed(self) -> Self::Out {
Box::new(self)
}
}