turbo_tasks_fs/
virtual_fs.rs1use anyhow::{Result, bail};
2use turbo_rcstr::RcStr;
3use turbo_tasks::{ValueDefault, ValueToString, Vc};
4
5use super::{FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent};
6use crate::RawDirectoryContent;
7
8#[turbo_tasks::value]
9pub struct VirtualFileSystem {
10 pub name: RcStr,
11}
12
13impl VirtualFileSystem {
14 pub fn new() -> Vc<Self> {
23 Self::cell(VirtualFileSystem {
24 name: "virtual file system".into(),
25 })
26 }
27
28 pub fn new_with_name(name: RcStr) -> Vc<Self> {
37 Self::cell(VirtualFileSystem { name })
38 }
39}
40
41impl ValueDefault for VirtualFileSystem {
42 fn value_default() -> Vc<Self> {
43 Self::new()
44 }
45}
46
47#[turbo_tasks::value_impl]
48impl FileSystem for VirtualFileSystem {
49 #[turbo_tasks::function]
50 fn read(&self, _fs_path: Vc<FileSystemPath>) -> Result<Vc<FileContent>> {
51 bail!("Reading is not possible on the virtual file system")
52 }
53
54 #[turbo_tasks::function]
55 fn read_link(&self, _fs_path: Vc<FileSystemPath>) -> Result<Vc<LinkContent>> {
56 bail!("Reading is not possible on the virtual file system")
57 }
58
59 #[turbo_tasks::function]
60 fn raw_read_dir(&self, _fs_path: Vc<FileSystemPath>) -> Result<Vc<RawDirectoryContent>> {
61 bail!("Reading is not possible on the virtual file system")
62 }
63
64 #[turbo_tasks::function]
65 fn write(&self, _fs_path: Vc<FileSystemPath>, _content: Vc<FileContent>) -> Result<Vc<()>> {
66 bail!("Writing is not possible on the virtual file system")
67 }
68
69 #[turbo_tasks::function]
70 fn write_link(&self, _fs_path: Vc<FileSystemPath>, _target: Vc<LinkContent>) -> Result<Vc<()>> {
71 bail!("Writing is not possible on the virtual file system")
72 }
73
74 #[turbo_tasks::function]
75 fn metadata(&self, _fs_path: Vc<FileSystemPath>) -> Result<Vc<FileMeta>> {
76 bail!("Reading is not possible on the virtual file system")
77 }
78}
79
80#[turbo_tasks::value_impl]
81impl ValueToString for VirtualFileSystem {
82 #[turbo_tasks::function]
83 fn to_string(&self) -> Vc<RcStr> {
84 Vc::cell(self.name.clone())
85 }
86}