Summary
The plain and summary audit renderers in crates/host-identity-cli/src/lib.rs currently allocate a helper String on the error path via one_line(err) so embedded newlines don't break the one-line-per-outcome contract. fmt::from_fn (stable since Rust 1.93) would let us stream the sanitised characters directly through the formatter without the intermediate String, eliminating one allocation per errored outcome.
Current state
// crates/host-identity-cli/src/lib.rs
fn one_line(err: &impl fmt::Display) -> String {
err.to_string().replace(['\n', '\r'], " ")
}
render_audit_plain and render_audit_summary call one_line(err) on the Errored arm. The allocation is small and only happens on the error path, so this isn't hot — but it's removable without behavior change once MSRV allows.
Blocked by
- Workspace MSRV is 1.85 (see
Cargo.toml rust-version).
fmt::from_fn stabilised in Rust 1.93.
Proposed refactor (when MSRV bumps)
fn one_line<'a>(err: &'a impl fmt::Display) -> impl fmt::Display + 'a {
fmt::from_fn(move |f| {
for ch in err.to_string().chars() {
let ch = if ch == '\n' || ch == '\r' { ' ' } else { ch };
f.write_char(ch)?;
}
Ok(())
})
}
Callers use it the same way; only the intermediate String disappears.
Tracking
Re-visit next time the workspace rust-version is bumped to 1.93+ (Cargo.toml).
Summary
The plain and summary audit renderers in
crates/host-identity-cli/src/lib.rscurrently allocate a helperStringon the error path viaone_line(err)so embedded newlines don't break the one-line-per-outcome contract.fmt::from_fn(stable since Rust 1.93) would let us stream the sanitised characters directly through the formatter without the intermediateString, eliminating one allocation per errored outcome.Current state
render_audit_plainandrender_audit_summarycallone_line(err)on theErroredarm. The allocation is small and only happens on the error path, so this isn't hot — but it's removable without behavior change once MSRV allows.Blocked by
Cargo.tomlrust-version).fmt::from_fnstabilised in Rust 1.93.Proposed refactor (when MSRV bumps)
Callers use it the same way; only the intermediate
Stringdisappears.Tracking
Re-visit next time the workspace
rust-versionis bumped to 1.93+ (Cargo.toml).