@@ -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] ) * ; ) *
@@ -227,18 +282,6 @@ macro_rules! impl_error_chain_processed {
227
282
}
228
283
}
229
284
230
- impl <' a> From <& ' a str > for $error_name {
231
- fn from( s: & ' a str ) -> Self {
232
- $error_name:: from_kind( s. into( ) )
233
- }
234
- }
235
-
236
- impl From <String > for $error_name {
237
- fn from( s: String ) -> Self {
238
- $error_name:: from_kind( s. into( ) )
239
- }
240
- }
241
-
242
285
impl :: std:: ops:: Deref for $error_name {
243
286
type Target = $error_kind_name;
244
287
@@ -255,13 +298,6 @@ macro_rules! impl_error_chain_processed {
255
298
/// The kind of an error.
256
299
#[ derive( Debug ) ]
257
300
pub enum $error_kind_name {
258
-
259
- /// A convenient variant for String.
260
- Msg ( s: String ) {
261
- description( & s)
262
- display( "{}" , s)
263
- }
264
-
265
301
$(
266
302
$( #[ $meta_links] ) *
267
303
$link_variant( e: $link_kind_path) {
@@ -291,18 +327,6 @@ macro_rules! impl_error_chain_processed {
291
327
}
292
328
) *
293
329
294
- impl <' a> From <& ' a str > for $error_kind_name {
295
- fn from( s: & ' a str ) -> Self {
296
- $error_kind_name:: Msg ( s. to_string( ) )
297
- }
298
- }
299
-
300
- impl From <String > for $error_kind_name {
301
- fn from( s: String ) -> Self {
302
- $error_kind_name:: Msg ( s)
303
- }
304
- }
305
-
306
330
impl From <$error_name> for $error_kind_name {
307
331
fn from( e: $error_name) -> Self {
308
332
e. 0
@@ -352,48 +376,64 @@ macro_rules! impl_error_chain_processed {
352
376
#[ macro_export]
353
377
macro_rules! error_chain_processing {
354
378
(
355
- ( { } , $b : tt , $c : tt, $d : tt )
379
+ ( { } , $( $rest : tt) * )
356
380
types $content: tt
357
381
$( $tail: tt ) *
358
382
) => {
359
383
error_chain_processing! {
360
- ( $content, $b , $c , $d )
384
+ ( $content, $( $rest ) * )
361
385
$( $tail) *
362
386
}
363
387
} ;
388
+
364
389
(
365
- ( $a: tt, { } , $c : tt , $d : tt)
390
+ ( $a: tt, { } , $( $rest : tt) * )
366
391
links $content: tt
367
392
$( $tail: tt ) *
368
393
) => {
369
394
error_chain_processing! {
370
- ( $a, $content, $c , $d )
395
+ ( $a, $content, $( $rest ) * )
371
396
$( $tail) *
372
397
}
373
398
} ;
399
+
374
400
(
375
- ( $a: tt, $b: tt, { } , $d : tt)
401
+ ( $a: tt, $b: tt, { } , $( $rest : tt) * )
376
402
foreign_links $content: tt
377
403
$( $tail: tt ) *
378
404
) => {
379
405
error_chain_processing! {
380
- ( $a, $b, $content, $d )
406
+ ( $a, $b, $content, $( $rest ) * )
381
407
$( $tail) *
382
408
}
383
409
} ;
410
+
384
411
(
385
- ( $a: tt, $b: tt, $c: tt, { } )
412
+ ( $a: tt, $b: tt, $c: tt, { } , $ ( $rest : tt ) * )
386
413
errors $content: tt
387
414
$( $tail: tt ) *
388
415
) => {
389
416
error_chain_processing! {
390
- ( $a, $b, $c, $content)
417
+ ( $a, $b, $c, $content, $( $rest) * )
418
+ $( $tail) *
419
+ }
420
+ } ;
421
+
422
+ (
423
+ ( $a: tt, $b: tt, $c: tt, $d: tt, { } , $( $rest: tt) * )
424
+ skip_msg_variant
425
+ $( $tail: tt ) *
426
+ ) => {
427
+ error_chain_processing! {
428
+ ( $a, $b, $c, $d, { skip_msg_variant} , $( $rest) * )
391
429
$( $tail) *
392
430
}
393
431
} ;
394
- ( ( $a: tt, $b: tt, $c: tt, $d: tt) ) => {
432
+
433
+ ( ( $a: tt, $b: tt, $c: tt, $d: tt, { $( $e: tt) * } , ) ) => {
395
434
impl_error_chain_processed! {
396
435
types $a
436
+ $( $e) *
397
437
links $b
398
438
foreign_links $c
399
439
errors $d
@@ -404,10 +444,10 @@ macro_rules! error_chain_processing {
404
444
/// Macro for generating error types and traits. See crate level documentation for details.
405
445
#[ macro_export]
406
446
macro_rules! error_chain {
407
- ( $( $block_name : ident { $ ( $block_content : tt ) * } ) * ) => {
447
+ ( $( $args : tt ) * ) => {
408
448
error_chain_processing! {
409
- ( { } , { } , { } , { } )
410
- $( $block_name { $ ( $block_content ) * } ) *
449
+ ( { } , { } , { } , { } , { } , )
450
+ $( $args ) *
411
451
}
412
452
} ;
413
453
}
0 commit comments