Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit de82983

Browse files
committed
Add support for customizing traits derived (broken currently)
1 parent 92a54ba commit de82983

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

src/error_chain.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
#[doc(hidden)]
33
#[macro_export]
44
macro_rules! impl_error_chain_processed {
5-
// Default values for `types`.
5+
// Default values for `types` and `derive`.
66
(
7+
// FIXME does not work if either types or derive isn't empty
78
types {}
9+
derive {}
810
$( $rest: tt )*
911
) => {
1012
impl_error_chain_processed! {
1113
types {
1214
Error, ErrorKind, ResultExt, Result;
1315
}
16+
derive {
17+
Debug;
18+
}
1419
$( $rest )*
1520
}
1621
};
@@ -22,6 +27,7 @@ macro_rules! impl_error_chain_processed {
2227
}
2328
$( $rest: tt )*
2429
) => {
30+
log_syntax!(rest: $($rest)*);
2531
impl_error_chain_processed! {
2632
types {
2733
$error_name, $error_kind_name,
@@ -40,6 +46,10 @@ macro_rules! impl_error_chain_processed {
4046
$result_ext_name:ident;
4147
}
4248

49+
derive {
50+
$($trait:ident),*;
51+
}
52+
4353
links {
4454
$( $link_variant:ident ( $link_error_path:path, $link_kind_path:path )
4555
$( #[$meta_links:meta] )*; ) *
@@ -350,48 +360,59 @@ macro_rules! impl_error_chain_processed {
350360
#[macro_export]
351361
macro_rules! error_chain_processing {
352362
(
353-
({}, $b:tt, $c:tt, $d:tt)
363+
({}, $b:tt, $c:tt, $d:tt, $e:tt)
354364
types $content:tt
355365
$( $tail:tt )*
356366
) => {
357367
error_chain_processing! {
358-
($content, $b, $c, $d)
368+
($content, $b, $c, $d, $e)
369+
$($tail)*
370+
}
371+
};
372+
(
373+
($a:tt, {}, $c:tt, $d:tt, $e:tt)
374+
derive $content:tt
375+
$( $tail:tt )*
376+
) => {
377+
error_chain_processing! {
378+
($a, $content, $c, $d, $e)
359379
$($tail)*
360380
}
361381
};
362382
(
363-
($a:tt, {}, $c:tt, $d:tt)
383+
($a:tt, $b:tt, {}, $d:tt, $e:tt)
364384
links $content:tt
365385
$( $tail:tt )*
366386
) => {
367387
error_chain_processing! {
368-
($a, $content, $c, $d)
388+
($a, $b, $content, $d, $e)
369389
$($tail)*
370390
}
371391
};
372392
(
373-
($a:tt, $b:tt, {}, $d:tt)
393+
($a:tt, $b:tt, $c:tt, {}, $e:tt)
374394
foreign_links $content:tt
375395
$( $tail:tt )*
376396
) => {
377397
error_chain_processing! {
378-
($a, $b, $content, $d)
398+
($a, $b, $c, $content, $e)
379399
$($tail)*
380400
}
381401
};
382402
(
383-
($a:tt, $b:tt, $c:tt, {})
403+
($a:tt, $b:tt, $c:tt, $d:tt, {})
384404
errors $content:tt
385405
$( $tail:tt )*
386406
) => {
387407
error_chain_processing! {
388-
($a, $b, $c, $content)
408+
($a, $b, $c, $d, $content)
389409
$($tail)*
390410
}
391411
};
392-
( ($a:tt, $b:tt, $c:tt, $d:tt) ) => {
412+
( ($a:tt, $b:tt, $c:tt, $d:tt, $e:tt) ) => {
393413
impl_error_chain_processed! {
394414
types $a
415+
derive $e
395416
links $b
396417
foreign_links $c
397418
errors $d
@@ -404,7 +425,7 @@ macro_rules! error_chain_processing {
404425
macro_rules! error_chain {
405426
( $( $block_name:ident { $( $block_content:tt )* } )* ) => {
406427
error_chain_processing! {
407-
({}, {}, {}, {})
428+
({}, {}, {}, {}, {})
408429
$($block_name { $( $block_content )* })*
409430
}
410431
};

0 commit comments

Comments
 (0)