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