@@ -40,23 +40,23 @@ impl FormatParse for FormatConversion {
40
40
}
41
41
42
42
impl FormatConversion {
43
- pub fn from_char ( c : CodePoint ) -> Option < FormatConversion > {
43
+ pub fn from_char ( c : CodePoint ) -> Option < Self > {
44
44
match c. to_char_lossy ( ) {
45
- 's' => Some ( FormatConversion :: Str ) ,
46
- 'r' => Some ( FormatConversion :: Repr ) ,
47
- 'a' => Some ( FormatConversion :: Ascii ) ,
48
- 'b' => Some ( FormatConversion :: Bytes ) ,
45
+ 's' => Some ( Self :: Str ) ,
46
+ 'r' => Some ( Self :: Repr ) ,
47
+ 'a' => Some ( Self :: Ascii ) ,
48
+ 'b' => Some ( Self :: Bytes ) ,
49
49
_ => None ,
50
50
}
51
51
}
52
52
53
- fn from_string ( text : & Wtf8 ) -> Option < FormatConversion > {
53
+ fn from_string ( text : & Wtf8 ) -> Option < Self > {
54
54
let mut chars = text. code_points ( ) ;
55
55
if chars. next ( ) ? != '!' {
56
56
return None ;
57
57
}
58
58
59
- FormatConversion :: from_char ( chars. next ( ) ?)
59
+ Self :: from_char ( chars. next ( ) ?)
60
60
}
61
61
}
62
62
@@ -69,12 +69,12 @@ pub enum FormatAlign {
69
69
}
70
70
71
71
impl FormatAlign {
72
- fn from_char ( c : CodePoint ) -> Option < FormatAlign > {
72
+ fn from_char ( c : CodePoint ) -> Option < Self > {
73
73
match c. to_char_lossy ( ) {
74
- '<' => Some ( FormatAlign :: Left ) ,
75
- '>' => Some ( FormatAlign :: Right ) ,
76
- '=' => Some ( FormatAlign :: AfterSign ) ,
77
- '^' => Some ( FormatAlign :: Center ) ,
74
+ '<' => Some ( Self :: Left ) ,
75
+ '>' => Some ( Self :: Right ) ,
76
+ '=' => Some ( Self :: AfterSign ) ,
77
+ '^' => Some ( Self :: Center ) ,
78
78
_ => None ,
79
79
}
80
80
}
@@ -143,7 +143,7 @@ pub enum FormatType {
143
143
}
144
144
145
145
impl From < & FormatType > for char {
146
- fn from ( from : & FormatType ) -> char {
146
+ fn from ( from : & FormatType ) -> Self {
147
147
match from {
148
148
FormatType :: String => 's' ,
149
149
FormatType :: Binary => 'b' ,
@@ -301,7 +301,7 @@ impl FormatSpec {
301
301
align = align. or ( Some ( FormatAlign :: AfterSign ) ) ;
302
302
}
303
303
304
- Ok ( FormatSpec {
304
+ Ok ( Self {
305
305
conversion,
306
306
fill,
307
307
align,
@@ -329,7 +329,7 @@ impl FormatSpec {
329
329
let magnitude_int_str = parts. next ( ) . unwrap ( ) . to_string ( ) ;
330
330
let dec_digit_cnt = magnitude_str. len ( ) as i32 - magnitude_int_str. len ( ) as i32 ;
331
331
let int_digit_cnt = disp_digit_cnt - dec_digit_cnt;
332
- let mut result = FormatSpec :: separate_integer ( magnitude_int_str, inter, sep, int_digit_cnt) ;
332
+ let mut result = Self :: separate_integer ( magnitude_int_str, inter, sep, int_digit_cnt) ;
333
333
if let Some ( part) = parts. next ( ) {
334
334
result. push_str ( & format ! ( ".{part}" ) )
335
335
}
@@ -352,11 +352,11 @@ impl FormatSpec {
352
352
// separate with 0 padding
353
353
let padding = "0" . repeat ( diff as usize ) ;
354
354
let padded_num = format ! ( "{padding}{magnitude_str}" ) ;
355
- FormatSpec :: insert_separator ( padded_num, inter, sep, sep_cnt)
355
+ Self :: insert_separator ( padded_num, inter, sep, sep_cnt)
356
356
} else {
357
357
// separate without padding
358
358
let sep_cnt = ( magnitude_len - 1 ) / inter;
359
- FormatSpec :: insert_separator ( magnitude_str, inter, sep, sep_cnt)
359
+ Self :: insert_separator ( magnitude_str, inter, sep, sep_cnt)
360
360
}
361
361
}
362
362
@@ -414,12 +414,7 @@ impl FormatSpec {
414
414
let magnitude_len = magnitude_str. len ( ) ;
415
415
let width = self . width . unwrap_or ( magnitude_len) as i32 - prefix. len ( ) as i32 ;
416
416
let disp_digit_cnt = cmp:: max ( width, magnitude_len as i32 ) ;
417
- FormatSpec :: add_magnitude_separators_for_char (
418
- magnitude_str,
419
- inter,
420
- sep,
421
- disp_digit_cnt,
422
- )
417
+ Self :: add_magnitude_separators_for_char ( magnitude_str, inter, sep, disp_digit_cnt)
423
418
}
424
419
None => magnitude_str,
425
420
}
@@ -762,27 +757,26 @@ impl FormatSpec {
762
757
"{}{}{}" ,
763
758
sign_str,
764
759
magnitude_str,
765
- FormatSpec :: compute_fill_string( fill_char, fill_chars_needed)
760
+ Self :: compute_fill_string( fill_char, fill_chars_needed)
766
761
) ,
767
762
FormatAlign :: Right => format ! (
768
763
"{}{}{}" ,
769
- FormatSpec :: compute_fill_string( fill_char, fill_chars_needed) ,
764
+ Self :: compute_fill_string( fill_char, fill_chars_needed) ,
770
765
sign_str,
771
766
magnitude_str
772
767
) ,
773
768
FormatAlign :: AfterSign => format ! (
774
769
"{}{}{}" ,
775
770
sign_str,
776
- FormatSpec :: compute_fill_string( fill_char, fill_chars_needed) ,
771
+ Self :: compute_fill_string( fill_char, fill_chars_needed) ,
777
772
magnitude_str
778
773
) ,
779
774
FormatAlign :: Center => {
780
775
let left_fill_chars_needed = fill_chars_needed / 2 ;
781
776
let right_fill_chars_needed = fill_chars_needed - left_fill_chars_needed;
782
- let left_fill_string =
783
- FormatSpec :: compute_fill_string ( fill_char, left_fill_chars_needed) ;
777
+ let left_fill_string = Self :: compute_fill_string ( fill_char, left_fill_chars_needed) ;
784
778
let right_fill_string =
785
- FormatSpec :: compute_fill_string ( fill_char, right_fill_chars_needed) ;
779
+ Self :: compute_fill_string ( fill_char, right_fill_chars_needed) ;
786
780
format ! ( "{left_fill_string}{sign_str}{magnitude_str}{right_fill_string}" )
787
781
}
788
782
} )
@@ -849,7 +843,7 @@ pub enum FormatParseError {
849
843
impl FromStr for FormatSpec {
850
844
type Err = FormatSpecError ;
851
845
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
852
- FormatSpec :: parse ( s)
846
+ Self :: parse ( s)
853
847
}
854
848
}
855
849
@@ -863,7 +857,7 @@ pub enum FieldNamePart {
863
857
impl FieldNamePart {
864
858
fn parse_part (
865
859
chars : & mut impl PeekingNext < Item = CodePoint > ,
866
- ) -> Result < Option < FieldNamePart > , FormatParseError > {
860
+ ) -> Result < Option < Self > , FormatParseError > {
867
861
chars
868
862
. next ( )
869
863
. map ( |ch| match ch. to_char_lossy ( ) {
@@ -875,7 +869,7 @@ impl FieldNamePart {
875
869
if attribute. is_empty ( ) {
876
870
Err ( FormatParseError :: EmptyAttribute )
877
871
} else {
878
- Ok ( FieldNamePart :: Attribute ( attribute) )
872
+ Ok ( Self :: Attribute ( attribute) )
879
873
}
880
874
}
881
875
'[' => {
@@ -885,9 +879,9 @@ impl FieldNamePart {
885
879
return if index. is_empty ( ) {
886
880
Err ( FormatParseError :: EmptyAttribute )
887
881
} else if let Some ( index) = parse_usize ( & index) {
888
- Ok ( FieldNamePart :: Index ( index) )
882
+ Ok ( Self :: Index ( index) )
889
883
} else {
890
- Ok ( FieldNamePart :: StringIndex ( index) )
884
+ Ok ( Self :: StringIndex ( index) )
891
885
} ;
892
886
}
893
887
index. push ( ch) ;
@@ -918,7 +912,7 @@ fn parse_usize(s: &Wtf8) -> Option<usize> {
918
912
}
919
913
920
914
impl FieldName {
921
- pub fn parse ( text : & Wtf8 ) -> Result < FieldName , FormatParseError > {
915
+ pub fn parse ( text : & Wtf8 ) -> Result < Self , FormatParseError > {
922
916
let mut chars = text. code_points ( ) . peekable ( ) ;
923
917
let first: Wtf8Buf = chars
924
918
. peeking_take_while ( |ch| * ch != '.' && * ch != '[' )
@@ -937,7 +931,7 @@ impl FieldName {
937
931
parts. push ( part)
938
932
}
939
933
940
- Ok ( FieldName { field_type, parts } )
934
+ Ok ( Self { field_type, parts } )
941
935
}
942
936
}
943
937
@@ -978,7 +972,7 @@ impl FormatString {
978
972
let mut cur_text = text;
979
973
let mut result_string = Wtf8Buf :: new ( ) ;
980
974
while !cur_text. is_empty ( ) {
981
- match FormatString :: parse_literal_single ( cur_text) {
975
+ match Self :: parse_literal_single ( cur_text) {
982
976
Ok ( ( next_char, remaining) ) => {
983
977
result_string. push ( next_char) ;
984
978
cur_text = remaining;
@@ -1092,7 +1086,7 @@ impl FormatString {
1092
1086
}
1093
1087
if let Some ( pos) = end_bracket_pos {
1094
1088
let right = & text[ pos..] ;
1095
- let format_part = FormatString :: parse_part_in_brackets ( & left) ?;
1089
+ let format_part = Self :: parse_part_in_brackets ( & left) ?;
1096
1090
Ok ( ( format_part, & right[ 1 ..] ) )
1097
1091
} else {
1098
1092
Err ( FormatParseError :: UnmatchedBracket )
@@ -1114,14 +1108,14 @@ impl<'a> FromTemplate<'a> for FormatString {
1114
1108
while !cur_text. is_empty ( ) {
1115
1109
// Try to parse both literals and bracketed format parts until we
1116
1110
// run out of text
1117
- cur_text = FormatString :: parse_literal ( cur_text)
1118
- . or_else ( |_| FormatString :: parse_spec ( cur_text) )
1111
+ cur_text = Self :: parse_literal ( cur_text)
1112
+ . or_else ( |_| Self :: parse_spec ( cur_text) )
1119
1113
. map ( |( part, new_text) | {
1120
1114
parts. push ( part) ;
1121
1115
new_text
1122
1116
} ) ?;
1123
1117
}
1124
- Ok ( FormatString {
1118
+ Ok ( Self {
1125
1119
format_parts : parts,
1126
1120
} )
1127
1121
}
0 commit comments