55
66use std:: fs:: File ;
77use std:: io;
8- #[ cfg( target_os = "linux" ) ]
9- use std:: path:: Path ;
108use std:: path:: PathBuf ;
119
12- #[ cfg( target_os = "linux" ) ]
13- use std:: fs:: read_link;
14-
1510#[ cfg( unix) ]
1611use std:: os:: unix:: io:: AsRawFd ;
17- #[ cfg( windows) ]
18- use std:: os:: windows:: io:: AsRawHandle ;
19-
20- #[ cfg( any( target_os = "macos" , target_os = "ios" , windows) ) ]
21- use std:: ffi:: OsString ;
22-
23- #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
24- use std:: os:: unix:: ffi:: OsStringExt ;
25- #[ cfg( windows) ]
26- use std:: os:: windows:: prelude:: * ;
27-
28- #[ cfg( windows) ]
29- use windows:: Win32 :: {
30- Foundation ,
31- Storage :: FileSystem :: { GetFinalPathNameByHandleW , GETFINALPATHNAMEBYHANDLE_FLAGS } ,
32- } ;
33-
34- #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
35- const F_GETPATH : i32 = 50 ;
3612
3713/// An extension trait for `std::fs::File` providing a `path` method.
3814pub trait FilePath {
@@ -63,13 +39,19 @@ pub trait FilePath {
6339impl FilePath for File {
6440 #[ cfg( target_os = "linux" ) ]
6541 fn path ( & self ) -> io:: Result < PathBuf > {
42+ use std:: path:: Path ;
43+
6644 let fd = self . as_raw_fd ( ) ;
6745 let path = Path :: new ( "/proc/self/fd/" ) . join ( fd. to_string ( ) ) ;
68- read_link ( path)
46+ std :: fs :: read_link ( path)
6947 }
7048
7149 #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
7250 fn path ( & self ) -> io:: Result < PathBuf > {
51+ use std:: ffi:: OsString ;
52+ use std:: os:: unix:: ffi:: OsStringExt ;
53+ const F_GETPATH : i32 = 50 ;
54+
7355 let fd = self . as_raw_fd ( ) ;
7456 let mut path = vec ! [ 0 ; libc:: PATH_MAX as usize + 1 ] ;
7557
@@ -84,7 +66,13 @@ impl FilePath for File {
8466 }
8567
8668 #[ cfg( windows) ]
87- fn path ( & self ) -> io:: Result < PathBuf > {
69+ fn path ( & self ) -> std:: io:: Result < PathBuf > {
70+ use std:: os:: windows:: { ffi:: OsStringExt , io:: AsRawHandle } ;
71+ use windows:: Win32 :: {
72+ Foundation ,
73+ Storage :: FileSystem :: { GetFinalPathNameByHandleW , GETFINALPATHNAMEBYHANDLE_FLAGS } ,
74+ } ;
75+
8876 // Call with null to get the required size.
8977 let len = unsafe {
9078 let handle = Foundation :: HANDLE ( self . as_raw_handle ( ) ) ;
0 commit comments