Skip to main content

panrelease/system/
native_system.rs

1use std::path::{Path, PathBuf};
2
3use crate::system::contract::FileSystem;
4
5#[derive(Default)]
6pub struct NativeSystem;
7
8impl FileSystem for NativeSystem {
9    fn read_string(path: &Path) -> anyhow::Result<String> {
10        let content = std::fs::read_to_string(path)?;
11        Ok(content)
12    }
13
14    fn write_string(path: &Path, content: &str) -> anyhow::Result<()> {
15        std::fs::write(path, content)?;
16        Ok(())
17    }
18
19    fn current_dir() -> anyhow::Result<PathBuf> {
20        Ok(std::env::current_dir()?)
21    }
22
23    fn is_a_dir(path: &Path) -> bool {
24        path.is_dir()
25    }
26
27    fn is_a_file(path: &Path) -> bool {
28        path.is_file()
29    }
30}