File tree Expand file tree Collapse file tree 3 files changed +21
-30
lines changed Expand file tree Collapse file tree 3 files changed +21
-30
lines changed Original file line number Diff line number Diff line change @@ -48,12 +48,13 @@ use visitor::FmtVisitor;
48
48
49
49
#[ macro_use]
50
50
mod config;
51
+ #[ macro_use]
52
+ mod utils;
51
53
mod changes;
52
54
mod visitor;
53
55
mod items;
54
56
mod missed_spans;
55
57
mod lists;
56
- mod utils;
57
58
mod types;
58
59
mod expr;
59
60
mod imports;
@@ -64,23 +65,6 @@ const SKIP_ANNOTATION: &'static str = "rustfmt_skip";
64
65
65
66
static mut CONFIG : Option < config:: Config > = None ;
66
67
67
- // Macro for deriving implementations of Decodable for enums
68
- macro_rules! impl_enum_decodable {
69
- ( $e: ident, $( $x: ident ) ,* ) => {
70
- impl Decodable for $e {
71
- fn decode<D : Decoder >( d: & mut D ) -> Result <Self , D :: Error > {
72
- let s = try!( d. read_str( ) ) ;
73
- match & * s {
74
- $(
75
- stringify!( $x) => Ok ( $e:: $x) ,
76
- ) *
77
- _ => Err ( d. error( "Bad variant" ) ) ,
78
- }
79
- }
80
- }
81
- } ;
82
- }
83
-
84
68
#[ derive( Copy , Clone ) ]
85
69
pub enum WriteMode {
86
70
Overwrite ,
Original file line number Diff line number Diff line change @@ -30,18 +30,7 @@ pub enum SeparatorTactic {
30
30
Vertical ,
31
31
}
32
32
33
- // TODO could use a macro for all these Decodable impls.
34
- impl Decodable for SeparatorTactic {
35
- fn decode < D : Decoder > ( d : & mut D ) -> Result < Self , D :: Error > {
36
- let s = try!( d. read_str ( ) ) ;
37
- match & * s {
38
- "Always" => Ok ( SeparatorTactic :: Always ) ,
39
- "Never" => Ok ( SeparatorTactic :: Never ) ,
40
- "Vertical" => Ok ( SeparatorTactic :: Vertical ) ,
41
- _ => Err ( d. error ( "Bad variant" ) ) ,
42
- }
43
- }
44
- }
33
+ impl_enum_decodable ! ( SeparatorTactic , Always , Never , Vertical ) ;
45
34
46
35
// TODO having some helpful ctors for ListFormatting would be nice.
47
36
pub struct ListFormatting < ' a > {
Original file line number Diff line number Diff line change @@ -47,3 +47,21 @@ pub fn format_visibility(vis: Visibility) -> &'static str {
47
47
Visibility :: Inherited => ""
48
48
}
49
49
}
50
+
51
+ // Macro for deriving implementations of Decodable for enums
52
+ #[ macro_export]
53
+ macro_rules! impl_enum_decodable {
54
+ ( $e: ident, $( $x: ident ) ,* ) => {
55
+ impl Decodable for $e {
56
+ fn decode<D : Decoder >( d: & mut D ) -> Result <Self , D :: Error > {
57
+ let s = try!( d. read_str( ) ) ;
58
+ match & * s {
59
+ $(
60
+ stringify!( $x) => Ok ( $e:: $x) ,
61
+ ) *
62
+ _ => Err ( d. error( "Bad variant" ) ) ,
63
+ }
64
+ }
65
+ }
66
+ } ;
67
+ }
You can’t perform that action at this time.
0 commit comments