@@ -21,10 +21,7 @@ use serde::{Serialize, Deserialize};
2121/// [`std::path::Path`]: https://doc.rust-lang.org/std/path/struct.PathBuf.html
2222#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2323#[ derive( Clone , Debug , Default , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
24- pub struct PathBuf {
25- #[ cfg_attr( feature = "serde" , serde( flatten) ) ]
26- inner : std:: path:: PathBuf ,
27- }
24+ pub struct PathBuf ( std:: path:: PathBuf ) ;
2825
2926impl PathBuf {
3027 /// Allocates an empty `PathBuf`.
@@ -53,7 +50,7 @@ impl PathBuf {
5350 /// assert_eq!(Path::new("/test"), p.as_path());
5451 /// ```
5552 pub fn as_path ( & self ) -> & Path {
56- self . inner . as_path ( ) . into ( )
53+ self . 0 . as_path ( ) . into ( )
5754 }
5855
5956 /// Extends `self` with `path`.
@@ -88,7 +85,7 @@ impl PathBuf {
8885 /// assert_eq!(path, PathBuf::from("/etc"));
8986 /// ```
9087 pub fn push < P : AsRef < Path > > ( & mut self , path : P ) {
91- self . inner . push ( path. as_ref ( ) )
88+ self . 0 . push ( path. as_ref ( ) )
9289 }
9390
9491 /// Truncates `self` to [`self.parent`].
@@ -112,7 +109,7 @@ impl PathBuf {
112109 /// assert_eq!(Path::new("/"), p);
113110 /// ```
114111 pub fn pop ( & mut self ) -> bool {
115- self . inner . pop ( )
112+ self . 0 . pop ( )
116113 }
117114
118115 /// Updates [`self.file_name`] to `file_name`.
@@ -142,7 +139,7 @@ impl PathBuf {
142139 /// assert!(buf == PathBuf::from("/baz.txt"));
143140 /// ```
144141 pub fn set_file_name < S : AsRef < OsStr > > ( & mut self , file_name : S ) {
145- self . inner . set_file_name ( file_name)
142+ self . 0 . set_file_name ( file_name)
146143 }
147144
148145 /// Updates [`self.extension`] to `extension`.
@@ -171,7 +168,7 @@ impl PathBuf {
171168 /// assert_eq!(Path::new("/feel/the.dark_side"), p.as_path());
172169 /// ```
173170 pub fn set_extension < S : AsRef < OsStr > > ( & mut self , extension : S ) -> bool {
174- self . inner . set_extension ( extension)
171+ self . 0 . set_extension ( extension)
175172 }
176173
177174 /// Consumes the `PathBuf`, returning its internal [`OsString`] storage.
@@ -187,15 +184,15 @@ impl PathBuf {
187184 /// let os_str = p.into_os_string();
188185 /// ```
189186 pub fn into_os_string ( self ) -> OsString {
190- self . inner . into_os_string ( )
187+ self . 0 . into_os_string ( )
191188 }
192189
193190 /// Converts this `PathBuf` into a [boxed][`Box`] [`Path`].
194191 ///
195192 /// [`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html
196193 /// [`Path`]: struct.Path.html
197194 pub fn into_boxed_path ( self ) -> Box < Path > {
198- let rw = Box :: into_raw ( self . inner . into_boxed_path ( ) ) as * mut Path ;
195+ let rw = Box :: into_raw ( self . 0 . into_boxed_path ( ) ) as * mut Path ;
199196 unsafe { Box :: from_raw ( rw) }
200197 }
201198}
@@ -227,13 +224,13 @@ impl<T: ?Sized + AsRef<OsStr>> From<&T> for PathBuf {
227224
228225impl From < OsString > for PathBuf {
229226 fn from ( s : OsString ) -> PathBuf {
230- PathBuf { inner : s. into ( ) }
227+ PathBuf ( s. into ( ) )
231228 }
232229}
233230
234231impl From < PathBuf > for OsString {
235232 fn from ( path_buf : PathBuf ) -> OsString {
236- path_buf. inner . into ( )
233+ path_buf. 0 . into ( )
237234 }
238235}
239236
@@ -269,7 +266,7 @@ impl Deref for PathBuf {
269266 type Target = Path ;
270267
271268 fn deref ( & self ) -> & Path {
272- Path :: new ( & self . inner )
269+ Path :: new ( & self . 0 )
273270 }
274271}
275272
@@ -318,7 +315,7 @@ impl From<PathBuf> for Rc<Path> {
318315
319316impl AsRef < OsStr > for PathBuf {
320317 fn as_ref ( & self ) -> & OsStr {
321- self . inner . as_ref ( )
318+ self . 0 . as_ref ( )
322319 }
323320}
324321
@@ -359,18 +356,18 @@ impl<'b, P: AsRef<Path> + 'b> FromStream<P> for PathBuf {
359356
360357impl From < std:: path:: PathBuf > for PathBuf {
361358 fn from ( path : std:: path:: PathBuf ) -> PathBuf {
362- PathBuf { inner : path }
359+ PathBuf ( path)
363360 }
364361}
365362
366363impl Into < std:: path:: PathBuf > for PathBuf {
367364 fn into ( self ) -> std:: path:: PathBuf {
368- self . inner
365+ self . 0
369366 }
370367}
371368
372369impl AsRef < std:: path:: Path > for PathBuf {
373370 fn as_ref ( & self ) -> & std:: path:: Path {
374- self . inner . as_ref ( )
371+ self . 0 . as_ref ( )
375372 }
376373}
0 commit comments