1use core::fmt;
4
5use crate::binary::read::ReadEof;
6
7#[derive(Clone, Eq, PartialEq, Debug)]
9pub enum ParseError {
10 BadEof,
12 BadValue,
14 BadVersion,
16 BadOffset,
18 BadIndex,
20 Overflow,
22 CrcMismatch,
24}
25
26impl From<ReadEof> for ParseError {
27 fn from(_error: ReadEof) -> Self {
28 ParseError::BadEof
29 }
30}
31
32impl From<core::num::TryFromIntError> for ParseError {
33 fn from(_error: core::num::TryFromIntError) -> Self {
34 ParseError::BadValue
35 }
36}
37
38impl fmt::Display for ParseError {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 ParseError::BadEof => write!(f, "end of data reached unexpectedly"),
42 ParseError::BadValue => write!(f, "invalid value"),
43 ParseError::BadVersion => write!(f, "unexpected data version"),
44 ParseError::BadOffset => write!(f, "invalid data offset"),
45 ParseError::BadIndex => write!(f, "invalid data index"),
46 ParseError::Overflow => write!(f, "a value overflowed its range"),
47 ParseError::CrcMismatch => write!(f, "CRC mismatch"),
48 }
49 }
50}
51
52#[cfg(not(feature = "no_std"))]
54impl std::error::Error for ParseError {}