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 for FromSqlError { fn from(pe: ParseError) -> Self { FromSqlError::Other(Box::new(pe)) } }