skip to content
[readonly]
==> README.md <==
1# @ajax/rust-fmt
2
3Text exactly as Rust's `format!` writes it, where C's `printf` differs:
4
5- `rf_f32` / `rf_f64`: a float's Display (`{}`): the shortest digits that read back as the same value,
6  never an exponent, no trailing `.0` (`1.0` is `1`, `1e-7` is `0.0000001`, NaN is `NaN`).
7- `rf_debug_str`: a string's Debug (`{:?}`): quoted, with `\n`, `\t`, `\r`, `\\`, `\"`, `\0` and
8  `\u{..}` escapes.
9- `rf_hex_alt`: `{:#x}` (`0x0` for zero, where C's `%#x` prints `0`).
10
11Everything else in Rust's formatting maps onto printf: `{:.2}` is `%.2f` (both round the exact binary
12value to nearest, ties to even), `{:016x}` is `%016llx`, `{:+.2}` is `%+.2f`.
13
14## Ported from
15
16The formatting the [alpha-rust-mesh](https://github.com/rsafier/alpha-rust-mesh) crates rely on
17(`core::fmt`'s float Display and `str::escape_debug`), for the fleet's wire formats and messages
18(`fleet.rs`, `sched.rs`), which must match the Rust byte for byte.
19
20## Tests
21
22`tests/fmt.c`: outputs checked against rustc, and a sweep showing every f32 Display reads back as itself.
23
24## Differences
25
26`rf_debug_str` escapes control bytes only; Rust also escapes some non-printable Unicode (e.g. lone
27combining marks at the start). Nothing in the fleet's messages contains them.
28
29## Licence
30
31MIT. See the repository's LICENSE.