feat: output overhaul stdlib primitives (chrono format_duration + format left-align)#328
Merged
Conversation
renders a Duration to a compact ASCII string into a caller buffer with a unit chosen by magnitude (<1ms / Nus / Nms / N.Ns / NmNs). no allocation, no platform branches. covers ns/us/ms/s/m ranges, unit-tested.
extends the hole grammar to '{' [':' ['<'] ['0'] [width] [x|X|c] '}'. a '<'
after ':' (before the optional 0/width) left-aligns: the value is written
first and space-padded on the right. the zero flag is ignored for left-align.
right-align specs ({:N}/{:0N}/{:08x}) stay byte-identical. unit-tested.
This was referenced Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the output-overhaul epic (briar-systems/mach#1773), implementing briar-systems/mach#1774.
Two shared multiplatform stdlib primitives the terminal-output overhaul needs. ASCII-only, no platform branches, no allocation.
1. chrono
format_durationchrono.Durationhad component accessors but no human string. Addsformat_duration(d: Duration, buf: *u8, cap: usize) str— renders a Duration into a caller-provided buffer, returning the null-terminated string (aliasingbuf), ornilifcapis insufficient. A 24-byte buffer holds every i64 duration. Unit chosen by magnitude:0ms<1msNusNmsN.Ns(tenths truncate)NmNsNegative durations carry a leading
-. Minutes is the top band (no hours).2. format
{:<N}left-alignExtends the hole-spec grammar from
'{' [':' ['0'] [width] [x|X|c] '}'to'{' [':' ['<'] ['0'] [width] [x|X|c] '}'. A<immediately after:(before the optional0/width) sets a newSpec.leftflag;emit_field/fmt_str_fieldthen write the value first and space-pad on the right. The zero flag is ignored for left-align (trailing zeros would corrupt the value). Right-align specs ({:N},{:0N},{:08x}) are byte-identical.Tests
mach-std suite green (567 passed, 0 failed). New unit tests:
format_durationacross ns/us/ms/s/m ranges + sign, band boundaries (1s, 1m, >1h), and insufficient-capacity cases.{:<N}left-align for str + int (and hex, negative, zero-flag-ignored, value-over-width), asserting exact padded bytes, with{:N}/{:0N}right-align re-asserted unchanged.Note: the consuming mach repo's
mach.lockbump is coordinated centrally by the epic lead, not in this PR.🤖 Generated with Claude Code