@@ -102,13 +102,68 @@ macro_rules! impl_error_chain_processed {
102
102
#[ allow( unused) ]
103
103
pub type $result_name<T > = :: std:: result:: Result <T , $error_name>;
104
104
} ;
105
- // Without `Result` wrapper.
105
+
106
+ // With `Msg` variant.
107
+ (
108
+ types {
109
+ $error_name: ident, $error_kind_name: ident, $( $types: tt) *
110
+ }
111
+ links $links: tt
112
+ foreign_links $foreign_links: tt
113
+ errors { $( $errors: tt) * }
114
+ ) => {
115
+ impl_error_chain_processed! {
116
+ types {
117
+ $error_name, $error_kind_name, $( $types) *
118
+ }
119
+ skip_msg_variant
120
+ links $links
121
+ foreign_links $foreign_links
122
+ errors {
123
+ /// A convenient variant for String.
124
+ Msg ( s: String ) {
125
+ description( & s)
126
+ display( "{}" , s)
127
+ }
128
+
129
+ $( $errors) *
130
+ }
131
+ }
132
+
133
+ impl <' a> From <& ' a str > for $error_kind_name {
134
+ fn from( s: & ' a str ) -> Self {
135
+ $error_kind_name:: Msg ( s. into( ) )
136
+ }
137
+ }
138
+
139
+ impl From <String > for $error_kind_name {
140
+ fn from( s: String ) -> Self {
141
+ $error_kind_name:: Msg ( s)
142
+ }
143
+ }
144
+
145
+ impl <' a> From <& ' a str > for $error_name {
146
+ fn from( s: & ' a str ) -> Self {
147
+ Self :: from_kind( s. into( ) )
148
+ }
149
+ }
150
+
151
+ impl From <String > for $error_name {
152
+ fn from( s: String ) -> Self {
153
+ Self :: from_kind( s. into( ) )
154
+ }
155
+ }
156
+ } ;
157
+
158
+ // Without `Result` wrapper or `Msg` variant.
106
159
(
107
160
types {
108
161
$error_name: ident, $error_kind_name: ident,
109
162
$result_ext_name: ident;
110
163
}
111
164
165
+ skip_msg_variant
166
+
112
167
links {
113
168
$( $link_variant: ident ( $link_error_path: path, $link_kind_path: path )
114
169
$( #[ $meta_links: meta] ) * ; ) *
@@ -294,33 +349,13 @@ macro_rules! impl_error_chain_processed {
294
349
}
295
350
}
296
351
297
- impl <' a> From <& ' a str > for $error_name {
298
- fn from( s: & ' a str ) -> Self {
299
- $error_name:: from_kind( s. into( ) )
300
- }
301
- }
302
-
303
- impl From <String > for $error_name {
304
- fn from( s: String ) -> Self {
305
- $error_name:: from_kind( s. into( ) )
306
- }
307
- }
308
-
309
-
310
352
// The ErrorKind type
311
353
// --------------
312
354
313
355
impl_error_chain_kind! {
314
356
/// The kind of an error.
315
357
#[ derive( Debug ) ]
316
358
pub enum $error_kind_name {
317
-
318
- /// A convenient variant for String.
319
- Msg ( s: String ) {
320
- description( & s)
321
- display( "{}" , s)
322
- }
323
-
324
359
$(
325
360
$( #[ $meta_links] ) *
326
361
$link_variant( e: $link_kind_path) {
@@ -350,18 +385,6 @@ macro_rules! impl_error_chain_processed {
350
385
}
351
386
) *
352
387
353
- impl <' a> From <& ' a str > for $error_kind_name {
354
- fn from( s: & ' a str ) -> Self {
355
- $error_kind_name:: Msg ( s. to_string( ) )
356
- }
357
- }
358
-
359
- impl From <String > for $error_kind_name {
360
- fn from( s: String ) -> Self {
361
- $error_kind_name:: Msg ( s)
362
- }
363
- }
364
-
365
388
impl From <$error_name> for $error_kind_name {
366
389
fn from( e: $error_name) -> Self {
367
390
e. 0
@@ -411,48 +434,64 @@ macro_rules! impl_error_chain_processed {
411
434
#[ macro_export( local_inner_macros) ]
412
435
macro_rules! error_chain_processing {
413
436
(
414
- ( { } , $b : tt , $c : tt, $d : tt )
437
+ ( { } , $( $rest : tt) * )
415
438
types $content: tt
416
439
$( $tail: tt ) *
417
440
) => {
418
441
error_chain_processing! {
419
- ( $content, $b , $c , $d )
442
+ ( $content, $( $rest ) * )
420
443
$( $tail) *
421
444
}
422
445
} ;
446
+
423
447
(
424
- ( $a: tt, { } , $c : tt , $d : tt)
448
+ ( $a: tt, { } , $( $rest : tt) * )
425
449
links $content: tt
426
450
$( $tail: tt ) *
427
451
) => {
428
452
error_chain_processing! {
429
- ( $a, $content, $c , $d )
453
+ ( $a, $content, $( $rest ) * )
430
454
$( $tail) *
431
455
}
432
456
} ;
457
+
433
458
(
434
- ( $a: tt, $b: tt, { } , $d : tt)
459
+ ( $a: tt, $b: tt, { } , $( $rest : tt) * )
435
460
foreign_links $content: tt
436
461
$( $tail: tt ) *
437
462
) => {
438
463
error_chain_processing! {
439
- ( $a, $b, $content, $d )
464
+ ( $a, $b, $content, $( $rest ) * )
440
465
$( $tail) *
441
466
}
442
467
} ;
468
+
443
469
(
444
- ( $a: tt, $b: tt, $c: tt, { } )
470
+ ( $a: tt, $b: tt, $c: tt, { } , $ ( $rest : tt ) * )
445
471
errors $content: tt
446
472
$( $tail: tt ) *
447
473
) => {
448
474
error_chain_processing! {
449
- ( $a, $b, $c, $content)
475
+ ( $a, $b, $c, $content, $( $rest) * )
476
+ $( $tail) *
477
+ }
478
+ } ;
479
+
480
+ (
481
+ ( $a: tt, $b: tt, $c: tt, $d: tt, { } , $( $rest: tt) * )
482
+ skip_msg_variant
483
+ $( $tail: tt ) *
484
+ ) => {
485
+ error_chain_processing! {
486
+ ( $a, $b, $c, $d, { skip_msg_variant} , $( $rest) * )
450
487
$( $tail) *
451
488
}
452
489
} ;
453
- ( ( $a: tt, $b: tt, $c: tt, $d: tt) ) => {
490
+
491
+ ( ( $a: tt, $b: tt, $c: tt, $d: tt, { $( $e: tt) * } , ) ) => {
454
492
impl_error_chain_processed! {
455
493
types $a
494
+ $( $e) *
456
495
links $b
457
496
foreign_links $c
458
497
errors $d
@@ -463,10 +502,10 @@ macro_rules! error_chain_processing {
463
502
/// Macro for generating error types and traits. See crate level documentation for details.
464
503
#[ macro_export( local_inner_macros) ]
465
504
macro_rules! error_chain {
466
- ( $( $block_name : ident { $ ( $block_content : tt ) * } ) * ) => {
505
+ ( $( $args : tt ) * ) => {
467
506
error_chain_processing! {
468
- ( { } , { } , { } , { } )
469
- $( $block_name { $ ( $block_content ) * } ) *
507
+ ( { } , { } , { } , { } , { } , )
508
+ $( $args ) *
470
509
}
471
510
} ;
472
511
}
0 commit comments