1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
use std::error::Error as StdError; pub type ErrBox = Box<dyn StdError + Send + Sync>; #[derive(std::fmt::Debug)] pub struct Error(String); impl Error { pub fn new(text: String) -> Box<Self> { Box::new(Error(text)) } } impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) } } impl StdError for Error {} #[macro_export] macro_rules! err { ($($arg:tt)*) => { Err($crate::types::Error::new(format!($($arg)*))); } }