793. One crate for the right-aligned number writer three programs each copy
Found while triaging mutation survivors (at 269c1d48c). Title and slug are provisional. The
crate's name, number_writer, is provisional (this lane, 2026-10-15 UTC). padnum, floated here,
was set aside: it abbreviates num and reads as a verb phrase. Also set aside: decimal_writer
(suggests a fixed-point type), padded_number (names the output, not the crate), number_column
(reads as a column's ordinal).
What is duplicated
write_right(v: u64, width: usize, out: &mut dyn FnMut(&[u8])) appears, byte for byte apart from a
doc comment, in crates/free/src/lib.rs, crates/vmstat/src/lib.rs and crates/slabtop/src/lib.rs.
It prints a decimal u64 padded on the left to width, never cutting a number wider than its
column. crates/free also carries a signed sibling, write_signed.
The cost showed up as mutation survivors: the same mutant (buf.len() - i to buf.len() / i) lived
in all three because none had a test of a number wider than its column. The lane added the same
test three times (a_number_wider_than_its_column_is_printed_whole). A fourth program that prints a
table will copy it again.
What is proposed
One crate holds the writer and its tests, and the three programs depend on it. This is the shape
CLAUDE.md rule 7 already asks for ("anything two binaries must agree on is a crate"), though here
the agreement is behavior rather than a wire format, so it is the weaker case for the rule.
The name of the crate is calef's call (an architect names crates), so this proposal does not choose one. The work is small: move the function, add the dependency to three manifests, delete three copies and two of the three tests.
Questions for an architect
- Whether a crate this small is wanted, or whether three copies and three tests are the cheaper shape. Would we still choose the crate if both cost the same? The lane thinks yes, since the bug surface is one function; the recommendation is not about effort.
- The crate's name, and whether
write_signedand theu64writer share it.
Reuse: write. No crate in the tree or on crates.io is adopted here; the function is twelve lines and a dependency for it would be a decision under ยง46 (thin primitives or whole subsystems) that this does not justify. The existing copies are the prior art.
Follow-on
- Recorded. The unpadded decimal writers older than this crate are the same digit loop without
the column, and this crate does not yet serve them; the finding lives beside
write_right's width-0case incrates/number_writer/src/lib.rs.
Index row
write_right is copied byte for byte into free, vmstat and slabtop, and the same mutation survivor lived in all three. One shared crate removes the copies, and the next table-printing program stops adding a fourth.