use std::{fmt, result};
pub type HidDeviceResult<T> = result::Result<T, HidDeviceError>;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum HidDeviceError {
InvalidHandle,
InvalidParameter,
InvalidBufferSize,
FunctionNotSupported,
SystemError,
DeviceNotFound,
DeviceNotOpened,
DeviceAlreadyOpened,
TransferTimeout,
TransferFailed,
CannotGetHidInfo,
Other,
}
impl fmt::Display for HidDeviceError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
fmt.write_str(match self {
HidDeviceError::InvalidHandle => "Invalid Handle",
HidDeviceError::InvalidParameter => "Specified (typically non-buffer related) parameter is wrong or unexpected",
HidDeviceError::InvalidBufferSize => "Specified buffer is not large enough to return requested data",
HidDeviceError::FunctionNotSupported => {
"Function not supported or unimplemented on this platform"
}
HidDeviceError::SystemError => "System error ",
HidDeviceError::DeviceNotFound => "The specified device index was invalid or the device does not exist or is inaccessible",
HidDeviceError::DeviceNotOpened => "The device must be opened prior to calling the function",
HidDeviceError::DeviceAlreadyOpened => "The device is already opened and cannot be re-opened.",
HidDeviceError::TransferTimeout => "The get or set report function returned due to a timeout",
HidDeviceError::TransferFailed => "The host failed to communicate with the device or function parameters are incorrect",
HidDeviceError::CannotGetHidInfo => "Cannot retrieve device path",
HidDeviceError::Other => "Other error",
})
}
}
impl std::error::Error for HidDeviceError {}