@@ -336,7 +336,7 @@ fn strip_default_padding(value: &str) -> String {
336336/// than minimum field width, and the digit zeros are significant content,
337337/// not padding.
338338fn is_nanosecond_specifier ( specifier : & str ) -> bool {
339- specifier. chars ( ) . last ( ) == Some ( 'N' )
339+ specifier. ends_with ( 'N' )
340340}
341341
342342/// Apply modifiers specifically for the `%N` (nanoseconds) specifier.
@@ -356,11 +356,10 @@ fn apply_nanosecond_modifiers(
356356 no_pad : bool ,
357357 underscore_flag : bool ,
358358 pad_char : char ,
359- width : usize ,
360- explicit_width : bool ,
361- ) -> Result < String , FormatError > {
359+ width : Option < usize > ,
360+ ) -> String {
362361 let default_width = 9 ;
363- let precision = if explicit_width { width } else { default_width } ;
362+ let precision = width. unwrap_or ( default_width) ;
364363
365364 // Truncate or extend to the requested precision
366365 let mut result: String = if precision <= value. len ( ) {
@@ -390,7 +389,7 @@ fn apply_nanosecond_modifiers(
390389 // Otherwise (default '0' padding or no flags): result already has the
391390 // right number of zero-padded digits from the truncation/extension above.
392391
393- Ok ( result)
392+ result
394393}
395394
396395/// Apply width and flag modifiers to a formatted value.
@@ -475,7 +474,13 @@ fn apply_modifiers(value: &str, parsed: &ParsedSpec<'_>) -> Result<String, Forma
475474 // (number of fractional digits), not minimum field width, and the
476475 // digit zeros are significant content rather than padding.
477476 if is_nanosecond_specifier ( specifier) {
478- return apply_nanosecond_modifiers ( & result, no_pad, underscore_flag, pad_char, width, explicit_width) ;
477+ return Ok ( apply_nanosecond_modifiers (
478+ & result,
479+ no_pad,
480+ underscore_flag,
481+ pad_char,
482+ width,
483+ ) ) ;
479484 }
480485
481486 // If no_pad flag is active, suppress all padding and return
@@ -1124,7 +1129,10 @@ mod tests {
11241129
11251130 // %_N: space-pad without width → 9 digits, trailing zeros → spaces
11261131 let result = format_with_modifiers ( & date, "%_N" , & config) . unwrap ( ) ;
1127- assert_eq ! ( result, "0 " , "GNU: %_N at @0 should be '0' + 8 spaces" ) ;
1132+ assert_eq ! (
1133+ result, "0 " ,
1134+ "GNU: %_N at @0 should be '0' + 8 spaces"
1135+ ) ;
11281136 }
11291137
11301138 #[ test]
0 commit comments