@@ -31,6 +31,7 @@ particular bits of it, etc.
3131
3232```rust
3333# #![allow(unused_must_use)]
34+ use std::io::fs::PathExtensions;
3435use std::io::{File, fs};
3536
3637let path = Path::new("foo.txt");
@@ -622,8 +623,9 @@ pub fn rmdir(path: &Path) -> IoResult<()> {
622623/// # Example
623624///
624625/// ```rust
625- /// use std::io;
626+ /// use std::io::fs::PathExtensions ;
626627/// use std::io::fs;
628+ /// use std::io;
627629///
628630/// // one possible implementation of fs::walk_dir only visiting files
629631/// fn visit_dirs(dir: &Path, cb: |&Path|) -> io::IoResult<()> {
@@ -868,45 +870,54 @@ impl Seek for File {
868870 }
869871}
870872
871- impl path:: Path {
873+ /// Utility methods for paths.
874+ pub trait PathExtensions {
872875 /// Get information on the file, directory, etc at this path.
873876 ///
874877 /// Consult the `fs::stat` documentation for more info.
875878 ///
876879 /// This call preserves identical runtime/error semantics with `file::stat`.
877- pub fn stat ( & self ) -> IoResult < FileStat > { stat ( self ) }
880+ fn stat ( & self ) -> IoResult < FileStat > ;
878881
879882 /// Get information on the file, directory, etc at this path, not following
880883 /// symlinks.
881884 ///
882885 /// Consult the `fs::lstat` documentation for more info.
883886 ///
884887 /// This call preserves identical runtime/error semantics with `file::lstat`.
885- pub fn lstat ( & self ) -> IoResult < FileStat > { lstat ( self ) }
888+ fn lstat ( & self ) -> IoResult < FileStat > ;
886889
887890 /// Boolean value indicator whether the underlying file exists on the local
888891 /// filesystem. Returns false in exactly the cases where `fs::stat` fails.
889- pub fn exists ( & self ) -> bool {
890- self . stat ( ) . is_ok ( )
891- }
892+ fn exists ( & self ) -> bool ;
892893
893894 /// Whether the underlying implementation (be it a file path, or something
894895 /// else) points at a "regular file" on the FS. Will return false for paths
895896 /// to non-existent locations or directories or other non-regular files
896897 /// (named pipes, etc). Follows links when making this determination.
897- pub fn is_file ( & self ) -> bool {
898- match self . stat ( ) {
899- Ok ( s) => s. kind == io:: TypeFile ,
900- Err ( ..) => false
901- }
902- }
898+ fn is_file ( & self ) -> bool ;
903899
904900 /// Whether the underlying implementation (be it a file path, or something
905901 /// else) is pointing at a directory in the underlying FS. Will return
906902 /// false for paths to non-existent locations or if the item is not a
907903 /// directory (eg files, named pipes, etc). Follows links when making this
908904 /// determination.
909- pub fn is_dir ( & self ) -> bool {
905+ fn is_dir ( & self ) -> bool ;
906+ }
907+
908+ impl PathExtensions for path:: Path {
909+ fn stat ( & self ) -> IoResult < FileStat > { stat ( self ) }
910+ fn lstat ( & self ) -> IoResult < FileStat > { lstat ( self ) }
911+ fn exists ( & self ) -> bool {
912+ self . stat ( ) . is_ok ( )
913+ }
914+ fn is_file ( & self ) -> bool {
915+ match self . stat ( ) {
916+ Ok ( s) => s. kind == io:: TypeFile ,
917+ Err ( ..) => false
918+ }
919+ }
920+ fn is_dir ( & self ) -> bool {
910921 match self . stat ( ) {
911922 Ok ( s) => s. kind == io:: TypeDirectory ,
912923 Err ( ..) => false
0 commit comments