1use core::error;
4use core::fmt::{Debug, Display, Formatter};
5
6use crate::error::UnexpectedBufferEndError;
7
8#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
10pub enum ParseArpError {
11 UnexpectedBufferEnd(UnexpectedBufferEndError),
13 UnsupportedHardwareOrProtocolFields,
15 UnsupportedOperationCode {
17 operation_code: u16,
19 },
20}
21
22impl From<UnexpectedBufferEndError> for ParseArpError {
23 #[inline]
24 fn from(value: UnexpectedBufferEndError) -> Self {
25 Self::UnexpectedBufferEnd(value)
26 }
27}
28
29impl Display for ParseArpError {
30 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
31 match self {
32 Self::UnsupportedHardwareOrProtocolFields => {
33 write!(
34 f,
35 "Hardware/protocol type or length do not fit IPv4 over ethernet"
36 )
37 }
38 Self::UnexpectedBufferEnd(err) => {
39 write!(f, "{err}")
40 }
41 Self::UnsupportedOperationCode { operation_code } => {
42 write!(
43 f,
44 "Unsupported operation code, only request(1) and reply(2) are supported, was: {operation_code}"
45 )
46 }
47 }
48 }
49}
50
51impl error::Error for ParseArpError {}