@@ -27,6 +27,18 @@ pub trait FileSystem {
2727
2828 /// Returns `true` if `path` exists.
2929 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+ }
3042}
3143
3244// TODO support untitled files for the LSP use case. Wrap a `str` and `String`
@@ -37,7 +49,7 @@ pub trait FileSystem {
3749///
3850/// The path is guaranteed to be valid UTF-8.
3951#[ repr( transparent) ]
40- #[ derive( Eq , PartialEq , Hash ) ]
52+ #[ derive( Eq , PartialEq , Hash , PartialOrd , Ord ) ]
4153pub struct FileSystemPath ( Utf8Path ) ;
4254
4355impl FileSystemPath {
@@ -95,7 +107,7 @@ impl FileSystemPath {
95107///
96108/// The path is guaranteed to be valid UTF-8.
97109#[ repr( transparent) ]
98- #[ derive( Eq , PartialEq , Clone , Hash ) ]
110+ #[ derive( Eq , PartialEq , Clone , Hash , PartialOrd , Ord ) ]
99111pub struct FileSystemPathBuf ( Utf8PathBuf ) ;
100112
101113impl Default for FileSystemPathBuf {
@@ -109,6 +121,10 @@ impl FileSystemPathBuf {
109121 Self ( Utf8PathBuf :: new ( ) )
110122 }
111123
124+ pub fn from_utf8_path_buf ( path : Utf8PathBuf ) -> Self {
125+ Self ( path)
126+ }
127+
112128 #[ inline]
113129 pub fn as_path ( & self ) -> & FileSystemPath {
114130 FileSystemPath :: new ( & self . 0 )
0 commit comments