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

Commit 9503cd4

Browse files
committed
Add support for customizing traits derived (broken currently)
1 parent 3d0df86 commit 9503cd4

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-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] )*; ) *
@@ -332,48 +342,59 @@ macro_rules! error_chain_processed {
332342
#[macro_export]
333343
macro_rules! error_chain_processing {
334344
(
335-
({}, $b:tt, $c:tt, $d:tt)
345+
({}, $b:tt, $c:tt, $d:tt, $e:tt)
336346
types $content:tt
337347
$( $tail:tt )*
338348
) => {
339349
error_chain_processing! {
340-
($content, $b, $c, $d)
350+
($content, $b, $c, $d, $e)
351+
$($tail)*
352+
}
353+
};
354+
(
355+
($a:tt, {}, $c:tt, $d:tt, $e:tt)
356+
derive $content:tt
357+
$( $tail:tt )*
358+
) => {
359+
error_chain_processing! {
360+
($a, $content, $c, $d, $e)
341361
$($tail)*
342362
}
343363
};
344364
(
345-
($a:tt, {}, $c:tt, $d:tt)
365+
($a:tt, $b:tt, {}, $d:tt, $e:tt)
346366
links $content:tt
347367
$( $tail:tt )*
348368
) => {
349369
error_chain_processing! {
350-
($a, $content, $c, $d)
370+
($a, $b, $content, $d, $e)
351371
$($tail)*
352372
}
353373
};
354374
(
355-
($a:tt, $b:tt, {}, $d:tt)
375+
($a:tt, $b:tt, $c:tt, {}, $e:tt)
356376
foreign_links $content:tt
357377
$( $tail:tt )*
358378
) => {
359379
error_chain_processing! {
360-
($a, $b, $content, $d)
380+
($a, $b, $c, $content, $e)
361381
$($tail)*
362382
}
363383
};
364384
(
365-
($a:tt, $b:tt, $c:tt, {})
385+
($a:tt, $b:tt, $c:tt, $d:tt, {})
366386
errors $content:tt
367387
$( $tail:tt )*
368388
) => {
369389
error_chain_processing! {
370-
($a, $b, $c, $content)
390+
($a, $b, $c, $d, $content)
371391
$($tail)*
372392
}
373393
};
374-
( ($a:tt, $b:tt, $c:tt, $d:tt) ) => {
394+
( ($a:tt, $b:tt, $c:tt, $d:tt, $e:tt) ) => {
375395
error_chain_processed! {
376396
types $a
397+
derive $e
377398
links $b
378399
foreign_links $c
379400
errors $d
@@ -387,7 +408,7 @@ macro_rules! error_chain_processing {
387408
macro_rules! error_chain {
388409
( $( $block_name:ident { $( $block_content:tt )* } )* ) => {
389410
error_chain_processing! {
390-
({}, {}, {}, {})
411+
({}, {}, {}, {}, {})
391412
$($block_name { $( $block_content )* })*
392413
}
393414
};

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![deny(missing_docs)]
2+
// TODO: remove
3+
#![feature(log_syntax)]
24

35
//! A library for consistent and reliable error handling
46
//!

0 commit comments

Comments
 (0)