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