@@ -374,6 +374,28 @@ where
374
374
}
375
375
}
376
376
377
+ impl < MODE , BUFFER , PAYLOAD > Transfer < MODE , BUFFER , PAYLOAD >
378
+ where
379
+ PAYLOAD : TransferPayload ,
380
+ {
381
+ pub ( crate ) fn extract_inner_without_drop ( self ) -> ( BUFFER , PAYLOAD ) {
382
+ // `Transfer` needs to have a `Drop` implementation, because we accept
383
+ // managed buffers that can free their memory on drop. Because of that
384
+ // we can't move out of the `Transfer`'s fields, so we use `ptr::read`
385
+ // and `mem::forget`.
386
+ //
387
+ // NOTE(unsafe) There is no panic branch between getting the resources
388
+ // and forgetting `self`.
389
+ unsafe {
390
+ // We cannot use mem::replace as we do not have valid objects to replace with
391
+ let buffer = ptr:: read ( & self . buffer ) ;
392
+ let payload = ptr:: read ( & self . payload ) ;
393
+ core:: mem:: forget ( self ) ;
394
+ ( buffer, payload)
395
+ }
396
+ }
397
+ }
398
+
377
399
/// Read transfer
378
400
pub struct R ;
379
401
@@ -426,19 +448,10 @@ macro_rules! rx_tx_channel_mapping {
426
448
// before the previous statement, which marks the DMA transfer as done
427
449
atomic:: compiler_fence( Ordering :: SeqCst ) ;
428
450
429
- // `Transfer` needs to have a `Drop` implementation, because we accept
451
+ // `Transfer` has a `Drop` implementation because we accept
430
452
// managed buffers that can free their memory on drop. Because of that
431
- // we can't move out of the `Transfer`'s fields, so we use `ptr::read`
432
- // and `mem::forget`.
433
- //
434
- // NOTE(unsafe) There is no panic branch between getting the resources
435
- // and forgetting `self`.
436
- unsafe {
437
- let buffer = ptr:: read( & self . buffer) ;
438
- let payload = ptr:: read( & self . payload) ;
439
- core:: mem:: forget( self ) ;
440
- ( buffer, payload)
441
- }
453
+ // we can't move out of the `Transfer`'s fields directly.
454
+ self . extract_inner_without_drop( )
442
455
}
443
456
}
444
457
@@ -937,19 +950,10 @@ macro_rules! dma {
937
950
// before the previous statement, which marks the DMA transfer as done
938
951
atomic:: compiler_fence( Ordering :: SeqCst ) ;
939
952
940
- // `Transfer` needs to have a `Drop` implementation, because we accept
953
+ // `Transfer` has a `Drop` implementation because we accept
941
954
// managed buffers that can free their memory on drop. Because of that
942
- // we can't move out of the `Transfer`'s fields, so we use `ptr::read`
943
- // and `mem::forget`.
944
- //
945
- // NOTE(unsafe) There is no panic branch between getting the resources
946
- // and forgetting `self`.
947
- unsafe {
948
- let buffer = ptr:: read( & self . buffer) ;
949
- let payload = ptr:: read( & self . payload) ;
950
- core:: mem:: forget( self ) ;
951
- ( buffer, payload)
952
- }
955
+ // we can't move out of the `Transfer`'s fields directly.
956
+ self . extract_inner_without_drop( )
953
957
}
954
958
}
955
959
@@ -975,19 +979,10 @@ macro_rules! dma {
975
979
// before the previous statement, which marks the DMA transfer as done
976
980
atomic:: compiler_fence( Ordering :: SeqCst ) ;
977
981
978
- // `Transfer` needs to have a `Drop` implementation, because we accept
982
+ // `Transfer` has a `Drop` implementation because we accept
979
983
// managed buffers that can free their memory on drop. Because of that
980
- // we can't move out of the `Transfer`'s fields, so we use `ptr::read`
981
- // and `mem::forget`.
982
- //
983
- // NOTE(unsafe) There is no panic branch between getting the resources
984
- // and forgetting `self`.
985
- unsafe {
986
- let buffer = ptr:: read( & self . buffer) ;
987
- let payload = ptr:: read( & self . payload) ;
988
- core:: mem:: forget( self ) ;
989
- ( buffer, payload)
990
- }
984
+ // we can't move out of the `Transfer`'s fields directly.
985
+ self . extract_inner_without_drop( )
991
986
}
992
987
}
993
988
0 commit comments