use anyhow::{Result, bail}; use turbo_rcstr::RcStr; use turbo_tasks::{ValueDefault, ValueToString, Vc}; use super::{FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent}; use crate::RawDirectoryContent; #[turbo_tasks::value] pub struct VirtualFileSystem { pub name: RcStr, } impl VirtualFileSystem { /// Creates a new [`Vc`]. /// /// NOTE: This function is not a `turbo_tasks::function` to avoid instances /// being equivalent identity-wise. This ensures that a /// [`FileSystemPath`] created from this [`Vc`] /// will never be equivalent, nor be interoperable, with a /// [`FileSystemPath`] created from another /// [`Vc`]. pub fn new() -> Vc { Self::cell(VirtualFileSystem { name: "virtual file system".into(), }) } /// Creates a new [`Vc`] with a name. /// /// NOTE: This function is not a `turbo_tasks::function` to avoid instances /// being equivalent identity-wise. This ensures that a /// [`FileSystemPath`] created from this [`Vc`] /// will never be equivalent, nor be interoperable, with a /// [`FileSystemPath`] created from another /// [`Vc`]. pub fn new_with_name(name: RcStr) -> Vc { Self::cell(VirtualFileSystem { name }) } } impl ValueDefault for VirtualFileSystem { fn value_default() -> Vc { Self::new() } } #[turbo_tasks::value_impl] impl FileSystem for VirtualFileSystem { #[turbo_tasks::function] fn read(&self, _fs_path: FileSystemPath) -> Result> { bail!("Reading is not possible on the virtual file system") } #[turbo_tasks::function] fn read_link(&self, _fs_path: FileSystemPath) -> Result> { bail!("Reading is not possible on the virtual file system") } #[turbo_tasks::function] fn raw_read_dir(&self, _fs_path: FileSystemPath) -> Result> { bail!("Reading is not possible on the virtual file system") } #[turbo_tasks::function] fn write(&self, _fs_path: FileSystemPath, _content: Vc) -> Result> { bail!("Writing is not possible on the virtual file system") } #[turbo_tasks::function] fn write_link(&self, _fs_path: FileSystemPath, _target: Vc) -> Result> { bail!("Writing is not possible on the virtual file system") } #[turbo_tasks::function] fn metadata(&self, _fs_path: FileSystemPath) -> Result> { bail!("Reading is not possible on the virtual file system") } } #[turbo_tasks::value_impl] impl ValueToString for VirtualFileSystem { #[turbo_tasks::function] fn to_string(&self) -> Vc { Vc::cell(self.name.clone()) } }