For a project I have to implement some formatting of values with a user-provided format string. Unfortunately, all crates that allow this are either nightly-only (
rt_format) or incomplete.
I'm fine with parsing the format string myself (although Rust could expose its own routine to do it in the library), but there is no stable way to pass formatter parameters, like align/width/precision, dynamically. And I really don't want to reimplement number formatting for all the different types.
I see two ways out of this:
Large impact: make the whole
V1machinery public and stable. Its naming is versioned after all, so I don't see the reason to keep it unstable; a new version would probably introduce new
V2APIs? (Also, has the V1 API changed incompatibly at all since Rust 1?)
Less impact: make the formatting settings of the
Formatterread-write accessible. For example,
fill()could get a setter
set_fill()and so on. I'm not aware of a downsides here, and the new API surface is pretty minimal and does not expose any of the
V1machinery. It does mean that Debug/Display/... impls can change user intention given by the format string, but they're already free to ignore it completely and just write whatever to the formatter.
Alternative, also less impact: allow stable creation of an
Argumentsinstance with flags selected at runtime, for the very restricted case of only one value to format. This can then be passed to
write_fmt, again without exposing any
What do you think? Does this need an RFC? I'm obviously willing to work on any chosen solution.