@@ -38,23 +38,23 @@ impl FormatParse for FormatConversion {
38
38
}
39
39
40
40
impl FormatConversion {
41
- pub fn from_char ( c : CodePoint ) -> Option < FormatConversion > {
41
+ pub fn from_char ( c : CodePoint ) -> Option < Self > {
42
42
match c. to_char_lossy ( ) {
43
- 's' => Some ( FormatConversion :: Str ) ,
44
- 'r' => Some ( FormatConversion :: Repr ) ,
45
- 'a' => Some ( FormatConversion :: Ascii ) ,
46
- 'b' => Some ( FormatConversion :: Bytes ) ,
43
+ 's' => Some ( Self :: Str ) ,
44
+ 'r' => Some ( Self :: Repr ) ,
45
+ 'a' => Some ( Self :: Ascii ) ,
46
+ 'b' => Some ( Self :: Bytes ) ,
47
47
_ => None ,
48
48
}
49
49
}
50
50
51
- fn from_string ( text : & Wtf8 ) -> Option < FormatConversion > {
51
+ fn from_string ( text : & Wtf8 ) -> Option < Self > {
52
52
let mut chars = text. code_points ( ) ;
53
53
if chars. next ( ) ? != '!' {
54
54
return None ;
55
55
}
56
56
57
- FormatConversion :: from_char ( chars. next ( ) ?)
57
+ Self :: from_char ( chars. next ( ) ?)
58
58
}
59
59
}
60
60
@@ -67,12 +67,12 @@ pub enum FormatAlign {
67
67
}
68
68
69
69
impl FormatAlign {
70
- fn from_char ( c : CodePoint ) -> Option < FormatAlign > {
70
+ fn from_char ( c : CodePoint ) -> Option < Self > {
71
71
match c. to_char_lossy ( ) {
72
- '<' => Some ( FormatAlign :: Left ) ,
73
- '>' => Some ( FormatAlign :: Right ) ,
74
- '=' => Some ( FormatAlign :: AfterSign ) ,
75
- '^' => Some ( FormatAlign :: Center ) ,
72
+ '<' => Some ( Self :: Left ) ,
73
+ '>' => Some ( Self :: Right ) ,
74
+ '=' => Some ( Self :: AfterSign ) ,
75
+ '^' => Some ( Self :: Center ) ,
76
76
_ => None ,
77
77
}
78
78
}
@@ -141,7 +141,7 @@ pub enum FormatType {
141
141
}
142
142
143
143
impl From < & FormatType > for char {
144
- fn from ( from : & FormatType ) -> char {
144
+ fn from ( from : & FormatType ) -> Self {
145
145
match from {
146
146
FormatType :: String => 's' ,
147
147
FormatType :: Binary => 'b' ,
@@ -299,7 +299,7 @@ impl FormatSpec {
299
299
align = align. or ( Some ( FormatAlign :: AfterSign ) ) ;
300
300
}
301
301
302
- Ok ( FormatSpec {
302
+ Ok ( Self {
303
303
conversion,
304
304
fill,
305
305
align,
@@ -327,7 +327,7 @@ impl FormatSpec {
327
327
let magnitude_int_str = parts. next ( ) . unwrap ( ) . to_string ( ) ;
328
328
let dec_digit_cnt = magnitude_str. len ( ) as i32 - magnitude_int_str. len ( ) as i32 ;
329
329
let int_digit_cnt = disp_digit_cnt - dec_digit_cnt;
330
- let mut result = FormatSpec :: separate_integer ( magnitude_int_str, inter, sep, int_digit_cnt) ;
330
+ let mut result = Self :: separate_integer ( magnitude_int_str, inter, sep, int_digit_cnt) ;
331
331
if let Some ( part) = parts. next ( ) {
332
332
result. push_str ( & format ! ( ".{part}" ) )
333
333
}
@@ -350,11 +350,11 @@ impl FormatSpec {
350
350
// separate with 0 padding
351
351
let padding = "0" . repeat ( diff as usize ) ;
352
352
let padded_num = format ! ( "{padding}{magnitude_str}" ) ;
353
- FormatSpec :: insert_separator ( padded_num, inter, sep, sep_cnt)
353
+ Self :: insert_separator ( padded_num, inter, sep, sep_cnt)
354
354
} else {
355
355
// separate without padding
356
356
let sep_cnt = ( magnitude_len - 1 ) / inter;
357
- FormatSpec :: insert_separator ( magnitude_str, inter, sep, sep_cnt)
357
+ Self :: insert_separator ( magnitude_str, inter, sep, sep_cnt)
358
358
}
359
359
}
360
360
@@ -412,12 +412,7 @@ impl FormatSpec {
412
412
let magnitude_len = magnitude_str. len ( ) ;
413
413
let width = self . width . unwrap_or ( magnitude_len) as i32 - prefix. len ( ) as i32 ;
414
414
let disp_digit_cnt = cmp:: max ( width, magnitude_len as i32 ) ;
415
- FormatSpec :: add_magnitude_separators_for_char (
416
- magnitude_str,
417
- inter,
418
- sep,
419
- disp_digit_cnt,
420
- )
415
+ Self :: add_magnitude_separators_for_char ( magnitude_str, inter, sep, disp_digit_cnt)
421
416
}
422
417
None => magnitude_str,
423
418
}
@@ -640,27 +635,26 @@ impl FormatSpec {
640
635
"{}{}{}" ,
641
636
sign_str,
642
637
magnitude_str,
643
- FormatSpec :: compute_fill_string( fill_char, fill_chars_needed)
638
+ Self :: compute_fill_string( fill_char, fill_chars_needed)
644
639
) ,
645
640
FormatAlign :: Right => format ! (
646
641
"{}{}{}" ,
647
- FormatSpec :: compute_fill_string( fill_char, fill_chars_needed) ,
642
+ Self :: compute_fill_string( fill_char, fill_chars_needed) ,
648
643
sign_str,
649
644
magnitude_str
650
645
) ,
651
646
FormatAlign :: AfterSign => format ! (
652
647
"{}{}{}" ,
653
648
sign_str,
654
- FormatSpec :: compute_fill_string( fill_char, fill_chars_needed) ,
649
+ Self :: compute_fill_string( fill_char, fill_chars_needed) ,
655
650
magnitude_str
656
651
) ,
657
652
FormatAlign :: Center => {
658
653
let left_fill_chars_needed = fill_chars_needed / 2 ;
659
654
let right_fill_chars_needed = fill_chars_needed - left_fill_chars_needed;
660
- let left_fill_string =
661
- FormatSpec :: compute_fill_string ( fill_char, left_fill_chars_needed) ;
655
+ let left_fill_string = Self :: compute_fill_string ( fill_char, left_fill_chars_needed) ;
662
656
let right_fill_string =
663
- FormatSpec :: compute_fill_string ( fill_char, right_fill_chars_needed) ;
657
+ Self :: compute_fill_string ( fill_char, right_fill_chars_needed) ;
664
658
format ! ( "{left_fill_string}{sign_str}{magnitude_str}{right_fill_string}" )
665
659
}
666
660
} )
@@ -725,7 +719,7 @@ pub enum FormatParseError {
725
719
impl FromStr for FormatSpec {
726
720
type Err = FormatSpecError ;
727
721
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
728
- FormatSpec :: parse ( s)
722
+ Self :: parse ( s)
729
723
}
730
724
}
731
725
@@ -739,7 +733,7 @@ pub enum FieldNamePart {
739
733
impl FieldNamePart {
740
734
fn parse_part (
741
735
chars : & mut impl PeekingNext < Item = CodePoint > ,
742
- ) -> Result < Option < FieldNamePart > , FormatParseError > {
736
+ ) -> Result < Option < Self > , FormatParseError > {
743
737
chars
744
738
. next ( )
745
739
. map ( |ch| match ch. to_char_lossy ( ) {
@@ -751,7 +745,7 @@ impl FieldNamePart {
751
745
if attribute. is_empty ( ) {
752
746
Err ( FormatParseError :: EmptyAttribute )
753
747
} else {
754
- Ok ( FieldNamePart :: Attribute ( attribute) )
748
+ Ok ( Self :: Attribute ( attribute) )
755
749
}
756
750
}
757
751
'[' => {
@@ -761,9 +755,9 @@ impl FieldNamePart {
761
755
return if index. is_empty ( ) {
762
756
Err ( FormatParseError :: EmptyAttribute )
763
757
} else if let Some ( index) = parse_usize ( & index) {
764
- Ok ( FieldNamePart :: Index ( index) )
758
+ Ok ( Self :: Index ( index) )
765
759
} else {
766
- Ok ( FieldNamePart :: StringIndex ( index) )
760
+ Ok ( Self :: StringIndex ( index) )
767
761
} ;
768
762
}
769
763
index. push ( ch) ;
@@ -794,7 +788,7 @@ fn parse_usize(s: &Wtf8) -> Option<usize> {
794
788
}
795
789
796
790
impl FieldName {
797
- pub fn parse ( text : & Wtf8 ) -> Result < FieldName , FormatParseError > {
791
+ pub fn parse ( text : & Wtf8 ) -> Result < Self , FormatParseError > {
798
792
let mut chars = text. code_points ( ) . peekable ( ) ;
799
793
let first: Wtf8Buf = chars
800
794
. peeking_take_while ( |ch| * ch != '.' && * ch != '[' )
@@ -813,7 +807,7 @@ impl FieldName {
813
807
parts. push ( part)
814
808
}
815
809
816
- Ok ( FieldName { field_type, parts } )
810
+ Ok ( Self { field_type, parts } )
817
811
}
818
812
}
819
813
@@ -854,7 +848,7 @@ impl FormatString {
854
848
let mut cur_text = text;
855
849
let mut result_string = Wtf8Buf :: new ( ) ;
856
850
while !cur_text. is_empty ( ) {
857
- match FormatString :: parse_literal_single ( cur_text) {
851
+ match Self :: parse_literal_single ( cur_text) {
858
852
Ok ( ( next_char, remaining) ) => {
859
853
result_string. push ( next_char) ;
860
854
cur_text = remaining;
@@ -968,7 +962,7 @@ impl FormatString {
968
962
}
969
963
if let Some ( pos) = end_bracket_pos {
970
964
let right = & text[ pos..] ;
971
- let format_part = FormatString :: parse_part_in_brackets ( & left) ?;
965
+ let format_part = Self :: parse_part_in_brackets ( & left) ?;
972
966
Ok ( ( format_part, & right[ 1 ..] ) )
973
967
} else {
974
968
Err ( FormatParseError :: UnmatchedBracket )
@@ -990,14 +984,14 @@ impl<'a> FromTemplate<'a> for FormatString {
990
984
while !cur_text. is_empty ( ) {
991
985
// Try to parse both literals and bracketed format parts until we
992
986
// run out of text
993
- cur_text = FormatString :: parse_literal ( cur_text)
994
- . or_else ( |_| FormatString :: parse_spec ( cur_text) )
987
+ cur_text = Self :: parse_literal ( cur_text)
988
+ . or_else ( |_| Self :: parse_spec ( cur_text) )
995
989
. map ( |( part, new_text) | {
996
990
parts. push ( part) ;
997
991
new_text
998
992
} ) ?;
999
993
}
1000
- Ok ( FormatString {
994
+ Ok ( Self {
1001
995
format_parts : parts,
1002
996
} )
1003
997
}
0 commit comments