use crate::async_vfs::{AsyncVfsPath, SeekAndRead};
use crate::error::VfsErrorKind;
use crate::{VfsError, VfsMetadata, VfsResult};
use async_std::io::Write;
use async_std::stream::Stream;
use async_trait::async_trait;
use std::fmt::Debug;
use std::time::SystemTime;
#[async_trait]
pub trait AsyncFileSystem: Debug + Sync + Send + 'static {
async fn read_dir(
&self,
path: &str,
) -> VfsResult<Box<dyn Unpin + Stream<Item = String> + Send>>;
async fn create_dir(&self, path: &str) -> VfsResult<()>;
async fn open_file(&self, path: &str) -> VfsResult<Box<dyn SeekAndRead + Send + Unpin>>;
async fn create_file(&self, path: &str) -> VfsResult<Box<dyn Write + Send + Unpin>>;
async fn append_file(&self, path: &str) -> VfsResult<Box<dyn Write + Send + Unpin>>;
async fn metadata(&self, path: &str) -> VfsResult<VfsMetadata>;
async fn set_creation_time(&self, _path: &str, _time: SystemTime) -> VfsResult<()> {
Err(VfsError::from(VfsErrorKind::NotSupported))
}
async fn set_modification_time(&self, _path: &str, _time: SystemTime) -> VfsResult<()> {
Err(VfsError::from(VfsErrorKind::NotSupported))
}
async fn set_access_time(&self, _path: &str, _time: SystemTime) -> VfsResult<()> {
Err(VfsError::from(VfsErrorKind::NotSupported))
}
async fn exists(&self, path: &str) -> VfsResult<bool>;
async fn remove_file(&self, path: &str) -> VfsResult<()>;
async fn remove_dir(&self, path: &str) -> VfsResult<()>;
async fn copy_file(&self, _src: &str, _dest: &str) -> VfsResult<()> {
Err(VfsErrorKind::NotSupported.into())
}
async fn move_file(&self, _src: &str, _dest: &str) -> VfsResult<()> {
Err(VfsErrorKind::NotSupported.into())
}
async fn move_dir(&self, _src: &str, _dest: &str) -> VfsResult<()> {
Err(VfsErrorKind::NotSupported.into())
}
}
impl<T: AsyncFileSystem> From<T> for AsyncVfsPath {
fn from(filesystem: T) -> Self {
AsyncVfsPath::new(filesystem)
}
}