use std::pin::Pin;
use crate::error::VfsResult;
use crate::traits::vfs;
use crate::traits::vfs::VfsCore;
use crate::vfs::fs_vfs;
pub trait DirStructure: DirStructureItem {}
pub trait DirStructureItem {
fn read(path: impl AsRef<<fs_vfs::FsVfs as VfsCore>::Path>) -> VfsResult<Self, fs_vfs::FsVfs>
where
Self: ReadFrom<'static, fs_vfs::FsVfs> + Sized,
{
Self::read_from(path.as_ref(), Pin::new(&fs_vfs::FsVfs))
}
fn write<'a, 'vfs: 'a>(
&'a self,
path: impl AsRef<<fs_vfs::FsVfs as VfsCore>::Path>,
) -> VfsResult<(), fs_vfs::FsVfs>
where
Self: WriteTo<'vfs, fs_vfs::FsVfs>,
{
self.write_to(path.as_ref(), Pin::new(&fs_vfs::FsVfs))
}
}
impl<T> DirStructureItem for T {}
pub trait ReadFrom<'vfs, Vfs: vfs::Vfs<'vfs> + ?Sized>: Sized + 'vfs {
fn read_from(path: &Vfs::Path, vfs: Pin<&'vfs Vfs>) -> VfsResult<Self, Vfs>;
}
pub trait WriteTo<'vfs, Vfs: vfs::WriteSupportingVfs<'vfs> + ?Sized> {
fn write_to(&self, path: &Vfs::Path, vfs: Pin<&'vfs Vfs>) -> VfsResult<(), Vfs>;
}
pub trait FromRefForWriter<'a, 'vfs: 'a, Vfs: vfs::WriteSupportingVfs<'vfs> + ?Sized + 'vfs>:
'a
{
type Inner: ?Sized;
type Wr: WriteTo<'vfs, Vfs> + 'a;
fn from_ref_for_writer(value: &'a Self::Inner) -> Self::Wr;
}
pub trait NewtypeToInner {
type Inner;
fn into_inner(self) -> Self::Inner;
}
impl<'a, Vfs: vfs::Vfs<'a>> ReadFrom<'a, Vfs> for () {
fn read_from(_path: &Vfs::Path, _vfs: Pin<&'a Vfs>) -> VfsResult<Self, Vfs> {
Ok(())
}
}
impl<'vfs, Vfs: vfs::WriteSupportingVfs<'vfs>> WriteTo<'vfs, Vfs> for () {
fn write_to(&self, _path: &Vfs::Path, _vfs: Pin<&'vfs Vfs>) -> VfsResult<(), Vfs> {
Ok(())
}
}