@@ -35,18 +35,17 @@ pub struct CFormatError {
3535
3636impl fmt:: Display for CFormatError {
3737 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
38- use CFormatErrorType :: * ;
3938 match self . typ {
40- UnmatchedKeyParentheses => write ! ( f, "incomplete format key" ) ,
41- IncompleteFormat => write ! ( f, "incomplete format" ) ,
42- UnsupportedFormatChar ( c) => write ! (
39+ CFormatErrorType :: UnmatchedKeyParentheses => write ! ( f, "incomplete format key" ) ,
40+ CFormatErrorType :: IncompleteFormat => write ! ( f, "incomplete format" ) ,
41+ CFormatErrorType :: UnsupportedFormatChar ( c) => write ! (
4342 f,
4443 "unsupported format character '{}' ({:#x}) at index {}" ,
4544 c,
4645 c. to_u32( ) ,
4746 self . index
4847 ) ,
49- IntTooBig => write ! ( f, "width/precision too big" ) ,
48+ CFormatErrorType :: IntTooBig => write ! ( f, "width/precision too big" ) ,
5049 _ => write ! ( f, "unexpected error parsing format string" ) ,
5150 }
5251 }
@@ -78,11 +77,9 @@ pub enum CFloatType {
7877
7978impl CFloatType {
8079 const fn case ( self ) -> Case {
81- use CFloatType :: * ;
82-
8380 match self {
84- ExponentLower | PointDecimalLower | GeneralLower => Case :: Lower ,
85- ExponentUpper | PointDecimalUpper | GeneralUpper => Case :: Upper ,
81+ Self :: ExponentLower | Self :: PointDecimalLower | Self :: GeneralLower => Case :: Lower ,
82+ Self :: ExponentUpper | Self :: PointDecimalUpper | Self :: GeneralUpper => Case :: Upper ,
8683 }
8784 }
8885}
@@ -443,27 +440,29 @@ impl CFormatSpec {
443440
444441 #[ must_use]
445442 pub fn format_number ( & self , num : & BigInt ) -> String {
446- use CNumberType :: * ;
447443 let CFormatType :: Number ( format_type) = self . format_type else {
448444 unreachable ! ( )
449445 } ;
446+
450447 let magnitude = num. abs ( ) ;
451448 let prefix = if self . flags . contains ( CConversionFlags :: ALTERNATE_FORM ) {
452449 match format_type {
453- Octal => "0o" ,
454- HexLower => "0x" ,
455- HexUpper => "0X" ,
450+ CNumberType :: Octal => "0o" ,
451+ CNumberType :: HexLower => "0x" ,
452+ CNumberType :: HexUpper => "0X" ,
456453 _ => "" ,
457454 }
458455 } else {
459456 ""
460457 } ;
461458
462459 let magnitude_string: String = match format_type {
463- DecimalD | DecimalI | DecimalU => magnitude. to_str_radix ( 10 ) ,
464- Octal => magnitude. to_str_radix ( 8 ) ,
465- HexLower => magnitude. to_str_radix ( 16 ) ,
466- HexUpper => {
460+ CNumberType :: DecimalD | CNumberType :: DecimalI | CNumberType :: DecimalU => {
461+ magnitude. to_str_radix ( 10 )
462+ }
463+ CNumberType :: Octal => magnitude. to_str_radix ( 8 ) ,
464+ CNumberType :: HexLower => magnitude. to_str_radix ( 16 ) ,
465+ CNumberType :: HexUpper => {
467466 let mut result = magnitude. to_str_radix ( 16 ) ;
468467 result. make_ascii_uppercase ( ) ;
469468 result
@@ -621,35 +620,33 @@ where
621620 C : FormatChar ,
622621 I : Iterator < Item = C > ,
623622{
624- use CFloatType :: * ;
625- use CNumberType :: * ;
626623 let ( index, c) = iter. next ( ) . ok_or_else ( || {
627624 (
628625 CFormatErrorType :: IncompleteFormat ,
629626 iter. peek ( ) . map_or ( 0 , |x| x. 0 ) ,
630627 )
631628 } ) ?;
632- let format_type = match c. to_char_lossy ( ) {
633- 'd' => CFormatType :: Number ( DecimalD ) ,
634- 'i' => CFormatType :: Number ( DecimalI ) ,
635- 'u' => CFormatType :: Number ( DecimalU ) ,
636- 'o' => CFormatType :: Number ( Octal ) ,
637- 'x' => CFormatType :: Number ( HexLower ) ,
638- 'X' => CFormatType :: Number ( HexUpper ) ,
639- 'e' => CFormatType :: Float ( ExponentLower ) ,
640- 'E' => CFormatType :: Float ( ExponentUpper ) ,
641- 'f' => CFormatType :: Float ( PointDecimalLower ) ,
642- 'F' => CFormatType :: Float ( PointDecimalUpper ) ,
643- 'g' => CFormatType :: Float ( GeneralLower ) ,
644- 'G' => CFormatType :: Float ( GeneralUpper ) ,
629+
630+ Ok ( match c. to_char_lossy ( ) {
631+ 'd' => CFormatType :: Number ( CNumberType :: DecimalD ) ,
632+ 'i' => CFormatType :: Number ( CNumberType :: DecimalI ) ,
633+ 'u' => CFormatType :: Number ( CNumberType :: DecimalU ) ,
634+ 'o' => CFormatType :: Number ( CNumberType :: Octal ) ,
635+ 'x' => CFormatType :: Number ( CNumberType :: HexLower ) ,
636+ 'X' => CFormatType :: Number ( CNumberType :: HexUpper ) ,
637+ 'e' => CFormatType :: Float ( CFloatType :: ExponentLower ) ,
638+ 'E' => CFormatType :: Float ( CFloatType :: ExponentUpper ) ,
639+ 'f' => CFormatType :: Float ( CFloatType :: PointDecimalLower ) ,
640+ 'F' => CFormatType :: Float ( CFloatType :: PointDecimalUpper ) ,
641+ 'g' => CFormatType :: Float ( CFloatType :: GeneralLower ) ,
642+ 'G' => CFormatType :: Float ( CFloatType :: GeneralUpper ) ,
645643 'c' => CFormatType :: Character ( CCharacterType :: Character ) ,
646644 'r' => CFormatType :: String ( CFormatConversion :: Repr ) ,
647645 's' => CFormatType :: String ( CFormatConversion :: Str ) ,
648646 'b' => CFormatType :: String ( CFormatConversion :: Bytes ) ,
649647 'a' => CFormatType :: String ( CFormatConversion :: Ascii ) ,
650648 _ => return Err ( ( CFormatErrorType :: UnsupportedFormatChar ( c. into ( ) ) , index) ) ,
651- } ;
652- Ok ( format_type)
649+ } )
653650}
654651
655652fn parse_quantity < C , I > ( iter : & mut ParseIter < I > ) -> Result < Option < CFormatQuantity > , ParsingError >
0 commit comments