1#![no_std]
2
3#[cfg(feature = "alloc")]
4extern crate alloc;
5
6pub mod buf;
7#[cfg(feature = "alloc")]
8mod dynamic;
9mod maybe;
10
11use core::future::Future;
12
13pub use buf::{IoBuf, IoBufMut};
14#[cfg(feature = "alloc")]
15pub use dynamic::{
16 error::{BoxedError, Error},
17 DynRead, DynWrite,
18};
19pub use maybe::{MaybeOwned, MaybeSend, MaybeSendFuture, MaybeSync};
20
21pub trait Write: MaybeSend {
22 type Error: core::error::Error + Send + Sync + 'static;
43
44 fn write_all<B: IoBuf>(
45 &mut self,
46 buf: B,
47 ) -> impl Future<Output = (Result<(), Self::Error>, B)> + MaybeSend;
48
49 fn flush(&mut self) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend;
50
51 fn close(&mut self) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend;
52}
53
54pub trait Read: MaybeSend + MaybeSync {
55 type Error: core::error::Error + Send + Sync + 'static;
75
76 fn read_exact_at<B: IoBufMut>(
77 &mut self,
78 buf: B,
79 pos: u64,
80 ) -> impl Future<Output = (Result<(), Self::Error>, B)> + MaybeSend;
81
82 #[cfg(feature = "alloc")]
83 fn read_to_end_at(
84 &mut self,
85 buf: alloc::vec::Vec<u8>,
86 pos: u64,
87 ) -> impl Future<Output = (Result<(), Self::Error>, alloc::vec::Vec<u8>)> + MaybeSend;
88
89 fn size(&self) -> impl Future<Output = Result<u64, Self::Error>> + MaybeSend;
90}
91
92impl<R: Read> Read for &mut R {
93 type Error = R::Error;
94
95 fn read_exact_at<B: IoBufMut>(
96 &mut self,
97 buf: B,
98 pos: u64,
99 ) -> impl Future<Output = (Result<(), Self::Error>, B)> + MaybeSend {
100 R::read_exact_at(self, buf, pos)
101 }
102
103 #[cfg(feature = "alloc")]
104 fn read_to_end_at(
105 &mut self,
106 buf: alloc::vec::Vec<u8>,
107 pos: u64,
108 ) -> impl Future<Output = (Result<(), Self::Error>, alloc::vec::Vec<u8>)> + MaybeSend {
109 R::read_to_end_at(self, buf, pos)
110 }
111
112 fn size(&self) -> impl Future<Output = Result<u64, Self::Error>> + MaybeSend {
113 R::size(self)
114 }
115}
116
117impl<W: Write> Write for &mut W {
118 type Error = W::Error;
119
120 fn write_all<B: IoBuf>(
121 &mut self,
122 buf: B,
123 ) -> impl Future<Output = (Result<(), Self::Error>, B)> + MaybeSend {
124 W::write_all(self, buf)
125 }
126
127 fn flush(&mut self) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend {
128 W::flush(self)
129 }
130
131 fn close(&mut self) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend {
132 W::close(self)
133 }
134}