@@ -33,13 +33,68 @@ macro_rules! impl_error_chain_processed {
33
33
#[ allow( unused) ]
34
34
pub type $result_name<T > = :: std:: result:: Result <T , $error_name>;
35
35
} ;
36
- // Without `Result` wrapper.
36
+
37
+ // With `Msg` variant.
38
+ (
39
+ types {
40
+ $error_name: ident, $error_kind_name: ident, $( $types: tt) *
41
+ }
42
+ links $links: tt
43
+ foreign_links $foreign_links: tt
44
+ errors { $( $errors: tt) * }
45
+ ) => {
46
+ impl_error_chain_processed! {
47
+ types {
48
+ $error_name, $error_kind_name, $( $types) *
49
+ }
50
+ skip_msg_variant
51
+ links $links
52
+ foreign_links $foreign_links
53
+ errors {
54
+ /// A convenient variant for String.
55
+ Msg ( s: String ) {
56
+ description( & s)
57
+ display( "{}" , s)
58
+ }
59
+
60
+ $( $errors) *
61
+ }
62
+ }
63
+
64
+ impl <' a> From <& ' a str > for $error_kind_name {
65
+ fn from( s: & ' a str ) -> Self {
66
+ $error_kind_name:: Msg ( s. into( ) )
67
+ }
68
+ }
69
+
70
+ impl From <String > for $error_kind_name {
71
+ fn from( s: String ) -> Self {
72
+ $error_kind_name:: Msg ( s)
73
+ }
74
+ }
75
+
76
+ impl <' a> From <& ' a str > for $error_name {
77
+ fn from( s: & ' a str ) -> Self {
78
+ Self :: from_kind( s. into( ) )
79
+ }
80
+ }
81
+
82
+ impl From <String > for $error_name {
83
+ fn from( s: String ) -> Self {
84
+ Self :: from_kind( s. into( ) )
85
+ }
86
+ }
87
+ } ;
88
+
89
+ // Without `Result` wrapper or `Msg` variant.
37
90
(
38
91
types {
39
92
$error_name: ident, $error_kind_name: ident,
40
93
$result_ext_name: ident;
41
94
}
42
95
96
+ skip_msg_variant
97
+
43
98
links {
44
99
$( $link_variant: ident ( $link_error_path: path, $link_kind_path: path )
45
100
$( #[ $meta_links: meta] ) * ; ) *
@@ -233,33 +288,13 @@ macro_rules! impl_error_chain_processed {
233
288
}
234
289
}
235
290
236
- impl <' a> From <& ' a str > for $error_name {
237
- fn from( s: & ' a str ) -> Self {
238
- $error_name:: from_kind( s. into( ) )
239
- }
240
- }
241
-
242
- impl From <String > for $error_name {
243
- fn from( s: String ) -> Self {
244
- $error_name:: from_kind( s. into( ) )
245
- }
246
- }
247
-
248
-
249
291
// The ErrorKind type
250
292
// --------------
251
293
252
294
impl_error_chain_kind! {
253
295
/// The kind of an error.
254
296
#[ derive( Debug ) ]
255
297
pub enum $error_kind_name {
256
-
257
- /// A convenient variant for String.
258
- Msg ( s: String ) {
259
- description( & s)
260
- display( "{}" , s)
261
- }
262
-
263
298
$(
264
299
$( #[ $meta_links] ) *
265
300
$link_variant( e: $link_kind_path) {
@@ -289,18 +324,6 @@ macro_rules! impl_error_chain_processed {
289
324
}
290
325
) *
291
326
292
- impl <' a> From <& ' a str > for $error_kind_name {
293
- fn from( s: & ' a str ) -> Self {
294
- $error_kind_name:: Msg ( s. to_string( ) )
295
- }
296
- }
297
-
298
- impl From <String > for $error_kind_name {
299
- fn from( s: String ) -> Self {
300
- $error_kind_name:: Msg ( s)
301
- }
302
- }
303
-
304
327
impl From <$error_name> for $error_kind_name {
305
328
fn from( e: $error_name) -> Self {
306
329
e. 0
@@ -350,48 +373,64 @@ macro_rules! impl_error_chain_processed {
350
373
#[ macro_export]
351
374
macro_rules! error_chain_processing {
352
375
(
353
- ( { } , $b : tt , $c : tt, $d : tt )
376
+ ( { } , $( $rest : tt) * )
354
377
types $content: tt
355
378
$( $tail: tt ) *
356
379
) => {
357
380
error_chain_processing! {
358
- ( $content, $b , $c , $d )
381
+ ( $content, $( $rest ) * )
359
382
$( $tail) *
360
383
}
361
384
} ;
385
+
362
386
(
363
- ( $a: tt, { } , $c : tt , $d : tt)
387
+ ( $a: tt, { } , $( $rest : tt) * )
364
388
links $content: tt
365
389
$( $tail: tt ) *
366
390
) => {
367
391
error_chain_processing! {
368
- ( $a, $content, $c , $d )
392
+ ( $a, $content, $( $rest ) * )
369
393
$( $tail) *
370
394
}
371
395
} ;
396
+
372
397
(
373
- ( $a: tt, $b: tt, { } , $d : tt)
398
+ ( $a: tt, $b: tt, { } , $( $rest : tt) * )
374
399
foreign_links $content: tt
375
400
$( $tail: tt ) *
376
401
) => {
377
402
error_chain_processing! {
378
- ( $a, $b, $content, $d )
403
+ ( $a, $b, $content, $( $rest ) * )
379
404
$( $tail) *
380
405
}
381
406
} ;
407
+
382
408
(
383
- ( $a: tt, $b: tt, $c: tt, { } )
409
+ ( $a: tt, $b: tt, $c: tt, { } , $ ( $rest : tt ) * )
384
410
errors $content: tt
385
411
$( $tail: tt ) *
386
412
) => {
387
413
error_chain_processing! {
388
- ( $a, $b, $c, $content)
414
+ ( $a, $b, $c, $content, $( $rest) * )
415
+ $( $tail) *
416
+ }
417
+ } ;
418
+
419
+ (
420
+ ( $a: tt, $b: tt, $c: tt, $d: tt, { } , $( $rest: tt) * )
421
+ skip_msg_variant
422
+ $( $tail: tt ) *
423
+ ) => {
424
+ error_chain_processing! {
425
+ ( $a, $b, $c, $d, { skip_msg_variant} , $( $rest) * )
389
426
$( $tail) *
390
427
}
391
428
} ;
392
- ( ( $a: tt, $b: tt, $c: tt, $d: tt) ) => {
429
+
430
+ ( ( $a: tt, $b: tt, $c: tt, $d: tt, { $( $e: tt) * } , ) ) => {
393
431
impl_error_chain_processed! {
394
432
types $a
433
+ $( $e) *
395
434
links $b
396
435
foreign_links $c
397
436
errors $d
@@ -402,10 +441,10 @@ macro_rules! error_chain_processing {
402
441
/// Macro for generating error types and traits. See crate level documentation for details.
403
442
#[ macro_export]
404
443
macro_rules! error_chain {
405
- ( $( $block_name : ident { $ ( $block_content : tt ) * } ) * ) => {
444
+ ( $( $args : tt ) * ) => {
406
445
error_chain_processing! {
407
- ( { } , { } , { } , { } )
408
- $( $block_name { $ ( $block_content ) * } ) *
446
+ ( { } , { } , { } , { } , { } , )
447
+ $( $args ) *
409
448
}
410
449
} ;
411
450
}
0 commit comments