1use crate::BmiResult;
2use std::error::Error;
3use std::fmt;
4
5macro_rules! err {
6 ($name:ident, $msg:literal) => {
7 #[doc = $msg]
8 #[doc = " error"]
9 #[derive(Debug, Copy, Clone, Eq, PartialEq)]
10 pub struct $name;
11
12 impl fmt::Display for $name {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 write!(f, $msg)
15 }
16 }
17
18 impl Error for $name {}
19
20 impl<T> From<$name> for BmiResult<T> {
21 fn from(value: $name) -> Self {
22 Err(Box::new(value))
23 }
24 }
25 };
26}
27
28err!(BmiNotImplementedError, "not implemented");
29err!(BmiIndexOutOfBounds, "index out of bounds");