From 746f37a389fdd17f564684bad64c2180491f0342 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Mon, 6 Nov 2023 19:00:05 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20impl=20fileSystem=20for?= =?UTF-8?q?=20`Arc`=20(#1166)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Impl `FileSystem` for `Arc` when `T` satisfies `FileSystem`, it is useful when the user wants to share the filesystem into multiple threads. --- crates/oxc_resolver/src/file_system.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/oxc_resolver/src/file_system.rs b/crates/oxc_resolver/src/file_system.rs index a676d8d26..fb625d101 100644 --- a/crates/oxc_resolver/src/file_system.rs +++ b/crates/oxc_resolver/src/file_system.rs @@ -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 when T satisfies FileSystem, it is useful when the user wants to share the filesystem into multiple threads. +impl FileSystem for Arc +where + T: FileSystem, +{ + fn read_to_string(&self, path: &Path) -> io::Result { + self.deref().read_to_string(path) + } + + fn metadata(&self, path: &Path) -> io::Result { + self.deref().metadata(path) + } + + fn symlink_metadata(&self, path: &Path) -> io::Result { + self.deref().symlink_metadata(path) + } + + fn canonicalize(&self, path: &Path) -> io::Result { + self.deref().canonicalize(path) + } +}