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