@@ -580,7 +580,13 @@ impl FormatSpec {
580580 } ,
581581 } ;
582582
583- self . format_sign_and_align ( & AsciiStr :: new ( & magnitude_str) , sign_str, FormatAlign :: Right )
583+ Ok (
584+ self . format_sign_and_align (
585+ & AsciiStr :: new ( & magnitude_str) ,
586+ sign_str,
587+ FormatAlign :: Right ,
588+ ) ,
589+ )
584590 }
585591
586592 /// Format a float with locale-aware 'n' format.
@@ -620,7 +626,13 @@ impl FormatSpec {
620626 }
621627 } ;
622628
623- self . format_sign_and_align ( & AsciiStr :: new ( & magnitude_str) , sign_str, FormatAlign :: Right )
629+ Ok (
630+ self . format_sign_and_align (
631+ & AsciiStr :: new ( & magnitude_str) ,
632+ sign_str,
633+ FormatAlign :: Right ,
634+ ) ,
635+ )
624636 }
625637
626638 /// Format a complex number with locale-aware 'n' format.
@@ -672,7 +684,7 @@ impl FormatSpec {
672684 // No parentheses for 'n' format (CPython: add_parens=0)
673685 let magnitude_str = format ! ( "{grouped_re}{grouped_im}" ) ;
674686
675- self . format_sign_and_align ( & AsciiStr :: new ( & magnitude_str) , "" , FormatAlign :: Right )
687+ Ok ( self . format_sign_and_align ( & AsciiStr :: new ( & magnitude_str) , "" , FormatAlign :: Right ) )
676688 }
677689
678690 pub fn format_bool ( & self , input : bool ) -> Result < String , FormatSpecError > {
@@ -789,7 +801,13 @@ impl FormatSpec {
789801 }
790802 } ;
791803 let magnitude_str = self . add_magnitude_separators ( raw_magnitude_str?, sign_str) ;
792- self . format_sign_and_align ( & AsciiStr :: new ( & magnitude_str) , sign_str, FormatAlign :: Right )
804+ Ok (
805+ self . format_sign_and_align (
806+ & AsciiStr :: new ( & magnitude_str) ,
807+ sign_str,
808+ FormatAlign :: Right ,
809+ ) ,
810+ )
793811 }
794812
795813 #[ inline]
@@ -863,11 +881,11 @@ impl FormatSpec {
863881 } ;
864882 let sign_prefix = format ! ( "{sign_str}{prefix}" ) ;
865883 let magnitude_str = self . add_magnitude_separators ( raw_magnitude_str, & sign_prefix) ;
866- self . format_sign_and_align (
884+ Ok ( self . format_sign_and_align (
867885 & AsciiStr :: new ( & magnitude_str) ,
868886 & sign_prefix,
869887 FormatAlign :: Right ,
870- )
888+ ) )
871889 }
872890
873891 pub fn format_string < T > ( & self , s : & T ) -> Result < String , FormatSpecError >
@@ -883,7 +901,7 @@ impl FormatSpec {
883901 Some ( p) => s. deref ( ) . chars ( ) . take ( p) . collect ( ) ,
884902 None => s. deref ( ) . to_owned ( ) ,
885903 } ;
886- self . format_sign_and_align ( & truncated, "" , FormatAlign :: Left )
904+ Ok ( self . format_sign_and_align ( & truncated, "" , FormatAlign :: Left ) )
887905 }
888906 _ => {
889907 let ch = char:: from ( self . format_type . as_ref ( ) . unwrap ( ) ) ;
@@ -905,7 +923,11 @@ impl FormatSpec {
905923 }
906924 match & self . fill . unwrap_or_else ( || ' ' . into ( ) ) . to_char ( ) {
907925 Some ( '0' ) => Err ( FormatSpecError :: ZeroPadding ) ,
908- _ => self . format_sign_and_align ( & AsciiStr :: new ( & magnitude_str) , "" , FormatAlign :: Right ) ,
926+ _ => Ok ( self . format_sign_and_align (
927+ & AsciiStr :: new ( & magnitude_str) ,
928+ "" ,
929+ FormatAlign :: Right ,
930+ ) ) ,
909931 }
910932 }
911933
@@ -1017,7 +1039,7 @@ impl FormatSpec {
10171039 magnitude_str : & T ,
10181040 sign_str : & str ,
10191041 default_align : FormatAlign ,
1020- ) -> Result < String , FormatSpecError >
1042+ ) -> String
10211043 where
10221044 T : CharLen + Deref < Target = str > ,
10231045 {
@@ -1030,7 +1052,7 @@ impl FormatSpec {
10301052 } ) ;
10311053
10321054 let magnitude_str = magnitude_str. deref ( ) ;
1033- Ok ( match align {
1055+ match align {
10341056 FormatAlign :: Left => format ! (
10351057 "{}{}{}" ,
10361058 sign_str,
@@ -1057,7 +1079,7 @@ impl FormatSpec {
10571079 Self :: compute_fill_string ( fill_char, right_fill_chars_needed) ;
10581080 format ! ( "{left_fill_string}{sign_str}{magnitude_str}{right_fill_string}" )
10591081 }
1060- } )
1082+ }
10611083 }
10621084}
10631085
0 commit comments