error bad-format-spec
Неверный спецификатор формата в интерполяции строки.
What it means#
The text after the top-level : of {expr:spec} is checked at compile time against the type of expr. Grammar: [[fill]align][sign][#][0][width][.precision][type]; align is < ^ >; sign + or -; the type is x X o b for integers, e E for floats, ? for str and char, and a unit ns us ms s m h d for Duration. Time, LocalDateTime and Date take a pattern (§17.5); a type with fn fmt(spec: str) -> str takes its own spec; any other type shows its text and only fill, align, width and precision apply. .N is not valid for integers, 0 and a sign only for numbers.
Example#
fn f(x: i64, name: str) -> str {
"{name:x} {x:.2}" // <- bad-format-spec
}error
bad-format-spec
How to fix#
Use a specifier that matches the type: {x:08x} for an integer, {y:.2} for a float, {d:ms} for a duration, {name:>8} for text.
fn f(x: i64, y: f64, d: Duration, name: str) -> str {
"{x:08x} {y:.2} {d:ms} {name:>8}"
}