use std::error::Error;
use std::fmt::Display;
use std::fmt as fmt;
#[derive(Debug)]
pub enum GmshError {
Initialization, Execution, CInterface, ModelMutation, ModelLookup, ModelBadInput, ModelParallelMeshQuery, UnknownOption, UnknownError,
}
pub type GmshResult<T> = Result<T, GmshError>;
impl Display for GmshError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
GmshError::Initialization => {
write!(f, "initialization error for Gmsh or an associated library is missing")
},
_ => write!(f, "big ol error")
}
}
}
impl Error for GmshError {}
#[doc(hidden)]
#[macro_export]
macro_rules! check_main_error {
($ierr:expr, $return_val: expr) => {
match $ierr {
0 => Ok($return_val),
-1 => Err(GmshError::Initialization),
1 => Err(GmshError::Execution),
_ => Err(GmshError::UnknownError),
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! check_model_error {
($ierr:expr, $return_val: expr) => {
match $ierr {
0 => Ok($return_val),
-1 => Err(GmshError::Initialization),
1 => Err(GmshError::ModelMutation),
2 => Err(GmshError::ModelLookup),
3 => Err(GmshError::ModelBadInput),
4 => Err(GmshError::ModelParallelMeshQuery),
_ => Err(GmshError::UnknownError),
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! check_option_error {
($ierr:expr, $return_val: expr) => {
match $ierr {
0 => Ok($return_val),
-1 => Err(GmshError::Initialization),
1 => Err(GmshError::UnknownOption),
_ => Err(GmshError::UnknownError),
}
};
}