@@ -4,7 +4,7 @@ use futures::future::FutureExt as _;
44use spawned_rt:: tasks:: { self as rt, mpsc, oneshot} ;
55use std:: { fmt:: Debug , future:: Future , panic:: AssertUnwindSafe } ;
66
7- use super :: error:: GenServerError ;
7+ use crate :: error:: GenServerError ;
88
99#[ derive( Debug ) ]
1010pub struct GenServerHandle < G : GenServer + ' static > {
@@ -93,11 +93,13 @@ pub enum GenServerInMsg<G: GenServer> {
9393
9494pub enum CallResponse < G : GenServer > {
9595 Reply ( G :: State , G :: OutMsg ) ,
96+ Unused ,
9697 Stop ( G :: OutMsg ) ,
9798}
9899
99100pub enum CastResponse < G : GenServer > {
100101 NoReply ( G :: State ) ,
102+ Unused ,
101103 Stop ,
102104}
103105
@@ -181,7 +183,7 @@ where
181183 handle : & GenServerHandle < Self > ,
182184 rx : & mut mpsc:: Receiver < GenServerInMsg < Self > > ,
183185 state : Self :: State ,
184- ) -> impl std :: future :: Future < Output = Result < ( Self :: State , bool ) , GenServerError > > + Send {
186+ ) -> impl Future < Output = Result < ( Self :: State , bool ) , GenServerError > > + Send {
185187 async move {
186188 let message = rx. recv ( ) . await ;
187189
@@ -200,17 +202,21 @@ where
200202 ( true , new_state, Ok ( response) )
201203 }
202204 CallResponse :: Stop ( response) => ( false , state_clone, Ok ( response) ) ,
205+ CallResponse :: Unused => {
206+ tracing:: error!( "GenServer received unexpected CallMessage" ) ;
207+ ( false , state_clone, Err ( GenServerError :: CallMsgUnused ) )
208+ }
203209 } ,
204210 Err ( error) => {
205- tracing:: trace !(
211+ tracing:: error !(
206212 "Error in callback, reverting state - Error: '{error:?}'"
207213 ) ;
208214 ( true , state_clone, Err ( GenServerError :: Callback ) )
209215 }
210216 } ;
211217 // Send response back
212218 if sender. send ( response) . is_err ( ) {
213- tracing:: trace !(
219+ tracing:: error !(
214220 "GenServer failed to send response back, client must have died"
215221 )
216222 } ;
@@ -224,6 +230,10 @@ where
224230 Ok ( response) => match response {
225231 CastResponse :: NoReply ( new_state) => ( true , new_state) ,
226232 CastResponse :: Stop => ( false , state_clone) ,
233+ CastResponse :: Unused => {
234+ tracing:: error!( "GenServer received unexpected CastMessage" ) ;
235+ ( false , state_clone)
236+ }
227237 } ,
228238 Err ( error) => {
229239 tracing:: trace!(
@@ -244,17 +254,21 @@ where
244254
245255 fn handle_call (
246256 & mut self ,
247- message : Self :: CallMsg ,
248- handle : & GenServerHandle < Self > ,
249- state : Self :: State ,
250- ) -> impl std:: future:: Future < Output = CallResponse < Self > > + Send ;
257+ _message : Self :: CallMsg ,
258+ _handle : & GenServerHandle < Self > ,
259+ _state : Self :: State ,
260+ ) -> impl Future < Output = CallResponse < Self > > + Send {
261+ async { CallResponse :: Unused }
262+ }
251263
252264 fn handle_cast (
253265 & mut self ,
254- message : Self :: CastMsg ,
255- handle : & GenServerHandle < Self > ,
256- state : Self :: State ,
257- ) -> impl std:: future:: Future < Output = CastResponse < Self > > + Send ;
266+ _message : Self :: CastMsg ,
267+ _handle : & GenServerHandle < Self > ,
268+ _state : Self :: State ,
269+ ) -> impl Future < Output = CastResponse < Self > > + Send {
270+ async { CastResponse :: Unused }
271+ }
258272}
259273
260274#[ cfg( test) ]
0 commit comments