1616
1717pub use Alignment :: * ;
1818pub use Count :: * ;
19- pub use Flag :: * ;
2019pub use Piece :: * ;
2120pub use Position :: * ;
2221
@@ -111,8 +110,14 @@ pub struct FormatSpec<'a> {
111110 pub fill : Option < char > ,
112111 /// Optionally specified alignment.
113112 pub align : Alignment ,
114- /// Packed version of various flags provided.
115- pub flags : u32 ,
113+ /// The `+` or `-` flag.
114+ pub sign : Option < Sign > ,
115+ /// The `#` flag.
116+ pub alternate : bool ,
117+ /// The `0` flag.
118+ pub zero_pad : bool ,
119+ /// The `x` or `X` flag. (Only for `Debug`.)
120+ pub debug_hex : Option < DebugHex > ,
116121 /// The integer precision to use.
117122 pub precision : Count < ' a > ,
118123 /// The span of the precision formatting flag (for diagnostics).
@@ -162,24 +167,22 @@ pub enum Alignment {
162167 AlignUnknown ,
163168}
164169
165- /// Various flags which can be applied to format strings. The meaning of these
166- /// flags is defined by the formatters themselves.
170+ /// Enum for the sign flags.
167171#[ derive( Copy , Clone , Debug , PartialEq ) ]
168- pub enum Flag {
169- /// A `+` will be used to denote positive numbers.
170- FlagSignPlus ,
171- /// A `-` will be used to denote negative numbers. This is the default.
172- FlagSignMinus ,
173- /// An alternate form will be used for the value. In the case of numbers,
174- /// this means that the number will be prefixed with the supplied string.
175- FlagAlternate ,
176- /// For numbers, this means that the number will be padded with zeroes,
177- /// and the sign (`+` or `-`) will precede them.
178- FlagSignAwareZeroPad ,
179- /// For Debug / `?`, format integers in lower-case hexadecimal.
180- FlagDebugLowerHex ,
181- /// For Debug / `?`, format integers in upper-case hexadecimal.
182- FlagDebugUpperHex ,
172+ pub enum Sign {
173+ /// The `+` flag.
174+ Plus ,
175+ /// The `-` flag.
176+ Minus ,
177+ }
178+
179+ /// Enum for the debug hex flags.
180+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
181+ pub enum DebugHex {
182+ /// The `x` flag in `{:x?}`.
183+ Lower ,
184+ /// The `X` flag in `{:X?}`.
185+ Upper ,
183186}
184187
185188/// A count is used for the precision and width parameters of an integer, and
@@ -597,7 +600,10 @@ impl<'a> Parser<'a> {
597600 let mut spec = FormatSpec {
598601 fill : None ,
599602 align : AlignUnknown ,
600- flags : 0 ,
603+ sign : None ,
604+ alternate : false ,
605+ zero_pad : false ,
606+ debug_hex : None ,
601607 precision : CountImplied ,
602608 precision_span : None ,
603609 width : CountImplied ,
@@ -626,13 +632,13 @@ impl<'a> Parser<'a> {
626632 }
627633 // Sign flags
628634 if self . consume ( '+' ) {
629- spec. flags |= 1 << ( FlagSignPlus as u32 ) ;
635+ spec. sign = Some ( Sign :: Plus ) ;
630636 } else if self . consume ( '-' ) {
631- spec. flags |= 1 << ( FlagSignMinus as u32 ) ;
637+ spec. sign = Some ( Sign :: Minus ) ;
632638 }
633639 // Alternate marker
634640 if self . consume ( '#' ) {
635- spec. flags |= 1 << ( FlagAlternate as u32 ) ;
641+ spec. alternate = true ;
636642 }
637643 // Width and precision
638644 let mut havewidth = false ;
@@ -647,7 +653,7 @@ impl<'a> Parser<'a> {
647653 spec. width_span = Some ( self . span ( end - 1 , end + 1 ) ) ;
648654 havewidth = true ;
649655 } else {
650- spec. flags |= 1 << ( FlagSignAwareZeroPad as u32 ) ;
656+ spec. zero_pad = true ;
651657 }
652658 }
653659
@@ -678,14 +684,14 @@ impl<'a> Parser<'a> {
678684 // Optional radix followed by the actual format specifier
679685 if self . consume ( 'x' ) {
680686 if self . consume ( '?' ) {
681- spec. flags |= 1 << ( FlagDebugLowerHex as u32 ) ;
687+ spec. debug_hex = Some ( DebugHex :: Lower ) ;
682688 spec. ty = "?" ;
683689 } else {
684690 spec. ty = "x" ;
685691 }
686692 } else if self . consume ( 'X' ) {
687693 if self . consume ( '?' ) {
688- spec. flags |= 1 << ( FlagDebugUpperHex as u32 ) ;
694+ spec. debug_hex = Some ( DebugHex :: Upper ) ;
689695 spec. ty = "?" ;
690696 } else {
691697 spec. ty = "X" ;
@@ -708,7 +714,10 @@ impl<'a> Parser<'a> {
708714 let mut spec = FormatSpec {
709715 fill : None ,
710716 align : AlignUnknown ,
711- flags : 0 ,
717+ sign : None ,
718+ alternate : false ,
719+ zero_pad : false ,
720+ debug_hex : None ,
712721 precision : CountImplied ,
713722 precision_span : None ,
714723 width : CountImplied ,
0 commit comments