-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfs.rs
49 lines (36 loc) · 1.29 KB
/
fs.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
40
41
42
43
44
45
46
47
48
49
use std::path::Path;
use async_trait::async_trait;
pub mod in_memory;
pub mod local;
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct FileSystemError(#[from] anyhow::Error);
impl From<std::io::Error> for FileSystemError {
fn from(error: std::io::Error) -> Self {
Self(error.into())
}
}
pub type FileSystemResult<T> = Result<T, FileSystemError>;
#[async_trait]
pub trait FileSystem {
async fn create_dir(&self, path: impl AsRef<Path> + Send) -> FileSystemResult<()>;
async fn create_dir_all(&self, path: impl AsRef<Path> + Send) -> FileSystemResult<()>;
async fn read(&self, path: impl AsRef<Path> + Send) -> FileSystemResult<Vec<u8>>;
async fn read_to_string(&self, path: impl AsRef<Path> + Send) -> FileSystemResult<String>;
async fn write(
&self,
path: impl AsRef<Path> + Send,
contents: impl AsRef<[u8]> + Send,
) -> FileSystemResult<()>;
async fn append(
&self,
path: impl AsRef<Path> + Send,
contents: impl AsRef<[u8]> + Send,
) -> FileSystemResult<()>;
async fn copy(
&self,
from: impl AsRef<Path> + Send,
to: impl AsRef<Path> + Send,
) -> FileSystemResult<()>;
async fn set_mode(&self, path: impl AsRef<Path> + Send, perm: u32) -> FileSystemResult<()>;
}