escpos_rw/
error.rs

1/// Errors that this crate throws.
2#[derive(Debug, PartialEq, Eq, Clone)]
3pub enum Error {
4    /// Error related to rusb
5    UsbError(rusb::Error),
6    /// This means no bulk endpoint could be found
7    NoBulkEndpoint,
8    /// I/O Error
9    IoError(String),
10    /// Bad configuration file
11    BadConfigFile,
12    /// Generic error
13    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 {}