@@ -31,6 +31,7 @@ particular bits of it, etc.
31
31
32
32
```rust
33
33
# #![allow(unused_must_use)]
34
+ use std::io::fs::PathExtensions;
34
35
use std::io::{File, fs};
35
36
36
37
let path = Path::new("foo.txt");
@@ -622,8 +623,9 @@ pub fn rmdir(path: &Path) -> IoResult<()> {
622
623
/// # Example
623
624
///
624
625
/// ```rust
625
- /// use std::io;
626
+ /// use std::io::fs::PathExtensions ;
626
627
/// use std::io::fs;
628
+ /// use std::io;
627
629
///
628
630
/// // one possible implementation of fs::walk_dir only visiting files
629
631
/// fn visit_dirs(dir: &Path, cb: |&Path|) -> io::IoResult<()> {
@@ -868,45 +870,54 @@ impl Seek for File {
868
870
}
869
871
}
870
872
871
- impl path:: Path {
873
+ /// Utility methods for paths.
874
+ pub trait PathExtensions {
872
875
/// Get information on the file, directory, etc at this path.
873
876
///
874
877
/// Consult the `fs::stat` documentation for more info.
875
878
///
876
879
/// 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 > ;
878
881
879
882
/// Get information on the file, directory, etc at this path, not following
880
883
/// symlinks.
881
884
///
882
885
/// Consult the `fs::lstat` documentation for more info.
883
886
///
884
887
/// 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 > ;
886
889
887
890
/// Boolean value indicator whether the underlying file exists on the local
888
891
/// 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 ;
892
893
893
894
/// Whether the underlying implementation (be it a file path, or something
894
895
/// else) points at a "regular file" on the FS. Will return false for paths
895
896
/// to non-existent locations or directories or other non-regular files
896
897
/// (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 ;
903
899
904
900
/// Whether the underlying implementation (be it a file path, or something
905
901
/// else) is pointing at a directory in the underlying FS. Will return
906
902
/// false for paths to non-existent locations or if the item is not a
907
903
/// directory (eg files, named pipes, etc). Follows links when making this
908
904
/// 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 {
910
921
match self . stat ( ) {
911
922
Ok ( s) => s. kind == io:: TypeDirectory ,
912
923
Err ( ..) => false
0 commit comments