1use std::{error, fmt};
2
3#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5#[non_exhaustive]
6pub enum Error {
7 WinError(u32),
11 BusNotFound,
15 BusAccessFailed(u32),
17 BusVersionMismatch,
19 NoFreeSlot,
21 AlreadyConnected,
27 NotPluggedIn,
29 TargetNotReady,
34 UserIndexOutOfRange,
38 OperationAborted,
40}
41
42impl From<u32> for Error {
43 #[inline]
44 fn from(error: u32) -> Error {
45 Error::WinError(error)
46 }
47}
48
49impl fmt::Display for Error {
50 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51 match *self {
52 Error::WinError(err) => write!(f, "win error: {}", err),
53 Error::BusNotFound => f.write_str("bus not found"),
54 Error::BusAccessFailed(err) => write!(f, "bus access failed: {}", err),
55 Error::BusVersionMismatch => f.write_str("bus version mismatch"),
56 Error::NoFreeSlot => f.write_str("no free slot"),
57 Error::AlreadyConnected => f.write_str("already connected"),
58 Error::NotPluggedIn => f.write_str("not plugged in"),
59 Error::TargetNotReady => f.write_str("target not ready"),
60 Error::UserIndexOutOfRange => f.write_str("user index out of range"),
61 Error::OperationAborted => f.write_str("operation aborted"),
62 }
63 }
64}
65
66impl error::Error for Error {}