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 28
macro_rules! make_error { ($name:ident) => { #[derive(Debug, Clone)] pub struct $name { details: String, } impl $name { pub fn new(details: &str) -> Self { Self { details: details.to_owned(), } } } impl std::fmt::Display for $name { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(&self.details) } } impl std::error::Error for $name {} }; } make_error!(UnknownCommandError); make_error!(ArgumentError); make_error!(ParserError);