@@ -10,31 +10,40 @@ use super::IntoSystem;
10
10
/// Implemented for systems that have an [`Observer`] as the first argument.
11
11
///
12
12
/// [`Observer`]: crate::observer::Observer
13
- pub trait ObserverSystem < E : ' static , B : Bundle > :
14
- System < In = Trigger < ' static , E , B > , Out = ( ) > + Send + ' static
13
+ pub trait ObserverSystem < E : ' static , B : Bundle , Out = ( ) > :
14
+ System < In = Trigger < ' static , E , B > , Out = Out > + Send + ' static
15
15
{
16
16
}
17
17
18
- impl < E : ' static , B : Bundle , T : System < In = Trigger < ' static , E , B > , Out = ( ) > + Send + ' static >
19
- ObserverSystem < E , B > for T
18
+ impl <
19
+ E : ' static ,
20
+ B : Bundle ,
21
+ Out ,
22
+ T : System < In = Trigger < ' static , E , B > , Out = Out > + Send + ' static ,
23
+ > ObserverSystem < E , B , Out > for T
20
24
{
21
25
}
22
26
23
27
/// Implemented for systems that convert into [`ObserverSystem`].
24
- pub trait IntoObserverSystem < E : ' static , B : Bundle , M > : Send + ' static {
28
+ pub trait IntoObserverSystem < E : ' static , B : Bundle , M , Out = ( ) > : Send + ' static {
25
29
/// The type of [`System`] that this instance converts into.
26
- type System : ObserverSystem < E , B > ;
30
+ type System : ObserverSystem < E , B , Out > ;
27
31
28
32
/// Turns this value into its corresponding [`System`].
29
33
fn into_system ( this : Self ) -> Self :: System ;
30
34
}
31
35
32
- impl < S : IntoSystem < Trigger < ' static , E , B > , ( ) , M > + Send + ' static , M , E : ' static , B : Bundle >
33
- IntoObserverSystem < E , B , M > for S
36
+ impl <
37
+ S : IntoSystem < Trigger < ' static , E , B > , Out , M > + Send + ' static ,
38
+ M ,
39
+ Out ,
40
+ E : ' static ,
41
+ B : Bundle ,
42
+ > IntoObserverSystem < E , B , M , Out > for S
34
43
where
35
- S :: System : ObserverSystem < E , B > ,
44
+ S :: System : ObserverSystem < E , B , Out > ,
36
45
{
37
- type System = <S as IntoSystem < Trigger < ' static , E , B > , ( ) , M > >:: System ;
46
+ type System = <S as IntoSystem < Trigger < ' static , E , B > , Out , M > >:: System ;
38
47
39
48
fn into_system ( this : Self ) -> Self :: System {
40
49
IntoSystem :: into_system ( this)
@@ -44,23 +53,23 @@ where
44
53
macro_rules! impl_system_function {
45
54
( $( $param: ident) ,* ) => {
46
55
#[ allow( non_snake_case) ]
47
- impl <E : ' static , B : Bundle , Func : Send + Sync + ' static , $( $param: SystemParam ) ,* > SystemParamFunction <fn ( Trigger <E , B >, $( $param, ) * ) > for Func
56
+ impl <E : ' static , B : Bundle , Out , Func : Send + Sync + ' static , $( $param: SystemParam ) ,* > SystemParamFunction <fn ( Trigger <E , B >, $( $param, ) * ) > for Func
48
57
where
49
58
for <' a> & ' a mut Func :
50
- FnMut ( Trigger <E , B >, $( $param) ,* ) +
51
- FnMut ( Trigger <E , B >, $( SystemParamItem <$param>) ,* )
59
+ FnMut ( Trigger <E , B >, $( $param) ,* ) -> Out +
60
+ FnMut ( Trigger <E , B >, $( SystemParamItem <$param>) ,* ) -> Out , Out : ' static
52
61
{
53
62
type In = Trigger <' static , E , B >;
54
- type Out = ( ) ;
63
+ type Out = Out ;
55
64
type Param = ( $( $param, ) * ) ;
56
65
#[ inline]
57
- fn run( & mut self , input: Trigger <' static , E , B >, param_value: SystemParamItem < ( $( $param, ) * ) >) {
66
+ fn run( & mut self , input: Trigger <' static , E , B >, param_value: SystemParamItem < ( $( $param, ) * ) >) -> Out {
58
67
#[ allow( clippy:: too_many_arguments) ]
59
- fn call_inner<E : ' static , B : Bundle , $( $param, ) * >(
60
- mut f: impl FnMut ( Trigger <' static , E , B >, $( $param, ) * ) ,
68
+ fn call_inner<E : ' static , B : Bundle , Out , $( $param, ) * >(
69
+ mut f: impl FnMut ( Trigger <' static , E , B >, $( $param, ) * ) -> Out ,
61
70
input: Trigger <' static , E , B >,
62
71
$( $param: $param, ) *
63
- ) {
72
+ ) -> Out {
64
73
f( input, $( $param, ) * )
65
74
}
66
75
let ( $( $param, ) * ) = param_value;
@@ -71,3 +80,37 @@ macro_rules! impl_system_function {
71
80
}
72
81
73
82
all_tuples ! ( impl_system_function, 0 , 16 , F ) ;
83
+
84
+ #[ cfg( test) ]
85
+ mod tests {
86
+ use crate :: {
87
+ self as bevy_ecs,
88
+ event:: Event ,
89
+ observer:: Trigger ,
90
+ system:: { In , IntoSystem } ,
91
+ world:: World ,
92
+ } ;
93
+
94
+ #[ derive( Event ) ]
95
+ struct TriggerEvent ;
96
+
97
+ #[ test]
98
+ fn test_piped_observer_systems_no_input ( ) {
99
+ fn a ( _: Trigger < TriggerEvent > ) { }
100
+ fn b ( ) { }
101
+
102
+ let mut world = World :: new ( ) ;
103
+ world. observe ( a. pipe ( b) ) ;
104
+ }
105
+
106
+ #[ test]
107
+ fn test_piped_observer_systems_with_inputs ( ) {
108
+ fn a ( _: Trigger < TriggerEvent > ) -> u32 {
109
+ 3
110
+ }
111
+ fn b ( _: In < u32 > ) { }
112
+
113
+ let mut world = World :: new ( ) ;
114
+ world. observe ( a. pipe ( b) ) ;
115
+ }
116
+ }
0 commit comments