1use std::{
2 error::Error,
3 fmt::{Display, Formatter},
4};
5
6use crate::PairKey;
7
8#[derive(Debug, PartialEq)]
10pub enum XfccError<'a> {
11 TrailingSequence(&'a [u8]),
14 DuplicatePairKey(PairKey),
17 ParsingError(nom::Err<nom::error::Error<&'a [u8]>>),
19}
20
21impl<'a> Display for XfccError<'a> {
22 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
23 match self {
24 Self::TrailingSequence(seq) => write!(f, "Trailing sequence {:?}", seq)?,
25 Self::DuplicatePairKey(key) => write!(f, "Duplicate pair key {key}")?,
26 Self::ParsingError(nom_err) => write!(f, "Parsing error {nom_err}")?,
27 }
28 Ok(())
29 }
30}
31
32impl<'a> Error for XfccError<'a> {}
33
34impl<'a> From<nom::Err<nom::error::Error<&'a [u8]>>> for XfccError<'a> {
35 fn from(value: nom::Err<nom::error::Error<&'a [u8]>>) -> Self {
36 Self::ParsingError(value)
37 }
38}