Skip to content

Commit 930b818

Browse files
committed
Use std variants of Path and PathBuf internally
1 parent 3bd6a9d commit 930b818

File tree

2 files changed

+10
-43
lines changed

2 files changed

+10
-43
lines changed

src/path/path.rs

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ use crate::{fs, io};
77
///
88
/// [`std::path::Path`]: https://doc.rust-lang.org/std/path/struct.Path.html
99
pub struct Path {
10-
inner: OsStr,
10+
inner: std::path::Path,
1111
}
1212

1313
impl Path {
1414
/// Yields the underlying [`OsStr`] slice.
1515
///
1616
/// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html
1717
pub fn as_os_str(&self) -> &OsStr {
18-
&self.inner
18+
self.inner.as_os_str()
1919
}
2020

2121
/// Returns the canonical, absolute form of the path with all intermediate
@@ -72,8 +72,7 @@ impl Path {
7272
/// [`Component`]: enum.Component.html
7373
/// [`CurDir`]: enum.Component.html#variant.CurDir
7474
pub fn components(&self) -> Components<'_> {
75-
let path: &std::path::Path = self.into();
76-
path.components()
75+
self.inner.components()
7776
}
7877

7978
/// Directly wraps a string slice as a `Path` slice.
@@ -99,7 +98,7 @@ impl Path {
9998
/// assert_eq!(from_string, from_path);
10099
/// ```
101100
pub fn new<S: AsRef<OsStr> + ?Sized>(s: &S) -> &Path {
102-
unsafe { &*(s.as_ref() as *const OsStr as *const Path) }
101+
unsafe { &*(std::path::Path::new(s) as *const std::path::Path as *const Path) }
103102
}
104103

105104
/// Converts a `Path` to an owned [`PathBuf`].
@@ -115,7 +114,7 @@ impl Path {
115114
/// assert_eq!(path_buf, PathBuf::from("foo.txt"));
116115
/// ```
117116
pub fn to_path_buf(&self) -> PathBuf {
118-
PathBuf::from(self.inner.to_os_string())
117+
PathBuf::from(self.inner.to_path_buf())
119118
}
120119
}
121120

@@ -137,40 +136,8 @@ impl AsRef<Path> for Path {
137136
}
138137
}
139138

140-
impl AsRef<Path> for OsStr {
141-
fn as_ref(&self) -> &Path {
142-
Path::new(self)
143-
}
144-
}
145-
146-
impl AsRef<Path> for str {
147-
fn as_ref(&self) -> &Path {
148-
Path::new(self)
149-
}
150-
}
151-
152139
impl std::fmt::Debug for Path {
153140
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
154141
std::fmt::Debug::fmt(&self.inner, formatter)
155142
}
156143
}
157-
158-
impl std::cmp::PartialEq for Path {
159-
fn eq(&self, other: &Path) -> bool {
160-
self.components().eq(other.components())
161-
}
162-
}
163-
164-
impl std::cmp::Eq for Path {}
165-
166-
impl std::cmp::PartialOrd for Path {
167-
fn partial_cmp(&self, other: &Path) -> Option<std::cmp::Ordering> {
168-
self.components().partial_cmp(other.components())
169-
}
170-
}
171-
172-
impl std::cmp::Ord for Path {
173-
fn cmp(&self, other: &Path) -> std::cmp::Ordering {
174-
self.components().cmp(other.components())
175-
}
176-
}

src/path/pathbuf.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ use crate::path::Path;
66
///
77
/// [`std::path::Path`]: https://doc.rust-lang.org/std/path/struct.PathBuf.html
88
pub struct PathBuf {
9-
inner: OsString,
9+
inner: std::path::PathBuf,
1010
}
1111

1212
impl From<std::path::PathBuf> for PathBuf {
1313
fn from(path: std::path::PathBuf) -> PathBuf {
14-
PathBuf {
15-
inner: path.into_os_string(),
16-
}
14+
PathBuf { inner: path }
1715
}
1816
}
1917

@@ -25,7 +23,9 @@ impl Into<std::path::PathBuf> for PathBuf {
2523

2624
impl From<OsString> for PathBuf {
2725
fn from(path: OsString) -> PathBuf {
28-
PathBuf { inner: path }
26+
PathBuf {
27+
inner: std::path::PathBuf::from(path),
28+
}
2929
}
3030
}
3131

0 commit comments

Comments
 (0)