kcl_lib/fs/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Functions for interacting with files on a machine.

#[cfg(not(target_arch = "wasm32"))]
pub mod local;
#[cfg(not(target_arch = "wasm32"))]
pub use local::FileManager;

#[cfg(target_arch = "wasm32")]
#[cfg(not(test))]
pub mod wasm;

use anyhow::Result;
#[cfg(target_arch = "wasm32")]
#[cfg(not(test))]
pub use wasm::FileManager;

#[async_trait::async_trait]
pub trait FileSystem: Clone {
    /// Read a file from the local file system.
    async fn read<P: AsRef<std::path::Path> + std::marker::Send + std::marker::Sync>(
        &self,
        path: P,
        source_range: crate::executor::SourceRange,
    ) -> Result<Vec<u8>, crate::errors::KclError>;

    /// Check if a file exists on the local file system.
    async fn exists<P: AsRef<std::path::Path> + std::marker::Send + std::marker::Sync>(
        &self,
        path: P,
        source_range: crate::executor::SourceRange,
    ) -> Result<bool, crate::errors::KclError>;

    /// Get all the files in a directory recursively.
    async fn get_all_files<P: AsRef<std::path::Path> + std::marker::Send + std::marker::Sync>(
        &self,
        path: P,
        source_range: crate::executor::SourceRange,
    ) -> Result<Vec<std::path::PathBuf>, crate::errors::KclError>;
}