@@ -27,6 +27,18 @@ pub trait FileSystem {
27
27
28
28
/// Returns `true` if `path` exists.
29
29
fn exists ( & self , path : & FileSystemPath ) -> bool ;
30
+
31
+ /// Returns `true` if `path` exists and is a directory.
32
+ fn is_directory ( & self , path : & FileSystemPath ) -> bool {
33
+ self . metadata ( path)
34
+ . map_or ( false , |metadata| metadata. file_type . is_directory ( ) )
35
+ }
36
+
37
+ /// Returns `true` if `path` exists and is a file.
38
+ fn is_file ( & self , path : & FileSystemPath ) -> bool {
39
+ self . metadata ( path)
40
+ . map_or ( false , |metadata| metadata. file_type . is_file ( ) )
41
+ }
30
42
}
31
43
32
44
// TODO support untitled files for the LSP use case. Wrap a `str` and `String`
@@ -37,7 +49,7 @@ pub trait FileSystem {
37
49
///
38
50
/// The path is guaranteed to be valid UTF-8.
39
51
#[ repr( transparent) ]
40
- #[ derive( Eq , PartialEq , Hash ) ]
52
+ #[ derive( Eq , PartialEq , Hash , PartialOrd , Ord ) ]
41
53
pub struct FileSystemPath ( Utf8Path ) ;
42
54
43
55
impl FileSystemPath {
@@ -95,7 +107,7 @@ impl FileSystemPath {
95
107
///
96
108
/// The path is guaranteed to be valid UTF-8.
97
109
#[ repr( transparent) ]
98
- #[ derive( Eq , PartialEq , Clone , Hash ) ]
110
+ #[ derive( Eq , PartialEq , Clone , Hash , PartialOrd , Ord ) ]
99
111
pub struct FileSystemPathBuf ( Utf8PathBuf ) ;
100
112
101
113
impl Default for FileSystemPathBuf {
@@ -109,6 +121,10 @@ impl FileSystemPathBuf {
109
121
Self ( Utf8PathBuf :: new ( ) )
110
122
}
111
123
124
+ pub fn from_utf8_path_buf ( path : Utf8PathBuf ) -> Self {
125
+ Self ( path)
126
+ }
127
+
112
128
#[ inline]
113
129
pub fn as_path ( & self ) -> & FileSystemPath {
114
130
FileSystemPath :: new ( & self . 0 )
0 commit comments