@@ -287,38 +287,46 @@ enum Entry {
287
287
Sentinel ,
288
288
}
289
289
290
- impl fmt:: Debug for Entry {
290
+ struct TakenState < ' a > {
291
+ slot : & ' a Cell < State > ,
292
+ state : State ,
293
+ }
294
+
295
+ impl Drop for TakenState < ' _ > {
296
+ fn drop ( & mut self ) {
297
+ self . slot
298
+ . set ( mem:: replace ( & mut self . state , State :: NotifiedTaken ) ) ;
299
+ }
300
+ }
301
+
302
+ impl fmt:: Debug for TakenState < ' _ > {
291
303
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
292
- struct TakenState < ' a > {
293
- state : Option < State > ,
294
- cell : & ' a Cell < State > ,
295
- }
304
+ fmt:: Debug :: fmt ( & self . state , f)
305
+ }
306
+ }
296
307
297
- impl Drop for TakenState < ' _ > {
298
- fn drop ( & mut self ) {
299
- self . cell . set ( self . state . take ( ) . unwrap ( ) ) ;
300
- }
301
- }
308
+ impl PartialEq for TakenState < ' _ > {
309
+ fn eq ( & self , other : & Self ) -> bool {
310
+ self . state == other . state
311
+ }
312
+ }
302
313
303
- impl fmt:: Debug for TakenState < ' _ > {
304
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
305
- fmt:: Debug :: fmt ( self . state . as_ref ( ) . unwrap ( ) , f)
306
- }
307
- }
314
+ impl < ' a > TakenState < ' a > {
315
+ fn new ( slot : & ' a Cell < State > ) -> Self {
316
+ let state = slot. replace ( State :: NotifiedTaken ) ;
317
+ Self { slot, state }
318
+ }
319
+ }
308
320
321
+ impl fmt:: Debug for Entry {
322
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
309
323
match self {
310
- Entry :: Listener { state, next, prev } => {
311
- let taken = TakenState {
312
- state : Some ( state. replace ( State :: Created ) ) ,
313
- cell : state,
314
- } ;
315
-
316
- f. debug_struct ( "Listener" )
317
- . field ( "state" , & taken)
318
- . field ( "prev" , prev)
319
- . field ( "next" , next)
320
- . finish ( )
321
- }
324
+ Entry :: Listener { state, next, prev } => f
325
+ . debug_struct ( "Listener" )
326
+ . field ( "state" , & TakenState :: new ( state) )
327
+ . field ( "prev" , prev)
328
+ . field ( "next" , next)
329
+ . finish ( ) ,
322
330
Entry :: Empty ( next) => f. debug_tuple ( "Empty" ) . field ( next) . finish ( ) ,
323
331
Entry :: Sentinel => f. debug_tuple ( "Sentinel" ) . finish ( ) ,
324
332
}
@@ -327,17 +335,6 @@ impl fmt::Debug for Entry {
327
335
328
336
impl PartialEq for Entry {
329
337
fn eq ( & self , other : & Entry ) -> bool {
330
- struct RestoreState < ' a > {
331
- state : Option < State > ,
332
- cell : & ' a Cell < State > ,
333
- }
334
-
335
- impl Drop for RestoreState < ' _ > {
336
- fn drop ( & mut self ) {
337
- self . cell . set ( self . state . take ( ) . unwrap ( ) ) ;
338
- }
339
- }
340
-
341
338
match ( self , other) {
342
339
(
343
340
Self :: Listener {
@@ -351,17 +348,7 @@ impl PartialEq for Entry {
351
348
next : next2,
352
349
} ,
353
350
) => {
354
- let taken1 = RestoreState {
355
- state : Some ( state1. replace ( State :: Created ) ) ,
356
- cell : state1,
357
- } ;
358
-
359
- let taken2 = RestoreState {
360
- state : Some ( state2. replace ( State :: Created ) ) ,
361
- cell : state2,
362
- } ;
363
-
364
- if taken1. state != taken2. state {
351
+ if TakenState :: new ( state1) != TakenState :: new ( state2) {
365
352
return false ;
366
353
}
367
354
0 commit comments