use std::{fmt, io};
#[derive(Debug)]
pub enum Error {
BadParam(String),
IO(String),
OutOfBound(String),
R2D2(r2d2::Error),
Sqlite(rusqlite::Error)
}
impl Error {
pub fn bad_param(s: impl Into<String>) -> Self {
Self::BadParam(s.into())
}
pub fn oob(s: impl Into<String>) -> Self {
Self::OutOfBound(s.into())
}
}
impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::BadParam(s) => {
write!(f, "Bad parameter; {s}")
}
Self::IO(s) => {
write!(f, "I/O; {s}")
}
Self::OutOfBound(s) => {
write!(f, "Out of bound; {s}")
}
Self::R2D2(err) => {
write!(f, "r2d2; {err}")
}
Self::Sqlite(err) => {
write!(f, "Sqlite; {err}")
}
}
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Self::IO(err.to_string())
}
}
impl From<r2d2::Error> for Error {
fn from(err: r2d2::Error) -> Self {
Self::R2D2(err)
}
}
impl From<rusqlite::Error> for Error {
fn from(err: rusqlite::Error) -> Self {
Self::Sqlite(err)
}
}