A grouping pattern must be static, so none can be built at run time #38
Labels
No labels
kind
bug
kind
enhancement
kind
refactor
workflow
needs-info
workflow
needs-triage
workflow
ready-for-agent
workflow
ready-for-human
workflow
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
rosa/lucre#38
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What to build
Format::groupingtakes a&'static [u8], so a grouping pattern can only bewritten into the program. One read from a configuration file or chosen at run
time cannot be used.
The same lifetime is why
Formathas no serde impls, whileRoundingMode— atype that only ever appears inside a
Format— has them. A caller can save therounding mode from their formatting options but not the options themselves.
Store the pattern inline so
Formatowns everything it holds, then give itSerializeandDeserializeunder the optionalserdefeature.Two shapes to choose between before building. A fixed-size array with a
length keeps the current generality. A pair of numbers — the size nearest the
decimal mark, then the size that repeats — covers every convention the crate
documents, including the Indian grouping, and is simpler to read and to
serialize. Pick one.
This is a breaking change to a public method.
Acceptance criteria
Formatno longer borrows, andFormat::newand the builder methods stayconstwhere they are todayFormatserializes and deserializes under the optionalserdefeaturemise run cipassesBlocked by
None — can start immediately.
Shape chosen: a pair of numbers
Formatnow storesfirstandrepeat— the group size next to the decimalmark, then the size that repeats — instead of
&'static [u8].Format::grouping(&[3, 2])becomesFormat::grouping(3, 2), andFormat::grouping(&[3])becomesFormat::grouping(3, 3).Why the pair over a fixed-size array with a length:
(3, 3)and Indian is
(3, 2). An array would carry a capacity chosen for casesnobody has.
leftward, and the last entry repeats. The pair states the repetition in
the parameter's name instead.
{"first": 3, "repeat": 2}, rather than alist whose length carries meaning. Nothing has to reject a list that is
longer than the capacity, so a whole class of read error stops existing.
FormatstaysCopyand every builder method staysconst.The zero cases carry over unchanged: a
firstof zero leaves every digit inone run (that is what
no_groupingsets), and arepeatof zero leaves thedigits past the first group in one run.
Also in this change
FormatgetsSerializeandDeserializeunder theserdefeature. Onefield per option; a field the document leaves out keeps the value
Format::newstarts with, so a configuration file need only state whatdiffers.
position,spaced, andprecisionare left out when unset ratherthan written as null, so TOML can hold the result.