Skip to main content

parse_format_spec

Function parse_format_spec 

Source
pub fn parse_format_spec(s: &str) -> Result<FormatSpec, String>
Expand description

Parse an Excel-style hash-pattern format string.

Accepted shapes (# and 0 interchangeable):

  • "#" / "0" — round to integer, no decimal portion.
  • "#.##" / "0.00" — round to 2 decimal places.
  • "##.###" / "00.000" — round to 3 decimal places.
  • "#." — equivalent to "#" (trailing . allowed, zero decimal places).

Rejects:

  • Empty strings.
  • Printf-style (%3.2f).
  • Multiple .s.
  • Non-#/0 characters (no ,, no %, no e).

Returns the compiled FormatSpec.