@@ -7,15 +7,15 @@ use crate::{fs, io};
7
7
///
8
8
/// [`std::path::Path`]: https://doc.rust-lang.org/std/path/struct.Path.html
9
9
pub struct Path {
10
- inner : OsStr ,
10
+ inner : std :: path :: Path ,
11
11
}
12
12
13
13
impl Path {
14
14
/// Yields the underlying [`OsStr`] slice.
15
15
///
16
16
/// [`OsStr`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html
17
17
pub fn as_os_str ( & self ) -> & OsStr {
18
- & self . inner
18
+ self . inner . as_os_str ( )
19
19
}
20
20
21
21
/// Returns the canonical, absolute form of the path with all intermediate
@@ -72,8 +72,7 @@ impl Path {
72
72
/// [`Component`]: enum.Component.html
73
73
/// [`CurDir`]: enum.Component.html#variant.CurDir
74
74
pub fn components ( & self ) -> Components < ' _ > {
75
- let path: & std:: path:: Path = self . into ( ) ;
76
- path. components ( )
75
+ self . inner . components ( )
77
76
}
78
77
79
78
/// Directly wraps a string slice as a `Path` slice.
@@ -99,7 +98,7 @@ impl Path {
99
98
/// assert_eq!(from_string, from_path);
100
99
/// ```
101
100
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 ) }
103
102
}
104
103
105
104
/// Converts a `Path` to an owned [`PathBuf`].
@@ -115,7 +114,7 @@ impl Path {
115
114
/// assert_eq!(path_buf, PathBuf::from("foo.txt"));
116
115
/// ```
117
116
pub fn to_path_buf ( & self ) -> PathBuf {
118
- PathBuf :: from ( self . inner . to_os_string ( ) )
117
+ PathBuf :: from ( self . inner . to_path_buf ( ) )
119
118
}
120
119
}
121
120
@@ -137,40 +136,8 @@ impl AsRef<Path> for Path {
137
136
}
138
137
}
139
138
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
-
152
139
impl std:: fmt:: Debug for Path {
153
140
fn fmt ( & self , formatter : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
154
141
std:: fmt:: Debug :: fmt ( & self . inner , formatter)
155
142
}
156
143
}
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
- }
0 commit comments