@@ -95,3 +95,130 @@ fn run_derived_generic_actor() {
9595 std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 50 ) ) ;
9696 }
9797}
98+
99+ #[ derive( Clone , Debug ) ]
100+ pub struct Message < T > {
101+ inner : T ,
102+ }
103+
104+ #[ actor( Message <String >) ]
105+ #[ derive( Clone , Default ) ]
106+ struct GenericMsgActor ;
107+
108+ impl Actor for GenericMsgActor {
109+ type Msg = GenericMsgActorMsg ;
110+
111+ fn supervisor_strategy ( & self ) -> Strategy {
112+ Strategy :: Stop
113+ }
114+
115+ fn recv ( & mut self , ctx : & Context < Self :: Msg > , msg : Self :: Msg , sender : Sender ) {
116+ self . receive ( ctx, msg, sender) ;
117+ ctx. stop ( & ctx. myself ) ;
118+ }
119+ }
120+
121+ impl Receive < Message < String > > for GenericMsgActor {
122+ type Msg = GenericMsgActorMsg ;
123+
124+ fn receive (
125+ & mut self ,
126+ _ctx : & Context < Self :: Msg > ,
127+ msg : Message < String > ,
128+ _sender : Option < BasicActorRef > ,
129+ ) {
130+ println ! ( "{}" , msg. inner) ;
131+ }
132+ }
133+
134+ #[ test]
135+ fn run_generic_message_actor ( ) {
136+ let sys = ActorSystem :: new ( ) . unwrap ( ) ;
137+
138+ let act = sys. actor_of :: < GenericMsgActor > ( "act" ) . unwrap ( ) ;
139+
140+ let msg = GenericMsgActorMsg :: Message ( Message {
141+ inner : "test" . to_string ( ) ,
142+ } ) ;
143+ act. tell ( msg, None ) ;
144+
145+ // wait until all direct children of the user root are terminated
146+ while sys. user_root ( ) . has_children ( ) {
147+ // in order to lower cpu usage, sleep here
148+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 50 ) ) ;
149+ }
150+ }
151+
152+ mod test_mod {
153+ #[ derive( Clone , Debug ) ]
154+ pub struct GenericMessage < T > {
155+ pub inner : T ,
156+ }
157+
158+ #[ derive( Clone , Debug ) ]
159+ pub struct Message ;
160+ }
161+
162+ #[ actor( test_mod:: GenericMessage <String >, test_mod:: Message ) ]
163+ #[ derive( Clone , Default ) ]
164+ struct PathMsgActor ;
165+
166+ impl Actor for PathMsgActor {
167+ type Msg = PathMsgActorMsg ;
168+
169+ fn supervisor_strategy ( & self ) -> Strategy {
170+ Strategy :: Stop
171+ }
172+
173+ fn recv ( & mut self , ctx : & Context < Self :: Msg > , msg : Self :: Msg , sender : Sender ) {
174+ self . receive ( ctx, msg, sender) ;
175+ ctx. stop ( & ctx. myself ) ;
176+ }
177+ }
178+
179+ impl Receive < test_mod:: GenericMessage < String > > for PathMsgActor {
180+ type Msg = PathMsgActorMsg ;
181+
182+ fn receive (
183+ & mut self ,
184+ _ctx : & Context < Self :: Msg > ,
185+ msg : test_mod:: GenericMessage < String > ,
186+ _sender : Option < BasicActorRef > ,
187+ ) {
188+ println ! ( "{}" , msg. inner) ;
189+ }
190+ }
191+
192+ impl Receive < test_mod:: Message > for PathMsgActor {
193+ type Msg = PathMsgActorMsg ;
194+
195+ fn receive (
196+ & mut self ,
197+ _ctx : & Context < Self :: Msg > ,
198+ _msg : test_mod:: Message ,
199+ _sender : Option < BasicActorRef > ,
200+ ) {
201+ println ! ( "message" ) ;
202+ }
203+ }
204+
205+ #[ test]
206+ fn run_path_message_actor ( ) {
207+ let sys = ActorSystem :: new ( ) . unwrap ( ) ;
208+
209+ let act = sys. actor_of :: < PathMsgActor > ( "act" ) . unwrap ( ) ;
210+
211+ let msg = PathMsgActorMsg :: TestModMessage ( test_mod:: Message ) ;
212+ act. tell ( msg, None ) ;
213+
214+ let generic_msg = PathMsgActorMsg :: TestModGenericMessage ( test_mod:: GenericMessage {
215+ inner : "test" . to_string ( ) ,
216+ } ) ;
217+ act. tell ( generic_msg, None ) ;
218+
219+ // wait until all direct children of the user root are terminated
220+ while sys. user_root ( ) . has_children ( ) {
221+ // in order to lower cpu usage, sleep here
222+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 50 ) ) ;
223+ }
224+ }
0 commit comments