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