use std::future::Future;
use crate::Result;
use super::types::{OpenMode, ReadReq, WriteReq};
pub trait Vfs: Send + Sync {
type File: VfsFile;
type LockHandle: Send + Sync;
fn open(&self, path: &str, mode: OpenMode) -> impl Future<Output = Result<Self::File>> + Send;
fn remove(&self, path: &str) -> impl Future<Output = Result<()>> + Send;
fn rename(&self, from: &str, to: &str) -> impl Future<Output = Result<()>> + Send;
fn list_dir(&self, path: &str) -> impl Future<Output = Result<Vec<String>>> + Send;
fn mkdir_all(&self, path: &str) -> impl Future<Output = Result<()>> + Send;
fn sync_dir(&self, path: &str) -> impl Future<Output = Result<()>> + Send;
fn lock_exclusive(&self, path: &str) -> impl Future<Output = Result<Self::LockHandle>> + Send;
fn lock_shared(&self, path: &str) -> impl Future<Output = Result<Self::LockHandle>> + Send;
fn root_path(&self) -> Option<&std::path::Path> {
None
}
}
pub trait VfsFile: Send {
fn read_at(&self, offset: u64, buf: &mut [u8]) -> impl Future<Output = Result<usize>> + Send;
fn read_at_vectored(&self, reqs: &mut [ReadReq<'_>])
-> impl Future<Output = Result<()>> + Send;
fn write_at(&mut self, offset: u64, buf: &[u8]) -> impl Future<Output = Result<usize>> + Send;
fn write_at_vectored(
&mut self,
reqs: &[WriteReq<'_>],
) -> impl Future<Output = Result<()>> + Send;
fn sync(&mut self) -> impl Future<Output = Result<()>> + Send;
fn truncate(&mut self, len: u64) -> impl Future<Output = Result<()>> + Send;
fn set_len(&mut self, len: u64) -> impl Future<Output = Result<()>> + Send {
self.truncate(len)
}
fn len(&self) -> impl Future<Output = Result<u64>> + Send;
fn is_empty(&self) -> impl Future<Output = Result<bool>> + Send;
fn supports_direct_io(&self) -> bool;
}