pub type Result = std::result::Result; #[derive(Debug)] pub enum JDbError { SledError(sled::Error), SerdeJsonError(serde_json::Error), NotUnique, NotFound, RegexError(regex::Error), JsonError(json::JsonError), } impl std::error::Error for JDbError {} impl std::fmt::Display for JDbError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { JDbError::SledError(e) => write!(f, "Sled Error: {}", e), JDbError::SerdeJsonError(e) => write!(f, "Serde JSON Error: {}", e), JDbError::NotUnique => write!(f, "Entry is not unique."), JDbError::NotFound => write!(f, "Entry was not found."), JDbError::RegexError(e) => write!(f, "Regex Error: {}", e), JDbError::JsonError(e) => write!(f, "JSON Error: {}", e), } } } impl From for JDbError { fn from(e: sled::Error) -> Self { JDbError::SledError(e) } } impl From for JDbError { fn from(e: serde_json::Error) -> Self { JDbError::SerdeJsonError(e) } } impl From for JDbError { fn from(e: regex::Error) -> Self { Self::RegexError(e) } } impl From for JDbError { fn from(e: json::Error) -> Self { Self::JsonError(e) } }