1use core::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub enum KnxError {
5 InvalidAddress(&'static str),
6 BufferTooShort { needed: usize, actual: usize },
7 InvalidFrame(&'static str),
8 UnsupportedServiceType(u16),
9}
10
11impl fmt::Display for KnxError {
12 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13 match self {
14 Self::InvalidAddress(reason) => write!(f, "invalid address: {reason}"),
15 Self::BufferTooShort { needed, actual } => {
16 write!(f, "buffer too short: needed {needed} bytes, got {actual}")
17 }
18 Self::InvalidFrame(reason) => write!(f, "invalid frame: {reason}"),
19 Self::UnsupportedServiceType(service_type) => {
20 write!(f, "unsupported service type: 0x{service_type:04x}")
21 }
22 }
23 }
24}
25
26#[cfg(feature = "std")]
27impl std::error::Error for KnxError {}
28
29pub type Result<T> = core::result::Result<T, KnxError>;