1#[cfg(feature = "pipe")]
3#[cfg_attr(docsrs, doc(cfg(feature = "pipe")))]
4pub mod pipe;
5
6#[cfg(feature = "async-pipe")]
8#[cfg_attr(docsrs, doc(cfg(feature = "async-pipe")))]
9pub mod async_pipe;
10
11#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
13#[cfg(any(feature = "pipe", feature = "async-pipe"))]
14#[cfg_attr(docsrs, doc(cfg(any(feature = "pipe", feature = "async-pipe"))))]
15pub enum PipeError {
16 Closed,
18 Eof,
20}
21
22impl PipeError {
23 #[inline]
25 pub const fn is_eof(&self) -> bool {
26 matches!(self, Self::Eof)
27 }
28
29 #[inline]
31 pub const fn is_closed(&self) -> bool {
32 matches!(self, Self::Closed)
33 }
34}
35
36impl core::fmt::Display for PipeError {
37 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
38 match self {
39 PipeError::Closed => write!(f, "Pipe: read/write on closed pipe"),
40 PipeError::Eof => write!(f, "Pipe: EOF"),
41 }
42 }
43}
44
45impl std::error::Error for PipeError {}
46
47pub trait ReadWriter: std::io::Write + std::io::Read {}
49
50impl<T: std::io::Read + std::io::Write> ReadWriter for T {}
51
52pub trait ReadCloser: std::io::Read + Closer {}
54
55impl<T: std::io::Read + Closer> ReadCloser for T {}
56
57pub trait WriteCloser: std::io::Write + Closer {}
59
60impl<T: std::io::Write + Closer> WriteCloser for T {}
61
62pub trait ReadWriteCloser: std::io::Read + Closer {}
64
65pub trait Closer {
70 fn close(&mut self) -> std::io::Result<()>;
72}