diff options
author | Luca Casonato <hello@lcas.dev> | 2023-08-08 16:28:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-08 16:28:18 -0400 |
commit | 03e963f57831367a39996c7d88bc9875e97d52d7 (patch) | |
tree | 8920cda4906ad9300550679d2492f0023d0beabc /ext/fs/interface.rs | |
parent | f2e30a6f7999fa6ce4ab789266927e3abbb48e3f (diff) |
chore: rename some helpers on the Fs trait (#20097)
Rename some of the helper methods on the Fs trait to be suffixed with
`_sync` / `_async`, in preparation of the introduction of more async
methods for some helpers.
Also adds a `read_text_file_async` helper to complement the renamed
`read_text_file_sync` helper.
Diffstat (limited to 'ext/fs/interface.rs')
-rw-r--r-- | ext/fs/interface.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/ext/fs/interface.rs b/ext/fs/interface.rs index 14ff54aaa..ca027011f 100644 --- a/ext/fs/interface.rs +++ b/ext/fs/interface.rs @@ -233,25 +233,31 @@ pub trait FileSystem: std::fmt::Debug + MaybeSend + MaybeSync { Ok(buf) } - fn is_file(&self, path: &Path) -> bool { + fn is_file_sync(&self, path: &Path) -> bool { self.stat_sync(path).map(|m| m.is_file).unwrap_or(false) } - fn is_dir(&self, path: &Path) -> bool { + fn is_dir_sync(&self, path: &Path) -> bool { self .stat_sync(path) .map(|m| m.is_directory) .unwrap_or(false) } - fn exists(&self, path: &Path) -> bool { + fn exists_sync(&self, path: &Path) -> bool { self.stat_sync(path).is_ok() } - fn read_to_string(&self, path: &Path) -> FsResult<String> { + fn read_text_file_sync(&self, path: &Path) -> FsResult<String> { let buf = self.read_file_sync(path)?; String::from_utf8(buf).map_err(|err| { std::io::Error::new(std::io::ErrorKind::InvalidData, err).into() }) } + async fn read_text_file_async(&self, path: PathBuf) -> FsResult<String> { + let buf = self.read_file_async(path).await?; + String::from_utf8(buf).map_err(|err| { + std::io::Error::new(std::io::ErrorKind::InvalidData, err).into() + }) + } } |