@@ -277,6 +277,8 @@ macro_rules! value_t_or_exit {
277
277
/// Convenience macro generated a simple enum with variants to be used as a type when parsing
278
278
/// arguments.
279
279
///
280
+ /// **NOTE:** This macro automaically implements std::str::FromStr and std::fmt::Display
281
+ ///
280
282
/// # Example
281
283
///
282
284
/// ```no_run
@@ -322,6 +324,14 @@ macro_rules! simple_enum {
322
324
}
323
325
}
324
326
}
327
+
328
+ impl :: std:: fmt:: Display for $e {
329
+ fn fmt( & self , f: & mut :: std:: fmt:: Formatter ) -> :: std:: fmt:: Result {
330
+ match * self {
331
+ $( $e:: $v => write!( f, stringify!( $v) ) , ) +
332
+ }
333
+ }
334
+ }
325
335
} ;
326
336
}
327
337
@@ -330,6 +340,8 @@ macro_rules! simple_enum {
330
340
///
331
341
/// **NOTE:** Case insensitivity is supported for ASCII characters
332
342
///
343
+ /// **NOTE:** This macro automaically implements std::str::FromStr and std::fmt::Display
344
+ ///
333
345
/// These enums support pub (or not) and use of the #[derive()] traits
334
346
///
335
347
///
@@ -385,6 +397,14 @@ macro_rules! arg_enum {
385
397
}
386
398
}
387
399
}
400
+
401
+ impl :: std:: fmt:: Display for $e {
402
+ fn fmt( & self , f: & mut :: std:: fmt:: Formatter ) -> :: std:: fmt:: Result {
403
+ match * self {
404
+ $( $e:: $v => write!( f, stringify!( $v) ) , ) +
405
+ }
406
+ }
407
+ }
388
408
} ;
389
409
( pub enum $e: ident { $( $v: ident) ,+ } ) => {
390
410
pub enum $e {
@@ -411,6 +431,14 @@ macro_rules! arg_enum {
411
431
}
412
432
}
413
433
}
434
+
435
+ impl :: std:: fmt:: Display for $e {
436
+ fn fmt( & self , f: & mut :: std:: fmt:: Formatter ) -> :: std:: fmt:: Result {
437
+ match * self {
438
+ $( $e:: $v => write!( f, stringify!( $v) ) , ) +
439
+ }
440
+ }
441
+ }
414
442
} ;
415
443
( #[ derive( $( $d: ident) ,+) ] enum $e: ident { $( $v: ident) ,+ } ) => {
416
444
#[ derive( $( $d, ) +) ]
@@ -438,6 +466,14 @@ macro_rules! arg_enum {
438
466
}
439
467
}
440
468
}
469
+
470
+ impl :: std:: fmt:: Display for $e {
471
+ fn fmt( & self , f: & mut :: std:: fmt:: Formatter ) -> :: std:: fmt:: Result {
472
+ match * self {
473
+ $( $e:: $v => write!( f, stringify!( $v) ) , ) +
474
+ }
475
+ }
476
+ }
441
477
} ;
442
478
( #[ derive( $( $d: ident) ,+) ] pub enum $e: ident { $( $v: ident) ,+ } ) => {
443
479
#[ derive( $( $d, ) +) ]
@@ -465,6 +501,14 @@ macro_rules! arg_enum {
465
501
}
466
502
}
467
503
}
504
+
505
+ impl :: std:: fmt:: Display for $e {
506
+ fn fmt( & self , f: & mut :: std:: fmt:: Formatter ) -> :: std:: fmt:: Result {
507
+ match * self {
508
+ $( $e:: $v => write!( f, stringify!( $v) ) , ) +
509
+ }
510
+ }
511
+ }
468
512
} ;
469
513
}
470
514
0 commit comments