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

Commit a6e475e

Browse files
committed
Add support for customizing traits derived (broken currently)
1 parent 527bea6 commit a6e475e

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

src/error_chain.rs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
/// Prefer to use `error_chain` instead of this macro.
22
#[macro_export]
33
macro_rules! error_chain_processed {
4-
// Default values for `types`.
4+
// Default values for `types` and `derive`.
55
(
6+
// FIXME does not work if either types or derive isn't empty
67
types {}
8+
derive {}
79
$( $rest: tt )*
8-
) => {
10+
) =>{
911
error_chain_processed! {
1012
types {
1113
Error, ErrorKind, ResultExt, Result;
1214
}
15+
derive {
16+
Debug;
17+
}
1318
$( $rest )*
1419
}
1520
};
@@ -21,6 +26,7 @@ macro_rules! error_chain_processed {
2126
}
2227
$( $rest: tt )*
2328
) => {
29+
log_syntax!(rest: $($rest)*);
2430
error_chain_processed! {
2531
types {
2632
$error_name, $error_kind_name,
@@ -39,6 +45,10 @@ macro_rules! error_chain_processed {
3945
$result_ext_name:ident;
4046
}
4147

48+
derive {
49+
$($trait:ident),*;
50+
}
51+
4252
links {
4353
$( $link_variant:ident ( $link_error_path:path, $link_kind_path:path )
4454
$( #[$meta_links:meta] )*; ) *
@@ -351,48 +361,59 @@ macro_rules! error_chain_processed {
351361
#[macro_export]
352362
macro_rules! error_chain_processing {
353363
(
354-
({}, $b:tt, $c:tt, $d:tt)
364+
({}, $b:tt, $c:tt, $d:tt, $e:tt)
355365
types $content:tt
356366
$( $tail:tt )*
357367
) => {
358368
error_chain_processing! {
359-
($content, $b, $c, $d)
369+
($content, $b, $c, $d, $e)
370+
$($tail)*
371+
}
372+
};
373+
(
374+
($a:tt, {}, $c:tt, $d:tt, $e:tt)
375+
derive $content:tt
376+
$( $tail:tt )*
377+
) => {
378+
error_chain_processing! {
379+
($a, $content, $c, $d, $e)
360380
$($tail)*
361381
}
362382
};
363383
(
364-
($a:tt, {}, $c:tt, $d:tt)
384+
($a:tt, $b:tt, {}, $d:tt, $e:tt)
365385
links $content:tt
366386
$( $tail:tt )*
367387
) => {
368388
error_chain_processing! {
369-
($a, $content, $c, $d)
389+
($a, $b, $content, $d, $e)
370390
$($tail)*
371391
}
372392
};
373393
(
374-
($a:tt, $b:tt, {}, $d:tt)
394+
($a:tt, $b:tt, $c:tt, {}, $e:tt)
375395
foreign_links $content:tt
376396
$( $tail:tt )*
377397
) => {
378398
error_chain_processing! {
379-
($a, $b, $content, $d)
399+
($a, $b, $c, $content, $e)
380400
$($tail)*
381401
}
382402
};
383403
(
384-
($a:tt, $b:tt, $c:tt, {})
404+
($a:tt, $b:tt, $c:tt, $d:tt, {})
385405
errors $content:tt
386406
$( $tail:tt )*
387407
) => {
388408
error_chain_processing! {
389-
($a, $b, $c, $content)
409+
($a, $b, $c, $d, $content)
390410
$($tail)*
391411
}
392412
};
393-
( ($a:tt, $b:tt, $c:tt, $d:tt) ) => {
413+
( ($a:tt, $b:tt, $c:tt, $d:tt, $e:tt) ) => {
394414
error_chain_processed! {
395415
types $a
416+
derive $e
396417
links $b
397418
foreign_links $c
398419
errors $d
@@ -406,7 +427,7 @@ macro_rules! error_chain_processing {
406427
macro_rules! error_chain {
407428
( $( $block_name:ident { $( $block_content:tt )* } )* ) => {
408429
error_chain_processing! {
409-
({}, {}, {}, {})
430+
({}, {}, {}, {}, {})
410431
$($block_name { $( $block_content )* })*
411432
}
412433
};

0 commit comments

Comments
 (0)