Custom Rust Error
macro_rules! error_impl {
($err_struct:ident, $msg: expr) => (
impl std::fmt::Display for $err_struct {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", $msg)
}
}
impl std::error::Error for $err_struct {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
);
}
#[derive(Debug, Copy, Clone)]
pub struct NotAsciiError;
error_impl!(NotAsciiError, "Not Valid Ascii");