Skip to content

Commit 3c03e1e

Browse files
committed
Remove top level use
1 parent 709e62b commit 3c03e1e

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ edition = "2021"
1414
libc = "0.2"
1515

1616
[target.'cfg(target_os="ios")'.dependencies]
17-
libc = {version = "0.2", default-features = false}
17+
libc = { version = "0.2", default-features = false }
1818

1919
[target.'cfg(windows)'.dependencies]
2020
windows = { version = "0.58.0", features = ["Win32_Storage_FileSystem"] }

src/lib.rs

+14-26
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,10 @@
55
66
use std::fs::File;
77
use std::io;
8-
#[cfg(target_os = "linux")]
9-
use std::path::Path;
108
use std::path::PathBuf;
119

12-
#[cfg(target_os = "linux")]
13-
use std::fs::read_link;
14-
1510
#[cfg(unix)]
1611
use 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.
3814
pub trait FilePath {
@@ -63,13 +39,19 @@ pub trait FilePath {
6339
impl 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

Comments
 (0)