A pair's Debug prints 278 characters and never spells the pair #27

Closed
opened 2026-08-15 04:17:22 +00:00 by rosa · 0 comments
Owner

Pair derives Debug over two Currency values, and Currency derives it over
four fields (src/lib.rs:996), so a pair prints 278 characters that never once
spell the pair:

Pair { base: Currency { alphabetic_code: IsoAlphabeticCode([85, 83, 68]), numeric_code: IsoNumericCode(840), minor_digits: 2, symbol: "$" }, quote: Currency { alphabetic_code: IsoAlphabeticCode([69, 85, 82]), numeric_code: IsoNumericCode(978), minor_digits: 2, symbol: "€" } }

The alphabetic code — the one thing a reader is looking for — arrives as
[85, 83, 68], three decimal bytes to be decoded by hand. This is what a failing
assert_eq! over two pairs prints, and what any dbg! or log line carrying a
pair, a rate, or an amount prints along with it.

Two scopes:

  • A manual Debug on Currency writing Currency(USD). Every type holding a
    currency — Money, ExchangeRate, Pair, Exchange — is legible at once,
    and the catalog data stays reachable through the accessors that already expose
    it.
  • A manual Debug on Pair alone, writing Pair("USD/EUR"). Fixes the pair and
    leaves Money and the rest as they are.

The first is the one worth making; the value in a currency is its code, and the
rest is a lookup table the debugger does not need reprinted. IsoAlphabeticCode
wants the same treatment for the same reason.

Debug output is not a stability guarantee, but it changes for anyone asserting
on it. Choosing the scope is what this needs before it can be picked up.

`Pair` derives `Debug` over two `Currency` values, and `Currency` derives it over four fields (`src/lib.rs:996`), so a pair prints 278 characters that never once spell the pair: ```text Pair { base: Currency { alphabetic_code: IsoAlphabeticCode([85, 83, 68]), numeric_code: IsoNumericCode(840), minor_digits: 2, symbol: "$" }, quote: Currency { alphabetic_code: IsoAlphabeticCode([69, 85, 82]), numeric_code: IsoNumericCode(978), minor_digits: 2, symbol: "€" } } ``` The alphabetic code — the one thing a reader is looking for — arrives as `[85, 83, 68]`, three decimal bytes to be decoded by hand. This is what a failing `assert_eq!` over two pairs prints, and what any `dbg!` or log line carrying a pair, a rate, or an amount prints along with it. Two scopes: - A manual `Debug` on `Currency` writing `Currency(USD)`. Every type holding a currency — `Money`, `ExchangeRate`, `Pair`, `Exchange` — is legible at once, and the catalog data stays reachable through the accessors that already expose it. - A manual `Debug` on `Pair` alone, writing `Pair("USD/EUR")`. Fixes the pair and leaves `Money` and the rest as they are. The first is the one worth making; the value in a currency is its code, and the rest is a lookup table the debugger does not need reprinted. `IsoAlphabeticCode` wants the same treatment for the same reason. Debug output is not a stability guarantee, but it changes for anyone asserting on it. Choosing the scope is what this needs before it can be picked up.
rosa closed this issue 2026-08-15 04:41:05 +00:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rosa/lucre#27
No description provided.