File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -98,9 +98,10 @@ impl AsRawFd for OwnedFd {
9898
9999impl IntoRawFd for OwnedFd {
100100 #[ inline]
101- fn into_raw_fd ( mut self ) -> RawFd {
102- // Safety: We're consume `self`, so we'll never use it again.
103- unsafe { ManuallyDrop :: take ( & mut self . inner ) } . into_raw_fd ( )
101+ fn into_raw_fd ( self ) -> RawFd {
102+ let raw_fd = self . inner . as_fd ( ) . as_raw_fd ( ) ;
103+ forget ( self ) ;
104+ raw_fd
104105 }
105106}
106107
Original file line number Diff line number Diff line change 1+ #[ cfg( not( target_os = "redox" ) ) ]
2+ #[ test]
3+ fn test_owned ( ) {
4+ use io_lifetimes:: AsFd ;
5+ #[ cfg( unix) ]
6+ use std:: os:: unix:: io:: { AsRawFd , FromRawFd , IntoRawFd } ;
7+ #[ cfg( target_os = "wasi" ) ]
8+ use std:: os:: wasi:: io:: { AsRawFd , FromRawFd , IntoRawFd } ;
9+
10+ let file = rsix:: fs:: openat (
11+ & rsix:: fs:: cwd ( ) ,
12+ "Cargo.toml" ,
13+ rsix:: fs:: OFlags :: RDONLY ,
14+ rsix:: fs:: Mode :: empty ( ) ,
15+ )
16+ . unwrap ( ) ;
17+
18+ let raw = file. as_raw_fd ( ) ;
19+ assert_eq ! ( raw, file. as_fd( ) . as_raw_fd( ) ) ;
20+
21+ let owned: io_lifetimes:: OwnedFd = file. into ( ) ;
22+ let inner = owned. into_raw_fd ( ) ;
23+ assert_eq ! ( raw, inner) ;
24+
25+ let new = unsafe { rsix:: io:: OwnedFd :: from_raw_fd ( inner) } ;
26+ let mut buf = [ 0_u8 ; 4 ] ;
27+ let _ = rsix:: io:: read ( & new, & mut buf) . unwrap ( ) ;
28+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ mod dup2_to_replace_stdio;
55mod epoll;
66mod error;
77mod eventfd;
8+ mod from_into;
89mod isatty;
910mod mmap;
1011#[ cfg( not( target_os = "redox" ) ) ] // redox doesn't have cwd/openat
You can’t perform that action at this time.
0 commit comments