flash_lso/
errors.rs

1use nom::error::{ErrorKind, FromExternalError, ParseError};
2use thiserror::Error;
3
4/// Enum for representing decoding errors
5#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
6pub enum Error<'a> {
7    /// Out of bounds decoding
8    #[error("Out of bounds")]
9    OutOfBounds,
10
11    /// A nom internal error
12    #[error("Nom internal error")]
13    Nom(&'a [u8], ErrorKind),
14}
15
16impl<'a> ParseError<&'a [u8]> for Error<'a> {
17    fn from_error_kind(input: &'a [u8], kind: ErrorKind) -> Self {
18        Error::Nom(input, kind)
19    }
20
21    fn append(_: &[u8], _: ErrorKind, other: Self) -> Self {
22        other
23    }
24}
25
26impl<'a, E> FromExternalError<&'a [u8], E> for Error<'a> {
27    fn from_external_error(input: &'a [u8], kind: ErrorKind, _e: E) -> Self {
28        Error::Nom(input, kind)
29    }
30}