use std::future;
use std::future::Future;
use std::pin::Pin;
use crate::error::VfsResult;
use crate::traits::async_vfs::VfsAsync;
use crate::traits::async_vfs::WriteSupportingVfsAsync;
use crate::traits::vfs::PathType;
use crate::traits::vfs::VfsCore;
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
pub trait ReadFromAsync<'a, Vfs: VfsAsync + ?Sized + 'a>: Sized + 'a {
type Future: Future<Output = VfsResult<Self, Vfs>> + Send + Unpin + 'a
where
Self: 'a;
fn read_from_async(
path: <<Vfs as VfsCore>::Path as PathType>::OwnedPath,
vfs: Pin<&'a Vfs>,
) -> Self::Future;
}
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
pub trait WriteToAsync<'a, Vfs: WriteSupportingVfsAsync + ?Sized + 'a> {
type Future: Future<Output = VfsResult<(), Vfs>> + Send + Unpin + 'a;
fn write_to_async(
self,
path: <<Vfs as VfsCore>::Path as PathType>::OwnedPath,
vfs: Pin<&'a Vfs>,
) -> Self::Future;
}
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
pub trait WriteToAsyncRef<'r, Vfs: WriteSupportingVfsAsync + ?Sized + 'r> {
type Future<'a>: Future<Output = VfsResult<(), Vfs>> + Send + Unpin + 'a
where
Self: 'a,
'r: 'a,
Vfs: 'a;
fn write_to_async_ref<'a>(
&'a self,
path: <<Vfs as VfsCore>::Path as PathType>::OwnedPath,
vfs: Pin<&'a Vfs>,
) -> Self::Future<'a>
where
'r: 'a;
}
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
pub trait FromRefForWriterAsync<'a, Vfs: WriteSupportingVfsAsync + ?Sized + 'a> {
type Inner: ?Sized;
type Wr: WriteToAsync<'a, Vfs> + 'a;
fn from_ref_for_writer_async(value: &'a Self::Inner) -> Self::Wr;
}
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
impl<'a, Vfs: VfsAsync + ?Sized + 'a> ReadFromAsync<'a, Vfs> for () {
type Future = future::Ready<VfsResult<Self, Vfs>>;
fn read_from_async(
_path: <<Vfs as VfsCore>::Path as PathType>::OwnedPath,
_vfs: Pin<&'a Vfs>,
) -> Self::Future {
future::ready(Ok(()))
}
}
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
impl<'a, Vfs: WriteSupportingVfsAsync + ?Sized + 'a> WriteToAsync<'a, Vfs> for () {
type Future = future::Ready<VfsResult<(), Vfs>>;
fn write_to_async(
self,
_path: <<Vfs as VfsCore>::Path as PathType>::OwnedPath,
_vfs: Pin<&'a Vfs>,
) -> Self::Future {
future::ready(Ok(()))
}
}