@@ -70,6 +70,7 @@ impl<T> IoResultExt<T> for io::Result<T> {
7070pub trait VfsBackend : sealed:: Sealed + Send + ' static {
7171 fn read ( & mut self , path : & Path ) -> io:: Result < Vec < u8 > > ;
7272 fn write ( & mut self , path : & Path , data : & [ u8 ] ) -> io:: Result < ( ) > ;
73+ fn exists ( & mut self , path : & Path ) -> io:: Result < bool > ;
7374 fn read_dir ( & mut self , path : & Path ) -> io:: Result < ReadDir > ;
7475 fn create_dir ( & mut self , path : & Path ) -> io:: Result < ( ) > ;
7576 fn create_dir_all ( & mut self , path : & Path ) -> io:: Result < ( ) > ;
@@ -175,6 +176,11 @@ impl VfsInner {
175176 Ok ( Arc :: new ( contents_str. into ( ) ) )
176177 }
177178
179+ fn exists < P : AsRef < Path > > ( & mut self , path : P ) -> io:: Result < bool > {
180+ let path = path. as_ref ( ) ;
181+ self . backend . exists ( path)
182+ }
183+
178184 fn write < P : AsRef < Path > , C : AsRef < [ u8 ] > > ( & mut self , path : P , contents : C ) -> io:: Result < ( ) > {
179185 let path = path. as_ref ( ) ;
180186 let contents = contents. as_ref ( ) ;
@@ -338,6 +344,17 @@ impl Vfs {
338344 self . inner . lock ( ) . unwrap ( ) . read_dir ( path)
339345 }
340346
347+ /// Return whether the given path exists.
348+ ///
349+ /// Roughly equivalent to [`std::fs::exists`][std::fs::exists].
350+ ///
351+ /// [std::fs::exists]: https://doc.rust-lang.org/stable/std/fs/fn.exists.html
352+ #[ inline]
353+ pub fn exists < P : AsRef < Path > > ( & self , path : P ) -> io:: Result < bool > {
354+ let path = path. as_ref ( ) ;
355+ self . inner . lock ( ) . unwrap ( ) . exists ( path)
356+ }
357+
341358 /// Creates a directory at the provided location.
342359 ///
343360 /// Roughly equivalent to [`std::fs::create_dir`][std::fs::create_dir].
0 commit comments