use std::fmt::Display; pub type Result = std::result::Result; #[derive(Debug)] pub enum ErrorKind { Internal, } #[derive(Debug)] pub struct Error { kind: ErrorKind, code: u16, message: String, } impl Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.message) } } impl Error { pub fn internal(code: u16, s: &str) -> Self { Self { kind: ErrorKind::Internal, code, message: s.to_string(), } } } impl From for Error { fn from(source: indradb::Error) -> Self { Self { kind: ErrorKind::Internal, code: 0, message: format!("{}", source), } } } impl From for Error { fn from(source: indradb::ValidationError) -> Self { Self { kind: ErrorKind::Internal, code: 1, message: format!("{}", source), } } }