dir_structure/traits/
asy.rs1use std::future;
4use std::future::Future;
5use std::pin::Pin;
6
7use crate::error::VfsResult;
8use crate::traits::async_vfs::VfsAsync;
9use crate::traits::async_vfs::WriteSupportingVfsAsync;
10use crate::traits::vfs::PathType;
11use crate::traits::vfs::VfsCore;
12
13#[cfg(feature = "async")]
17#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
18pub trait ReadFromAsync<'a, Vfs: VfsAsync + ?Sized + 'a>: Sized + 'a {
19 type Future: Future<Output = VfsResult<Self, Vfs>> + Send + Unpin + 'a
21 where
22 Self: 'a;
23
24 fn read_from_async(
27 path: <<Vfs as VfsCore>::Path as PathType>::OwnedPath,
28 vfs: Pin<&'a Vfs>,
29 ) -> Self::Future;
30}
31
32#[cfg(feature = "async")]
37#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
38pub trait WriteToAsync<'a, Vfs: WriteSupportingVfsAsync + ?Sized + 'a> {
39 type Future: Future<Output = VfsResult<(), Vfs>> + Send + Unpin + 'a;
41
42 fn write_to_async(
44 self,
45 path: <<Vfs as VfsCore>::Path as PathType>::OwnedPath,
46 vfs: Pin<&'a Vfs>,
47 ) -> Self::Future;
48}
49
50#[cfg(feature = "async")]
57#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
58pub trait WriteToAsyncRef<'r, Vfs: WriteSupportingVfsAsync + ?Sized + 'r> {
59 type Future<'a>: Future<Output = VfsResult<(), Vfs>> + Send + Unpin + 'a
61 where
62 Self: 'a,
63 'r: 'a,
64 Vfs: 'a;
65
66 fn write_to_async_ref<'a>(
68 &'a self,
69 path: <<Vfs as VfsCore>::Path as PathType>::OwnedPath,
70 vfs: Pin<&'a Vfs>,
71 ) -> Self::Future<'a>
72 where
73 'r: 'a;
74}
75
76#[cfg(feature = "async")]
78#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
79pub trait FromRefForWriterAsync<'a, Vfs: WriteSupportingVfsAsync + ?Sized + 'a> {
80 type Inner: ?Sized;
82 type Wr: WriteToAsync<'a, Vfs> + 'a;
84
85 fn from_ref_for_writer_async(value: &'a Self::Inner) -> Self::Wr;
88}
89
90#[cfg(feature = "async")]
91#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
92impl<'a, Vfs: VfsAsync + ?Sized + 'a> ReadFromAsync<'a, Vfs> for () {
93 type Future = future::Ready<VfsResult<Self, Vfs>>;
94
95 fn read_from_async(
96 _path: <<Vfs as VfsCore>::Path as PathType>::OwnedPath,
97 _vfs: Pin<&'a Vfs>,
98 ) -> Self::Future {
99 future::ready(Ok(()))
100 }
101}
102
103#[cfg(feature = "async")]
104#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
105impl<'a, Vfs: WriteSupportingVfsAsync + ?Sized + 'a> WriteToAsync<'a, Vfs> for () {
106 type Future = future::Ready<VfsResult<(), Vfs>>;
107
108 fn write_to_async(
109 self,
110 _path: <<Vfs as VfsCore>::Path as PathType>::OwnedPath,
111 _vfs: Pin<&'a Vfs>,
112 ) -> Self::Future {
113 future::ready(Ok(()))
114 }
115}