1#[derive(Debug, PartialEq, Eq, Clone)]
3pub enum Error {
4 UsbError(rusb::Error),
6 NoBulkEndpoint,
8 IoError(String),
10 BadConfigFile,
12 PrinterError(String),
14}
15
16impl From<std::io::Error> for Error {
17 fn from(e: std::io::Error) -> Error {
18 Error::IoError(format!("{}", e))
19 }
20}
21
22impl std::fmt::Display for Error {
23 fn fmt(&self, formatter: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
24 let content = match self {
25 Error::UsbError(e) => format!("USB error: {}", e),
26 Error::NoBulkEndpoint => format!("No bulk endpoint could be found"),
27 Error::IoError(detail) => format!("I/O Error: {}", detail),
28 Error::BadConfigFile => format!("Incorrect configuration file"),
29 Error::PrinterError(detail) => format!("Printer error: {}", detail),
30 };
31 write!(formatter, "{}", content)
32 }
33}
34
35impl std::error::Error for Error {}