pty_process/
error.rs

1/// Error type for errors from this crate
2#[derive(Debug)]
3pub enum Error {
4    /// error came from `std::io::Error`
5    Io(std::io::Error),
6    /// error came from `nix::Error`
7    Rustix(rustix::io::Errno),
8    /// unsplit was called on halves of two different ptys
9    #[cfg(feature = "async")]
10    Unsplit(crate::OwnedReadPty, crate::OwnedWritePty),
11}
12
13impl std::fmt::Display for Error {
14    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15        match self {
16            Self::Io(e) => write!(f, "{e}"),
17            Self::Rustix(e) => write!(f, "{e}"),
18            #[cfg(feature = "async")]
19            Self::Unsplit(..) => {
20                write!(f, "unsplit called on halves of two different ptys")
21            }
22        }
23    }
24}
25
26impl std::convert::From<std::io::Error> for Error {
27    fn from(e: std::io::Error) -> Self {
28        Self::Io(e)
29    }
30}
31
32impl std::convert::From<rustix::io::Errno> for Error {
33    fn from(e: rustix::io::Errno) -> Self {
34        Self::Rustix(e)
35    }
36}
37
38impl std::error::Error for Error {
39    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
40        match self {
41            Self::Io(e) => Some(e),
42            Self::Rustix(e) => Some(e),
43            #[cfg(feature = "async")]
44            Self::Unsplit(..) => None,
45        }
46    }
47}
48
49/// Convenience wrapper for `Result`s using [`Error`](Error)
50pub type Result<T> = std::result::Result<T, Error>;