blob: 66186cf2379030f69385cc03e93e35b6fbb47b9b (
plain)
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
|
use std::fmt;
use rusqlite::types::FromSqlError;
#[derive(Clone, Debug, PartialEq)]
pub enum ParseError {
IdNotPrintable,
IdIncorrectSize { expected: usize, actual: usize },
}
impl std::error::Error for ParseError {}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::IdNotPrintable => write!(
f,
"IDs must be an ascii graphic character (no whitespace/control)"
),
Self::IdIncorrectSize { expected, actual } => write!(
f,
"Unable to decode ID. Expected a size of {expected}, but data had len={actual}"
),
}
}
}
impl From<ParseError> for FromSqlError {
fn from(pe: ParseError) -> Self {
FromSqlError::Other(Box::new(pe))
}
}
|