monoio/io/
mod.rs

1//! IO traits
2
3mod async_buf_read;
4mod async_buf_read_ext;
5mod async_read_rent;
6mod async_read_rent_ext;
7mod async_rent_cancelable;
8mod async_rent_cancelable_ext;
9mod async_write_rent;
10mod async_write_rent_ext;
11
12pub mod sink;
13pub mod stream;
14
15pub mod as_fd;
16#[cfg(all(target_os = "linux", feature = "splice"))]
17pub mod splice;
18
19pub use async_buf_read::AsyncBufRead;
20pub use async_buf_read_ext::AsyncBufReadExt;
21pub use async_read_rent::{AsyncReadRent, AsyncReadRentAt};
22pub use async_read_rent_ext::AsyncReadRentExt;
23pub use async_rent_cancelable::{CancelableAsyncReadRent, CancelableAsyncWriteRent};
24pub use async_rent_cancelable_ext::{CancelableAsyncReadRentExt, CancelableAsyncWriteRentExt};
25pub use async_write_rent::{AsyncWriteRent, AsyncWriteRentAt};
26pub use async_write_rent_ext::AsyncWriteRentExt;
27
28mod util;
29
30#[cfg(feature = "poll-io")]
31pub use tokio::io as poll_io;
32pub(crate) use util::operation_canceled;
33#[cfg(all(target_os = "linux", feature = "splice"))]
34pub use util::zero_copy;
35pub use util::{
36    copy, BufReader, BufWriter, CancelHandle, Canceller, OwnedReadHalf, OwnedWriteHalf,
37    PrefixedReadIo, Split, Splitable,
38};
39#[cfg(feature = "poll-io")]
40/// Convert a completion-based io to a poll-based io.
41pub trait IntoPollIo: Sized {
42    /// The poll-based io type.
43    type PollIo;
44
45    /// Convert a completion-based io to a poll-based io(able to get comp_io back).
46    fn try_into_poll_io(self) -> Result<Self::PollIo, (std::io::Error, Self)>;
47
48    /// Convert a completion-based io to a poll-based io.
49    #[inline]
50    fn into_poll_io(self) -> std::io::Result<Self::PollIo> {
51        self.try_into_poll_io().map_err(|(e, _)| e)
52    }
53}
54
55#[cfg(feature = "poll-io")]
56/// Convert a poll-based io to a completion-based io.
57pub trait IntoCompIo: Sized {
58    /// The completion-based io type.
59    type CompIo;
60
61    /// Convert a poll-based io to a completion-based io(able to get poll_io back).
62    fn try_into_comp_io(self) -> Result<Self::CompIo, (std::io::Error, Self)>;
63
64    /// Convert a poll-based io to a completion-based io.
65    #[inline]
66    fn into_comp_io(self) -> std::io::Result<Self::CompIo> {
67        self.try_into_comp_io().map_err(|(e, _)| e)
68    }
69}