vfs/async_vfs/
filesystem.rs1use crate::async_vfs::{AsyncVfsPath, SeekAndRead};
4use crate::error::VfsErrorKind;
5use crate::{VfsError, VfsMetadata, VfsResult};
6
7use async_std::io::Write;
8use async_std::stream::Stream;
9use async_trait::async_trait;
10use std::fmt::Debug;
11use std::time::SystemTime;
12
13#[async_trait]
21pub trait AsyncFileSystem: Debug + Sync + Send + 'static {
22 async fn read_dir(
25 &self,
26 path: &str,
27 ) -> VfsResult<Box<dyn Unpin + Stream<Item = String> + Send>>;
28 async fn create_dir(&self, path: &str) -> VfsResult<()>;
32 async fn open_file(&self, path: &str) -> VfsResult<Box<dyn SeekAndRead + Send + Unpin>>;
34 async fn create_file(&self, path: &str) -> VfsResult<Box<dyn Write + Send + Unpin>>;
36 async fn append_file(&self, path: &str) -> VfsResult<Box<dyn Write + Send + Unpin>>;
38 async fn metadata(&self, path: &str) -> VfsResult<VfsMetadata>;
40 async fn set_creation_time(&self, _path: &str, _time: SystemTime) -> VfsResult<()> {
42 Err(VfsError::from(VfsErrorKind::NotSupported))
43 }
44 async fn set_modification_time(&self, _path: &str, _time: SystemTime) -> VfsResult<()> {
46 Err(VfsError::from(VfsErrorKind::NotSupported))
47 }
48 async fn set_access_time(&self, _path: &str, _time: SystemTime) -> VfsResult<()> {
50 Err(VfsError::from(VfsErrorKind::NotSupported))
51 }
52 async fn exists(&self, path: &str) -> VfsResult<bool>;
54 async fn remove_file(&self, path: &str) -> VfsResult<()>;
56 async fn remove_dir(&self, path: &str) -> VfsResult<()>;
58 async fn copy_file(&self, _src: &str, _dest: &str) -> VfsResult<()> {
60 Err(VfsErrorKind::NotSupported.into())
61 }
62 async fn move_file(&self, _src: &str, _dest: &str) -> VfsResult<()> {
64 Err(VfsErrorKind::NotSupported.into())
65 }
66 async fn move_dir(&self, _src: &str, _dest: &str) -> VfsResult<()> {
68 Err(VfsErrorKind::NotSupported.into())
69 }
70}
71
72impl<T: AsyncFileSystem> From<T> for AsyncVfsPath {
73 fn from(filesystem: T) -> Self {
74 AsyncVfsPath::new(filesystem)
75 }
76}