use alloc::string::String;
use core::fmt;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
Error(String),
Corrupt(String),
Io(String),
Busy,
CantOpen(String),
Constraint(String),
Parse(String),
Unsupported(&'static str),
}
impl Error {
pub fn code(&self) -> i32 {
match self {
Error::Error(_) | Error::Parse(_) | Error::Unsupported(_) => 1, Error::Corrupt(_) => 11, Error::Io(_) => 10, Error::Busy => 5, Error::CantOpen(_) => 14, Error::Constraint(_) => 19, }
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Error(m) => write!(f, "error: {m}"),
Error::Corrupt(m) => write!(f, "database disk image is malformed: {m}"),
Error::Io(m) => write!(f, "disk I/O error: {m}"),
Error::Busy => write!(f, "database is locked"),
Error::CantOpen(m) => write!(f, "unable to open database file: {m}"),
Error::Constraint(m) => write!(f, "constraint failed: {m}"),
Error::Parse(m) => write!(f, "SQL error: {m}"),
Error::Unsupported(m) => write!(f, "not yet implemented: {m}"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}