use std::fmt;
use std::io;
#[derive(Debug)]
pub enum SocketCanError {
Io(io::Error),
InvalidFrame(String),
InvalidInterface(String),
}
impl fmt::Display for SocketCanError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SocketCanError::Io(e) => write!(f, "SocketCAN I/O error: {e}"),
SocketCanError::InvalidFrame(msg) => write!(f, "invalid frame: {msg}"),
SocketCanError::InvalidInterface(msg) => write!(f, "invalid interface: {msg}"),
}
}
}
impl std::error::Error for SocketCanError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
SocketCanError::Io(e) => Some(e),
_ => None,
}
}
}
impl From<io::Error> for SocketCanError {
fn from(e: io::Error) -> Self {
SocketCanError::Io(e)
}
}