@@ -40,23 +40,23 @@ impl FormatParse for FormatConversion {
4040}
4141
4242impl FormatConversion {
43- pub fn from_char ( c : CodePoint ) -> Option < FormatConversion > {
43+ pub fn from_char ( c : CodePoint ) -> Option < Self > {
4444 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 ) ,
4949 _ => None ,
5050 }
5151 }
5252
53- fn from_string ( text : & Wtf8 ) -> Option < FormatConversion > {
53+ fn from_string ( text : & Wtf8 ) -> Option < Self > {
5454 let mut chars = text. code_points ( ) ;
5555 if chars. next ( ) ? != '!' {
5656 return None ;
5757 }
5858
59- FormatConversion :: from_char ( chars. next ( ) ?)
59+ Self :: from_char ( chars. next ( ) ?)
6060 }
6161}
6262
@@ -69,12 +69,12 @@ pub enum FormatAlign {
6969}
7070
7171impl FormatAlign {
72- fn from_char ( c : CodePoint ) -> Option < FormatAlign > {
72+ fn from_char ( c : CodePoint ) -> Option < Self > {
7373 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 ) ,
7878 _ => None ,
7979 }
8080 }
@@ -143,7 +143,7 @@ pub enum FormatType {
143143}
144144
145145impl From < & FormatType > for char {
146- fn from ( from : & FormatType ) -> char {
146+ fn from ( from : & FormatType ) -> Self {
147147 match from {
148148 FormatType :: String => 's' ,
149149 FormatType :: Binary => 'b' ,
@@ -301,7 +301,7 @@ impl FormatSpec {
301301 align = align. or ( Some ( FormatAlign :: AfterSign ) ) ;
302302 }
303303
304- Ok ( FormatSpec {
304+ Ok ( Self {
305305 conversion,
306306 fill,
307307 align,
@@ -329,7 +329,7 @@ impl FormatSpec {
329329 let magnitude_int_str = parts. next ( ) . unwrap ( ) . to_string ( ) ;
330330 let dec_digit_cnt = magnitude_str. len ( ) as i32 - magnitude_int_str. len ( ) as i32 ;
331331 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) ;
333333 if let Some ( part) = parts. next ( ) {
334334 result. push_str ( & format ! ( ".{part}" ) )
335335 }
@@ -352,11 +352,11 @@ impl FormatSpec {
352352 // separate with 0 padding
353353 let padding = "0" . repeat ( diff as usize ) ;
354354 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)
356356 } else {
357357 // separate without padding
358358 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)
360360 }
361361 }
362362
@@ -414,12 +414,7 @@ impl FormatSpec {
414414 let magnitude_len = magnitude_str. len ( ) ;
415415 let width = self . width . unwrap_or ( magnitude_len) as i32 - prefix. len ( ) as i32 ;
416416 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)
423418 }
424419 None => magnitude_str,
425420 }
@@ -762,27 +757,26 @@ impl FormatSpec {
762757 "{}{}{}" ,
763758 sign_str,
764759 magnitude_str,
765- FormatSpec :: compute_fill_string( fill_char, fill_chars_needed)
760+ Self :: compute_fill_string( fill_char, fill_chars_needed)
766761 ) ,
767762 FormatAlign :: Right => format ! (
768763 "{}{}{}" ,
769- FormatSpec :: compute_fill_string( fill_char, fill_chars_needed) ,
764+ Self :: compute_fill_string( fill_char, fill_chars_needed) ,
770765 sign_str,
771766 magnitude_str
772767 ) ,
773768 FormatAlign :: AfterSign => format ! (
774769 "{}{}{}" ,
775770 sign_str,
776- FormatSpec :: compute_fill_string( fill_char, fill_chars_needed) ,
771+ Self :: compute_fill_string( fill_char, fill_chars_needed) ,
777772 magnitude_str
778773 ) ,
779774 FormatAlign :: Center => {
780775 let left_fill_chars_needed = fill_chars_needed / 2 ;
781776 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) ;
784778 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) ;
786780 format ! ( "{left_fill_string}{sign_str}{magnitude_str}{right_fill_string}" )
787781 }
788782 } )
@@ -849,7 +843,7 @@ pub enum FormatParseError {
849843impl FromStr for FormatSpec {
850844 type Err = FormatSpecError ;
851845 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
852- FormatSpec :: parse ( s)
846+ Self :: parse ( s)
853847 }
854848}
855849
@@ -863,7 +857,7 @@ pub enum FieldNamePart {
863857impl FieldNamePart {
864858 fn parse_part (
865859 chars : & mut impl PeekingNext < Item = CodePoint > ,
866- ) -> Result < Option < FieldNamePart > , FormatParseError > {
860+ ) -> Result < Option < Self > , FormatParseError > {
867861 chars
868862 . next ( )
869863 . map ( |ch| match ch. to_char_lossy ( ) {
@@ -875,7 +869,7 @@ impl FieldNamePart {
875869 if attribute. is_empty ( ) {
876870 Err ( FormatParseError :: EmptyAttribute )
877871 } else {
878- Ok ( FieldNamePart :: Attribute ( attribute) )
872+ Ok ( Self :: Attribute ( attribute) )
879873 }
880874 }
881875 '[' => {
@@ -885,9 +879,9 @@ impl FieldNamePart {
885879 return if index. is_empty ( ) {
886880 Err ( FormatParseError :: EmptyAttribute )
887881 } else if let Some ( index) = parse_usize ( & index) {
888- Ok ( FieldNamePart :: Index ( index) )
882+ Ok ( Self :: Index ( index) )
889883 } else {
890- Ok ( FieldNamePart :: StringIndex ( index) )
884+ Ok ( Self :: StringIndex ( index) )
891885 } ;
892886 }
893887 index. push ( ch) ;
@@ -918,7 +912,7 @@ fn parse_usize(s: &Wtf8) -> Option<usize> {
918912}
919913
920914impl FieldName {
921- pub fn parse ( text : & Wtf8 ) -> Result < FieldName , FormatParseError > {
915+ pub fn parse ( text : & Wtf8 ) -> Result < Self , FormatParseError > {
922916 let mut chars = text. code_points ( ) . peekable ( ) ;
923917 let first: Wtf8Buf = chars
924918 . peeking_take_while ( |ch| * ch != '.' && * ch != '[' )
@@ -937,7 +931,7 @@ impl FieldName {
937931 parts. push ( part)
938932 }
939933
940- Ok ( FieldName { field_type, parts } )
934+ Ok ( Self { field_type, parts } )
941935 }
942936}
943937
@@ -978,7 +972,7 @@ impl FormatString {
978972 let mut cur_text = text;
979973 let mut result_string = Wtf8Buf :: new ( ) ;
980974 while !cur_text. is_empty ( ) {
981- match FormatString :: parse_literal_single ( cur_text) {
975+ match Self :: parse_literal_single ( cur_text) {
982976 Ok ( ( next_char, remaining) ) => {
983977 result_string. push ( next_char) ;
984978 cur_text = remaining;
@@ -1092,7 +1086,7 @@ impl FormatString {
10921086 }
10931087 if let Some ( pos) = end_bracket_pos {
10941088 let right = & text[ pos..] ;
1095- let format_part = FormatString :: parse_part_in_brackets ( & left) ?;
1089+ let format_part = Self :: parse_part_in_brackets ( & left) ?;
10961090 Ok ( ( format_part, & right[ 1 ..] ) )
10971091 } else {
10981092 Err ( FormatParseError :: UnmatchedBracket )
@@ -1114,14 +1108,14 @@ impl<'a> FromTemplate<'a> for FormatString {
11141108 while !cur_text. is_empty ( ) {
11151109 // Try to parse both literals and bracketed format parts until we
11161110 // 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) )
11191113 . map ( |( part, new_text) | {
11201114 parts. push ( part) ;
11211115 new_text
11221116 } ) ?;
11231117 }
1124- Ok ( FormatString {
1118+ Ok ( Self {
11251119 format_parts : parts,
11261120 } )
11271121 }
0 commit comments