can_hal_socketcan/
error.rs1use std::fmt;
2use std::io;
3
4#[derive(Debug)]
6pub enum SocketCanError {
7 Io(io::Error),
9 InvalidFrame(String),
11 InvalidInterface(String),
13}
14
15impl fmt::Display for SocketCanError {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 match self {
18 SocketCanError::Io(e) => write!(f, "SocketCAN I/O error: {e}"),
19 SocketCanError::InvalidFrame(msg) => write!(f, "invalid frame: {msg}"),
20 SocketCanError::InvalidInterface(msg) => write!(f, "invalid interface: {msg}"),
21 }
22 }
23}
24
25impl std::error::Error for SocketCanError {
26 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
27 match self {
28 SocketCanError::Io(e) => Some(e),
29 _ => None,
30 }
31 }
32}
33
34impl From<io::Error> for SocketCanError {
35 fn from(e: io::Error) -> Self {
36 SocketCanError::Io(e)
37 }
38}