@@ -36,8 +36,7 @@ use std::{
3636} ;
3737
3838use libc:: off_t;
39- #[ allow( deprecated) ]
40- use pin_utils:: unsafe_pinned;
39+ use pin_project_lite:: pin_project;
4140
4241use crate :: {
4342 errno:: Errno ,
@@ -119,8 +118,6 @@ struct AioCb<'a> {
119118
120119#[ allow( deprecated) ]
121120impl < ' a > AioCb < ' a > {
122- pin_utils:: unsafe_unpinned!( aiocb: LibcAiocb ) ;
123-
124121 fn aio_return ( mut self : Pin < & mut Self > ) -> Result < usize > {
125122 self . in_progress = false ;
126123 unsafe {
@@ -164,7 +161,7 @@ impl<'a> AioCb<'a> {
164161 }
165162
166163 fn error ( self : Pin < & mut Self > ) -> Result < ( ) > {
167- let r = unsafe { libc:: aio_error ( & self . aiocb ( ) . 0 ) } ;
164+ let r = unsafe { libc:: aio_error ( & self . aiocb . 0 ) } ;
168165 match r {
169166 0 => Ok ( ( ) ) ,
170167 num if num > 0 => Err ( Errno :: from_raw ( num) ) ,
@@ -366,11 +363,11 @@ pub trait Aio {
366363macro_rules! aio_methods {
367364 ( ) => {
368365 fn cancel( self : Pin <& mut Self >) -> Result <AioCancelStat > {
369- self . aiocb ( ) . cancel( )
366+ self . project ( ) . aiocb . cancel( )
370367 }
371368
372369 fn error( self : Pin <& mut Self >) -> Result <( ) > {
373- self . aiocb ( ) . error( )
370+ self . project ( ) . aiocb . error( )
374371 }
375372
376373 fn fd( & self ) -> BorrowedFd <' a> {
@@ -399,18 +396,20 @@ macro_rules! aio_methods {
399396 aio_methods!( ) ;
400397
401398 fn aio_return( self : Pin <& mut Self >) -> Result <<Self as Aio >:: Output > {
402- self . aiocb ( ) . aio_return( )
399+ self . project ( ) . aiocb . aio_return( )
403400 }
404401
405402 fn submit( mut self : Pin <& mut Self >) -> Result <( ) > {
406- let p: * mut libc:: aiocb = & mut self . as_mut( ) . aiocb( ) . aiocb. 0 ;
403+ let p: * mut libc:: aiocb =
404+ & mut self . as_mut( ) . project( ) . aiocb. get_mut( ) . aiocb. 0 ;
407405 Errno :: result( { unsafe { libc:: $func( p) } } ) . map( |_| {
408- self . aiocb ( ) . set_in_progress( ) ;
406+ self . as_mut ( ) . project ( ) . aiocb . set_in_progress( ) ;
409407 } )
410408 }
411409 } ;
412410}
413411
412+ pin_project ! {
414413/// An asynchronous version of `fsync(2)`.
415414///
416415/// # References
@@ -435,17 +434,18 @@ macro_rules! aio_methods {
435434/// }
436435/// aiof.as_mut().aio_return().expect("aio_fsync failed late");
437436/// ```
438- #[ derive( Debug ) ]
439- #[ repr( transparent) ]
440- pub struct AioFsync < ' a > {
441- aiocb : AioCb < ' a > ,
442- _pin : PhantomPinned ,
437+ #[ derive( Debug ) ]
438+ #[ repr( transparent) ]
439+ pub struct AioFsync <' a> {
440+ #[ pin]
441+ aiocb: AioCb <' a>,
442+ #[ pin]
443+ _pin: PhantomPinned ,
444+ }
443445}
444446
445447#[ allow( deprecated) ]
446448impl < ' a > AioFsync < ' a > {
447- unsafe_pinned ! ( aiocb: AioCb <' a>) ;
448-
449449 /// Returns the operation's fsync mode: data and metadata or data only?
450450 pub fn mode ( & self ) -> AioFsyncMode {
451451 AioFsyncMode :: try_from ( self . aiocb . aiocb . 0 . aio_lio_opcode ) . unwrap ( )
@@ -486,15 +486,15 @@ impl<'a> Aio for AioFsync<'a> {
486486 aio_methods ! ( ) ;
487487
488488 fn aio_return ( self : Pin < & mut Self > ) -> Result < ( ) > {
489- self . aiocb ( ) . aio_return ( ) . map ( drop)
489+ self . project ( ) . aiocb . aio_return ( ) . map ( drop)
490490 }
491491
492492 fn submit ( mut self : Pin < & mut Self > ) -> Result < ( ) > {
493- let aiocb = & mut self . as_mut ( ) . aiocb ( ) . aiocb . 0 ;
493+ let aiocb = & mut self . as_mut ( ) . project ( ) . aiocb . get_mut ( ) . aiocb . 0 ;
494494 let mode = mem:: replace ( & mut aiocb. aio_lio_opcode , 0 ) ;
495495 let p: * mut libc:: aiocb = aiocb;
496496 Errno :: result ( unsafe { libc:: aio_fsync ( mode, p) } ) . map ( |_| {
497- self . aiocb ( ) . set_in_progress ( ) ;
497+ self . as_mut ( ) . project ( ) . aiocb . set_in_progress ( ) ;
498498 } )
499499 }
500500}
@@ -507,6 +507,7 @@ impl AsRef<libc::aiocb> for AioFsync<'_> {
507507 }
508508}
509509
510+ pin_project ! {
510511/// Asynchronously reads from a file descriptor into a buffer
511512///
512513/// # References
@@ -548,18 +549,19 @@ impl AsRef<libc::aiocb> for AioFsync<'_> {
548549/// }
549550/// assert_eq!(rbuf, b"cdef");
550551/// ```
551- #[ derive( Debug ) ]
552- #[ repr( transparent) ]
553- pub struct AioRead < ' a > {
554- aiocb : AioCb < ' a > ,
555- _data : PhantomData < & ' a [ u8 ] > ,
556- _pin : PhantomPinned ,
552+ #[ derive( Debug ) ]
553+ #[ repr( transparent) ]
554+ pub struct AioRead <' a> {
555+ #[ pin]
556+ aiocb: AioCb <' a>,
557+ _data: PhantomData <& ' a [ u8 ] >,
558+ #[ pin]
559+ _pin: PhantomPinned ,
560+ }
557561}
558562
559563#[ allow( deprecated) ]
560564impl < ' a > AioRead < ' a > {
561- unsafe_pinned ! ( aiocb: AioCb <' a>) ;
562-
563565 /// Returns the requested length of the aio operation in bytes
564566 ///
565567 /// This method returns the *requested* length of the operation. To get the
@@ -623,6 +625,8 @@ impl AsRef<libc::aiocb> for AioRead<'_> {
623625 }
624626}
625627
628+ #[ cfg( target_os = "freebsd" ) ]
629+ pin_project ! {
626630/// Asynchronously reads from a file descriptor into a scatter/gather list of buffers.
627631///
628632/// # References
@@ -668,20 +672,20 @@ impl AsRef<libc::aiocb> for AioRead<'_> {
668672/// assert_eq!(rbuf0, b"cdef");
669673/// assert_eq!(rbuf1, b"12");
670674/// ```
671- #[ cfg( target_os = "freebsd" ) ]
672- #[ derive( Debug ) ]
673- #[ repr( transparent) ]
674- pub struct AioReadv < ' a > {
675- aiocb : AioCb < ' a > ,
676- _data : PhantomData < & ' a [ & ' a [ u8 ] ] > ,
677- _pin : PhantomPinned ,
675+ #[ derive( Debug ) ]
676+ #[ repr( transparent) ]
677+ pub struct AioReadv <' a> {
678+ #[ pin]
679+ aiocb: AioCb <' a>,
680+ _data: PhantomData <& ' a [ & ' a [ u8 ] ] >,
681+ #[ pin]
682+ _pin: PhantomPinned ,
683+ }
678684}
679685
680686#[ allow( deprecated) ]
681687#[ cfg( target_os = "freebsd" ) ]
682688impl < ' a > AioReadv < ' a > {
683- unsafe_pinned ! ( aiocb: AioCb <' a>) ;
684-
685689 /// Returns the number of buffers the operation will read into.
686690 pub fn iovlen ( & self ) -> usize {
687691 self . aiocb . aiocb . 0 . aio_nbytes
@@ -748,6 +752,7 @@ impl AsRef<libc::aiocb> for AioReadv<'_> {
748752 }
749753}
750754
755+ pin_project ! {
751756/// Asynchronously writes from a buffer to a file descriptor
752757///
753758/// # References
@@ -781,18 +786,19 @@ impl AsRef<libc::aiocb> for AioReadv<'_> {
781786/// }
782787/// assert_eq!(aiow.as_mut().aio_return().unwrap(), WBUF.len());
783788/// ```
784- #[ derive( Debug ) ]
785- #[ repr( transparent) ]
786- pub struct AioWrite < ' a > {
787- aiocb : AioCb < ' a > ,
788- _data : PhantomData < & ' a [ u8 ] > ,
789- _pin : PhantomPinned ,
789+ #[ derive( Debug ) ]
790+ #[ repr( transparent) ]
791+ pub struct AioWrite <' a> {
792+ #[ pin]
793+ aiocb: AioCb <' a>,
794+ _data: PhantomData <& ' a [ u8 ] >,
795+ #[ pin]
796+ _pin: PhantomPinned ,
797+ }
790798}
791799
792800#[ allow( deprecated) ]
793801impl < ' a > AioWrite < ' a > {
794- unsafe_pinned ! ( aiocb: AioCb <' a>) ;
795-
796802 /// Returns the requested length of the aio operation in bytes
797803 ///
798804 /// This method returns the *requested* length of the operation. To get the
@@ -860,6 +866,8 @@ impl AsRef<libc::aiocb> for AioWrite<'_> {
860866 }
861867}
862868
869+ #[ cfg( target_os = "freebsd" ) ]
870+ pin_project ! {
863871/// Asynchronously writes from a scatter/gather list of buffers to a file descriptor.
864872///
865873/// # References
@@ -898,20 +906,20 @@ impl AsRef<libc::aiocb> for AioWrite<'_> {
898906/// }
899907/// assert_eq!(aiow.as_mut().aio_return().unwrap(), len);
900908/// ```
901- #[ cfg( target_os = "freebsd" ) ]
902- #[ derive( Debug ) ]
903- #[ repr( transparent) ]
904- pub struct AioWritev < ' a > {
905- aiocb : AioCb < ' a > ,
906- _data : PhantomData < & ' a [ & ' a [ u8 ] ] > ,
907- _pin : PhantomPinned ,
909+ #[ derive( Debug ) ]
910+ #[ repr( transparent) ]
911+ pub struct AioWritev <' a> {
912+ #[ pin]
913+ aiocb: AioCb <' a>,
914+ _data: PhantomData <& ' a [ & ' a [ u8 ] ] >,
915+ #[ pin]
916+ _pin: PhantomPinned ,
917+ }
908918}
909919
910920#[ allow( deprecated) ]
911921#[ cfg( target_os = "freebsd" ) ]
912922impl < ' a > AioWritev < ' a > {
913- unsafe_pinned ! ( aiocb: AioCb <' a>) ;
914-
915923 /// Returns the number of buffers the operation will read into.
916924 pub fn iovlen ( & self ) -> usize {
917925 self . aiocb . aiocb . 0 . aio_nbytes
0 commit comments