@@ -591,36 +591,40 @@ pub(crate) enum FieldNamePart {
591
591
impl FieldNamePart {
592
592
fn parse_part (
593
593
chars : & mut impl PeekingNext < Item = char > ,
594
- ) -> Result < FieldNamePart , FormatParseError > {
595
- let ch = chars. next ( ) . unwrap ( ) ;
596
- if ch == '.' {
597
- let mut attribute = String :: new ( ) ;
598
- for ch in chars. peeking_take_while ( |ch| * ch != '.' && * ch != '[' ) {
599
- attribute. push ( ch) ;
600
- }
601
- if attribute. is_empty ( ) {
602
- Err ( FormatParseError :: EmptyAttribute )
603
- } else {
604
- Ok ( FieldNamePart :: Attribute ( attribute) )
605
- }
606
- } else if ch == '[' {
607
- let mut index = String :: new ( ) ;
608
- for ch in chars {
609
- if ch == ']' {
610
- return if index. is_empty ( ) {
594
+ ) -> Result < Option < FieldNamePart > , FormatParseError > {
595
+ chars
596
+ . next ( )
597
+ . map ( |ch| match ch {
598
+ '.' => {
599
+ let mut attribute = String :: new ( ) ;
600
+ for ch in chars. peeking_take_while ( |ch| * ch != '.' && * ch != '[' ) {
601
+ attribute. push ( ch) ;
602
+ }
603
+ if attribute. is_empty ( ) {
611
604
Err ( FormatParseError :: EmptyAttribute )
612
- } else if let Ok ( index) = index. parse :: < usize > ( ) {
613
- Ok ( FieldNamePart :: Index ( index) )
614
605
} else {
615
- Ok ( FieldNamePart :: StringIndex ( index ) )
616
- } ;
606
+ Ok ( FieldNamePart :: Attribute ( attribute ) )
607
+ }
617
608
}
618
- index. push ( ch) ;
619
- }
620
- Err ( FormatParseError :: MissingRightBracket )
621
- } else {
622
- Err ( FormatParseError :: InvalidCharacterAfterRightBracket )
623
- }
609
+ '[' => {
610
+ let mut index = String :: new ( ) ;
611
+ for ch in chars {
612
+ if ch == ']' {
613
+ return if index. is_empty ( ) {
614
+ Err ( FormatParseError :: EmptyAttribute )
615
+ } else if let Ok ( index) = index. parse :: < usize > ( ) {
616
+ Ok ( FieldNamePart :: Index ( index) )
617
+ } else {
618
+ Ok ( FieldNamePart :: StringIndex ( index) )
619
+ } ;
620
+ }
621
+ index. push ( ch) ;
622
+ }
623
+ Err ( FormatParseError :: MissingRightBracket )
624
+ }
625
+ _ => Err ( FormatParseError :: InvalidCharacterAfterRightBracket ) ,
626
+ } )
627
+ . transpose ( )
624
628
}
625
629
}
626
630
@@ -633,8 +637,8 @@ pub(crate) enum FieldType {
633
637
634
638
#[ derive( Debug , PartialEq ) ]
635
639
pub ( crate ) struct FieldName {
636
- pub ( crate ) field_type : FieldType ,
637
- pub ( crate ) parts : Vec < FieldNamePart > ,
640
+ pub field_type : FieldType ,
641
+ pub parts : Vec < FieldNamePart > ,
638
642
}
639
643
640
644
impl FieldName {
@@ -654,8 +658,8 @@ impl FieldName {
654
658
} ;
655
659
656
660
let mut parts = Vec :: new ( ) ;
657
- while chars . peek ( ) . is_some ( ) {
658
- parts. push ( FieldNamePart :: parse_part ( & mut chars ) ? )
661
+ while let Some ( part ) = FieldNamePart :: parse_part ( & mut chars ) ? {
662
+ parts. push ( part )
659
663
}
660
664
661
665
Ok ( FieldName { field_type, parts } )
@@ -674,7 +678,7 @@ pub(crate) enum FormatPart {
674
678
675
679
#[ derive( Debug , PartialEq ) ]
676
680
pub ( crate ) struct FormatString {
677
- pub ( crate ) format_parts : Vec < FormatPart > ,
681
+ pub format_parts : Vec < FormatPart > ,
678
682
}
679
683
680
684
impl FormatString {
0 commit comments