1use std::{fmt, io};
2
3pub type Result<T> = std::result::Result<T, ErrorKind>;
5
6#[derive(Debug)]
8pub enum ErrorKind {
9 IoError(io::Error),
11 Interrupted,
13 Eof,
15 Aborted,
17}
18
19impl std::error::Error for ErrorKind {
20 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
21 match self {
22 ErrorKind::IoError(e) => Some(e),
23 ErrorKind::Interrupted | ErrorKind::Eof | ErrorKind::Aborted => None,
24 }
25 }
26}
27
28impl fmt::Display for ErrorKind {
29 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 ErrorKind::IoError(e) => write!(fmt, "IoError: {}", e),
32 ErrorKind::Interrupted => write!(fmt, "CTRL+C"),
33 ErrorKind::Aborted => write!(fmt, "ESC"),
34 ErrorKind::Eof => write!(fmt, "EOF"),
35 }
36 }
37}
38
39impl From<io::Error> for ErrorKind {
40 fn from(e: io::Error) -> Self {
41 Self::IoError(e)
42 }
43}