sqlite_parser_nom/
error.rs

1use std::fmt::{Display, Formatter};
2
3#[derive(thiserror::Error, Debug)]
4pub enum SQLiteError {
5    #[error(transparent)]
6    IOError(#[from] std::io::Error),
7
8    #[error(transparent)]
9    ParsingError(#[from] nom::error::Error<OwnedBytes>),
10
11    #[error("unknown text encoding `{0}`")]
12    UnknownTextEncodingError(u32),
13}
14
15/// Used so the error could outlive its input
16#[derive(Debug)]
17pub struct OwnedBytes(pub Vec<u8>);
18
19impl From<Vec<u8>> for OwnedBytes {
20    fn from(value: Vec<u8>) -> Self {
21        OwnedBytes(value)
22    }
23}
24
25impl Display for OwnedBytes {
26    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
27        self.0.iter().fold(Ok(()), |result, byte| {
28            result.and_then(|_| writeln!(f, "{:X} ", byte))
29        })
30    }
31}