use std::fmt::{Display, Formatter};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
USB(rusb::Error),
InvalidCDB,
InvalidCSW,
CSWIOError(u8),
TransferStillPending,
InvalidCSWTag,
NoTransferPending,
CSWResidue(u32),
}
impl std::error::Error for Error {}
impl From<rusb::Error> for Error {
fn from(err: rusb::Error) -> Self {
Error::USB(err)
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Error::USB(err) => write!(f, "USB error: {}", err),
Error::InvalidCDB => write!(f, "Invalid arguments to create CDW"),
Error::InvalidCSW => write!(f, "Invalid CSW signature"),
Error::CSWIOError(io) => write!(f, "CSW I/O error: {}", io),
Error::TransferStillPending => write!(f, "Transfer still pending"),
Error::InvalidCSWTag => write!(f, "Invalid CSW tag"),
Error::NoTransferPending => write!(f, "No transfer pending"),
Error::CSWResidue(residue) => write!(f, "CSW residue > 0: {}", residue),
}
}
}