walletkit_db/sqlite/
error.rs1use std::fmt;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub struct ErrorCode(pub i32);
8
9impl fmt::Display for ErrorCode {
10 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11 write!(f, "{}", self.0)
12 }
13}
14
15#[derive(Debug, PartialEq, Eq)]
17pub struct Error {
18 pub code: ErrorCode,
20 pub message: String,
22}
23
24impl Error {
25 pub(crate) fn new(code: i32, message: impl Into<String>) -> Self {
27 Self {
28 code: ErrorCode(code),
29 message: message.into(),
30 }
31 }
32}
33
34impl fmt::Display for Error {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 write!(f, "sqlite error {}: {}", self.code, self.message)
37 }
38}
39
40impl std::error::Error for Error {}
41
42pub type DbResult<T> = std::result::Result<T, Error>;