use thiserror::Error;
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum Error {
#[error("invalid RPC packet")]
InvalidRPC = 0x01,
#[error("unknown RPC command")]
UnknownRPC = 0x02,
#[error("unable to connect to the requested network")]
UnableToConnect = 0x03,
#[error("not authorised")]
NotAuthorized = 0x04,
#[error("bad hostname")]
BadHostname = 0x05,
#[error("unknown error")]
Unknown = 0xFF,
}
impl Error {
pub fn as_byte(self) -> u8 {
self as u8
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn error_byte_values() {
assert_eq!(Error::InvalidRPC.as_byte(), 0x01);
assert_eq!(Error::UnknownRPC.as_byte(), 0x02);
assert_eq!(Error::UnableToConnect.as_byte(), 0x03);
assert_eq!(Error::NotAuthorized.as_byte(), 0x04);
assert_eq!(Error::BadHostname.as_byte(), 0x05);
assert_eq!(Error::Unknown.as_byte(), 0xFF);
}
}