@@ -56,30 +56,12 @@ pub struct Argument<'a> {
56
56
57
57
impl < ' a > Argument < ' a > {
58
58
pub fn is_identifier ( & self ) -> bool {
59
- matches ! ( self . position, Position :: ArgumentNamed ( _) )
60
- && matches ! (
61
- self . format,
62
- FormatSpec {
63
- fill: None ,
64
- fill_span: None ,
65
- align: AlignUnknown ,
66
- sign: None ,
67
- alternate: false ,
68
- zero_pad: false ,
69
- debug_hex: None ,
70
- precision: CountImplied ,
71
- precision_span: None ,
72
- width: CountImplied ,
73
- width_span: None ,
74
- ty: "" ,
75
- ty_span: None ,
76
- } ,
77
- )
59
+ matches ! ( self . position, Position :: ArgumentNamed ( _) ) && self . format == FormatSpec :: default ( )
78
60
}
79
61
}
80
62
81
63
/// Specification for the formatting of an argument in the format string.
82
- #[ derive( Clone , Debug , PartialEq ) ]
64
+ #[ derive( Clone , Debug , PartialEq , Default ) ]
83
65
pub struct FormatSpec < ' a > {
84
66
/// Optionally specified character to fill alignment with.
85
67
pub fill : Option < char > ,
@@ -132,7 +114,7 @@ impl Position<'_> {
132
114
}
133
115
134
116
/// Enum of alignments which are supported.
135
- #[ derive( Copy , Clone , Debug , PartialEq ) ]
117
+ #[ derive( Copy , Clone , Debug , PartialEq , Default ) ]
136
118
pub enum Alignment {
137
119
/// The value will be aligned to the left.
138
120
AlignLeft ,
@@ -141,6 +123,7 @@ pub enum Alignment {
141
123
/// The value will be aligned in the center.
142
124
AlignCenter ,
143
125
/// The value will take on a default alignment.
126
+ #[ default]
144
127
AlignUnknown ,
145
128
}
146
129
@@ -164,7 +147,7 @@ pub enum DebugHex {
164
147
165
148
/// A count is used for the precision and width parameters of an integer, and
166
149
/// can reference either an argument or a literal integer.
167
- #[ derive( Clone , Debug , PartialEq ) ]
150
+ #[ derive( Clone , Debug , PartialEq , Default ) ]
168
151
pub enum Count < ' a > {
169
152
/// The count is specified explicitly.
170
153
CountIs ( u16 ) ,
@@ -175,6 +158,7 @@ pub enum Count<'a> {
175
158
/// The count is specified by a star (like in `{:.*}`) that refers to the argument at the given index.
176
159
CountIsStar ( usize ) ,
177
160
/// The count is implied and cannot be explicitly specified.
161
+ #[ default]
178
162
CountImplied ,
179
163
}
180
164
@@ -596,21 +580,8 @@ impl<'a> Parser<'a> {
596
580
/// Parses a format specifier at the current position, returning all of the
597
581
/// relevant information in the `FormatSpec` struct.
598
582
fn format ( & mut self ) -> FormatSpec < ' a > {
599
- let mut spec = FormatSpec {
600
- fill : None ,
601
- fill_span : None ,
602
- align : AlignUnknown ,
603
- sign : None ,
604
- alternate : false ,
605
- zero_pad : false ,
606
- debug_hex : None ,
607
- precision : CountImplied ,
608
- precision_span : None ,
609
- width : CountImplied ,
610
- width_span : None ,
611
- ty : & self . input [ ..0 ] ,
612
- ty_span : None ,
613
- } ;
583
+ let mut spec = FormatSpec :: default ( ) ;
584
+
614
585
if !self . consume ( ':' ) {
615
586
return spec;
616
587
}
@@ -727,21 +698,8 @@ impl<'a> Parser<'a> {
727
698
/// Parses an inline assembly template modifier at the current position, returning the modifier
728
699
/// in the `ty` field of the `FormatSpec` struct.
729
700
fn inline_asm ( & mut self ) -> FormatSpec < ' a > {
730
- let mut spec = FormatSpec {
731
- fill : None ,
732
- fill_span : None ,
733
- align : AlignUnknown ,
734
- sign : None ,
735
- alternate : false ,
736
- zero_pad : false ,
737
- debug_hex : None ,
738
- precision : CountImplied ,
739
- precision_span : None ,
740
- width : CountImplied ,
741
- width_span : None ,
742
- ty : & self . input [ ..0 ] ,
743
- ty_span : None ,
744
- } ;
701
+ let mut spec = FormatSpec :: default ( ) ;
702
+
745
703
if !self . consume ( ':' ) {
746
704
return spec;
747
705
}
0 commit comments