veecle_os_data_support_can/
error.rs1use core::error::Error;
2use core::fmt::Display;
3
4#[derive(Debug)]
5#[non_exhaustive]
6pub enum CanDecodeError {
8 IncorrectId,
10
11 IncorrectBufferSize,
13
14 OutOfRange {
16 name: &'static str,
18 ty: &'static str,
20 message: &'static str,
22 },
23
24 Invalid {
26 message: &'static str,
28 },
29}
30
31impl CanDecodeError {
32 pub fn invalid(message: &'static str) -> Self {
34 Self::Invalid { message }
35 }
36}
37
38impl Display for CanDecodeError {
39 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
40 match *self {
41 CanDecodeError::IncorrectId => write!(f, "incorrect CAN frame id"),
42 CanDecodeError::IncorrectBufferSize => write!(f, "incorrect CAN frame size"),
43 CanDecodeError::OutOfRange { name, ty, message } => {
44 write!(f, "field {name}:{ty}: {message}")
45 }
46 CanDecodeError::Invalid { message } => write!(f, "validation failure: {message}"),
47 }
48 }
49}
50
51impl Error for CanDecodeError {}