@@ -1060,7 +1060,7 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
1060
1060
// a string piece.
1061
1061
for ( arg, piece) in fmt. iter ( ) . zip ( args. pieces . iter ( ) ) {
1062
1062
formatter. buf . write_str ( * piece) ?;
1063
- formatter . run ( arg) ?;
1063
+ run ( & mut formatter , arg) ?;
1064
1064
idx += 1 ;
1065
1065
}
1066
1066
}
@@ -1074,6 +1074,40 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
1074
1074
Ok ( ( ) )
1075
1075
}
1076
1076
1077
+ fn run ( fmt : & mut Formatter < ' _ > , arg : & rt:: v1:: Argument ) -> Result {
1078
+ // Fill in the format parameters into the formatter
1079
+ fmt. fill = arg. format . fill ;
1080
+ fmt. align = arg. format . align ;
1081
+ fmt. flags = arg. format . flags ;
1082
+ fmt. width = getcount ( & fmt. args , & arg. format . width ) ;
1083
+ fmt. precision = getcount ( & fmt. args , & arg. format . precision ) ;
1084
+
1085
+ // Extract the correct argument
1086
+ let value = {
1087
+ #[ cfg( bootstrap) ]
1088
+ {
1089
+ match arg. position {
1090
+ rt:: v1:: Position :: At ( i) => fmt. args [ i] ,
1091
+ }
1092
+ }
1093
+ #[ cfg( not( bootstrap) ) ]
1094
+ {
1095
+ fmt. args [ arg. position ]
1096
+ }
1097
+ } ;
1098
+
1099
+ // Then actually do some printing
1100
+ ( value. formatter ) ( value. value , fmt)
1101
+ }
1102
+
1103
+ fn getcount ( args : & [ ArgumentV1 < ' _ > ] , cnt : & rt:: v1:: Count ) -> Option < usize > {
1104
+ match * cnt {
1105
+ rt:: v1:: Count :: Is ( n) => Some ( n) ,
1106
+ rt:: v1:: Count :: Implied => None ,
1107
+ rt:: v1:: Count :: Param ( i) => args[ i] . as_usize ( ) ,
1108
+ }
1109
+ }
1110
+
1077
1111
/// Padding after the end of something. Returned by `Formatter::padding`.
1078
1112
#[ must_use = "don't forget to write the post padding" ]
1079
1113
struct PostPadding {
@@ -1118,43 +1152,6 @@ impl<'a> Formatter<'a> {
1118
1152
}
1119
1153
}
1120
1154
1121
- // First up is the collection of functions used to execute a format string
1122
- // at runtime. This consumes all of the compile-time statics generated by
1123
- // the format! syntax extension.
1124
- fn run ( & mut self , arg : & rt:: v1:: Argument ) -> Result {
1125
- // Fill in the format parameters into the formatter
1126
- self . fill = arg. format . fill ;
1127
- self . align = arg. format . align ;
1128
- self . flags = arg. format . flags ;
1129
- self . width = self . getcount ( & arg. format . width ) ;
1130
- self . precision = self . getcount ( & arg. format . precision ) ;
1131
-
1132
- // Extract the correct argument
1133
- let value = {
1134
- #[ cfg( bootstrap) ]
1135
- {
1136
- match arg. position {
1137
- rt:: v1:: Position :: At ( i) => self . args [ i] ,
1138
- }
1139
- }
1140
- #[ cfg( not( bootstrap) ) ]
1141
- {
1142
- self . args [ arg. position ]
1143
- }
1144
- } ;
1145
-
1146
- // Then actually do some printing
1147
- ( value. formatter ) ( value. value , self )
1148
- }
1149
-
1150
- fn getcount ( & mut self , cnt : & rt:: v1:: Count ) -> Option < usize > {
1151
- match * cnt {
1152
- rt:: v1:: Count :: Is ( n) => Some ( n) ,
1153
- rt:: v1:: Count :: Implied => None ,
1154
- rt:: v1:: Count :: Param ( i) => self . args [ i] . as_usize ( ) ,
1155
- }
1156
- }
1157
-
1158
1155
// Helper methods used for padding and processing formatting arguments that
1159
1156
// all formatting traits can use.
1160
1157
0 commit comments