use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DbErrorCode(pub i32);
impl fmt::Display for DbErrorCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, PartialEq, Eq)]
pub struct DbError {
pub code: DbErrorCode,
pub message: String,
}
impl DbError {
pub(crate) fn new(code: i32, message: impl Into<String>) -> Self {
Self {
code: DbErrorCode(code),
message: message.into(),
}
}
}
impl fmt::Display for DbError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "sqlite error {}: {}", self.code, self.message)
}
}
impl std::error::Error for DbError {}
pub type DbResult<T> = Result<T, DbError>;