chore: 🤖 impl fileSystem for Arc<T> (#1166)

1. Impl `FileSystem` for `Arc<T>` when `T` satisfies `FileSystem`, it is
useful when the user wants to share the filesystem into multiple
threads.
This commit is contained in:
IWANABETHATGUY 2023-11-06 19:00:05 +08:00 committed by GitHub
parent de6150a071
commit 746f37a389
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,8 @@
use std::{
fs, io,
ops::Deref,
path::{Path, PathBuf},
sync::Arc,
};
/// File System abstraction used for `ResolverGeneric`.
@ -94,3 +96,25 @@ impl FileSystem for FileSystemOs {
dunce::canonicalize(path)
}
}
/// Impl FileSystem for Arc<T> when T satisfies FileSystem, it is useful when the user wants to share the filesystem into multiple threads.
impl<T> FileSystem for Arc<T>
where
T: FileSystem,
{
fn read_to_string(&self, path: &Path) -> io::Result<String> {
self.deref().read_to_string(path)
}
fn metadata(&self, path: &Path) -> io::Result<FileMetadata> {
self.deref().metadata(path)
}
fn symlink_metadata(&self, path: &Path) -> io::Result<FileMetadata> {
self.deref().symlink_metadata(path)
}
fn canonicalize(&self, path: &Path) -> io::Result<PathBuf> {
self.deref().canonicalize(path)
}
}