1use anyhow::Result;
4
5use crate::SourceRange;
6
7#[cfg(not(target_arch = "wasm32"))]
8pub mod local;
9#[cfg(not(target_arch = "wasm32"))]
10pub use local::FileManager;
11
12#[cfg(target_arch = "wasm32")]
13#[cfg(not(test))]
14pub mod wasm;
15
16#[cfg(target_arch = "wasm32")]
17#[cfg(not(test))]
18pub use wasm::FileManager;
19
20#[async_trait::async_trait]
21pub trait FileSystem: Clone {
22 async fn read<P: AsRef<std::path::Path> + std::marker::Send + std::marker::Sync>(
24 &self,
25 path: P,
26 source_range: SourceRange,
27 ) -> Result<Vec<u8>, crate::errors::KclError>;
28
29 async fn read_to_string<P: AsRef<std::path::Path> + std::marker::Send + std::marker::Sync>(
31 &self,
32 path: P,
33 source_range: SourceRange,
34 ) -> Result<String, crate::errors::KclError>;
35
36 async fn exists<P: AsRef<std::path::Path> + std::marker::Send + std::marker::Sync>(
38 &self,
39 path: P,
40 source_range: SourceRange,
41 ) -> Result<bool, crate::errors::KclError>;
42
43 async fn get_all_files<P: AsRef<std::path::Path> + std::marker::Send + std::marker::Sync>(
45 &self,
46 path: P,
47 source_range: SourceRange,
48 ) -> Result<Vec<std::path::PathBuf>, crate::errors::KclError>;
49}