Add macro to generate error types with custom fields and functions
This commit is contained in:
parent
1442b370bb
commit
603b4de593
1 changed files with 18 additions and 3 deletions
|
@ -22,12 +22,13 @@ macro_rules! generate_error_module {
|
|||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! generate_error_types {
|
||||
(
|
||||
macro_rules! generate_custom_error_types {
|
||||
{
|
||||
$name: ident,
|
||||
$kindname: ident,
|
||||
$customMemberTypeName: ident,
|
||||
$($kind:ident => $string:expr),*
|
||||
) => {
|
||||
} => {
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum $kindname {
|
||||
$( $kind ),*
|
||||
|
@ -62,6 +63,7 @@ macro_rules! generate_error_types {
|
|||
pub struct $name {
|
||||
err_type: $kindname,
|
||||
cause: Option<Box<Error>>,
|
||||
custom_data: Option<$customMemberTypeName>,
|
||||
}
|
||||
|
||||
impl $name {
|
||||
|
@ -70,6 +72,7 @@ macro_rules! generate_error_types {
|
|||
$name {
|
||||
err_type: errtype,
|
||||
cause: cause,
|
||||
custom_data: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,6 +108,18 @@ macro_rules! generate_error_types {
|
|||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! generate_error_types {
|
||||
(
|
||||
$name: ident,
|
||||
$kindname: ident,
|
||||
$($kind:ident => $string:expr),*
|
||||
) => {
|
||||
generate_custom_error_types!($name, $kindname, members = {}, functions = {}, $($kind),*);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
|
|
Loading…
Reference in a new issue