1
- use crate :: EnablingCondition ;
2
- use std:: collections:: VecDeque ;
1
+ use std:: { collections:: VecDeque , marker:: PhantomData } ;
3
2
4
3
pub struct Dispatcher < Action , State > {
5
- queue : VecDeque < AnyAction < Action , State > > ,
4
+ queue : VecDeque < Action > ,
5
+ _marker : PhantomData < State > ,
6
6
}
7
7
8
- impl < Action , State > Dispatcher < Action , State > {
8
+ impl < Action , State > Dispatcher < Action , State >
9
+ where
10
+ Action : crate :: EnablingCondition < State > ,
11
+ {
9
12
pub fn new ( ) -> Self {
10
13
Self {
11
14
queue : VecDeque :: new ( ) ,
15
+ _marker : Default :: default ( ) ,
12
16
}
13
17
}
14
18
15
19
pub fn push < T > ( & mut self , action : T )
16
20
where
17
- T : ' static + EnablingCondition < State > + Into < Action > + Clone + Send ,
21
+ T : Into < Action > ,
18
22
{
19
- let wrapped_action = AnyAction :: < Action , State > :: new ( action) ;
20
- self . queue . push_back ( wrapped_action) ;
23
+ self . queue . push_back ( action. into ( ) ) ;
21
24
}
22
25
23
- pub ( crate ) fn pop ( & mut self ) -> Option < AnyAction < Action , State > > {
26
+ pub ( crate ) fn pop ( & mut self ) -> Option < Action > {
24
27
self . queue . pop_front ( )
25
28
}
26
29
@@ -32,39 +35,3 @@ impl<Action, State> Dispatcher<Action, State> {
32
35
. for_each ( |action| self . queue . push_front ( action) ) ;
33
36
}
34
37
}
35
-
36
- trait ActionConvertible < A , S > : EnablingCondition < S > {
37
- fn convert ( & self ) -> A ;
38
- }
39
-
40
- pub ( crate ) struct AnyAction < A , S > {
41
- inner : Box < dyn ActionConvertible < A , S > + Send > ,
42
- }
43
-
44
- impl < A , S > AnyAction < A , S > {
45
- fn new < T > ( action : T ) -> Self
46
- where
47
- T : ' static + ActionConvertible < A , S > + Send ,
48
- {
49
- Self {
50
- inner : Box :: new ( action) ,
51
- }
52
- }
53
-
54
- pub fn is_enabled ( & self , state : & S , time : crate :: Timestamp ) -> bool {
55
- self . inner . is_enabled ( state, time)
56
- }
57
-
58
- pub fn convert ( & self ) -> A {
59
- self . inner . convert ( )
60
- }
61
- }
62
-
63
- impl < T , A , S > ActionConvertible < A , S > for T
64
- where
65
- T : Clone + Into < A > + EnablingCondition < S > ,
66
- {
67
- fn convert ( & self ) -> A {
68
- self . clone ( ) . into ( )
69
- }
70
- }
0 commit comments