libdd_capabilities/
file.rs1use crate::maybe_send::MaybeSend;
10use core::future::Future;
11
12#[derive(Debug, thiserror::Error)]
13pub enum FileError {
14 #[error("File not found: {0}")]
15 NotFound(String),
16 #[error("Permission denied: {0}")]
17 PermissionDenied(String),
18 #[error("IO error: {0}")]
19 Io(anyhow::Error),
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
28pub struct FileMetadata {
29 pub size: u64,
30 pub inode: Option<u64>,
31 pub is_file: bool,
32 pub is_dir: bool,
33}
34
35pub trait FileCapability: Clone + std::fmt::Debug {
36 fn new() -> Self;
37
38 fn read(&self, path: &str)
39 -> impl Future<Output = Result<bytes::Bytes, FileError>> + MaybeSend;
40
41 fn write(
42 &self,
43 path: &str,
44 contents: bytes::Bytes,
45 ) -> impl Future<Output = Result<(), FileError>> + MaybeSend;
46
47 fn metadata(
48 &self,
49 path: &str,
50 ) -> impl Future<Output = Result<FileMetadata, FileError>> + MaybeSend;
51
52 fn exists(&self, path: &str) -> impl Future<Output = Result<bool, FileError>> + MaybeSend;
53}