1#[derive(Debug)]
3pub enum Error {
4 Io(std::io::Error),
6 Rustix(rustix::io::Errno),
8 #[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
49pub type Result<T> = std::result::Result<T, Error>;