A currency pair's notation is decided in both Display and serde #18
Labels
No labels
kind
bug
kind
enhancement
kind
refactor
workflow
needs-info
workflow
needs-triage
workflow
ready-for-agent
workflow
ready-for-human
workflow
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
rosa/lucre#18
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
How a currency pair is written down — the priced currency, a slash, the currency
it is priced in — is decided twice.
ExchangeRate'sDisplay(src/exchange.rs:307) builds it from a literal:The serde module decides it again (
src/serde.rs:474) with aPairnewtype, aPAIR_SEPARATORconstant, aSerializethat formats"{base}{PAIR_SEPARATOR}{quote}", and aPairVisitorthat reads it back withsplit_once(PAIR_SEPARATOR).Both render the same notation and the serialized table depends on it as a map
key (
src/serde.rs:541), but only one of the two names the separator. Changingit in
serde.rsleavesDisplaywriting the old form with no compilercomplaint, and there is no test that holds the two to the same notation.
Pairis also the wrong side of the boundary. It knows what a rate's twocurrencies are called and how a board writes them —
exchange.rs's subject, notserde's — and it exists in
serde.rsonly because that is where it was firstneeded.
Move
Pairintoexchange.rsaspub(crate), withDisplayandFromStrcarrying the notation.
ExchangeRate'sDisplaythen renders"{pair} {rate}",serde's
Serializebecomescollect_str(&pair), andPairVisitorbecomes aparse, dropping the hand-rolledsplit_onceand the twoCurrency::from_alphabetic_codecalls. The separator is decided once, and thefeature-gated module stops owning a decision the core module makes.
exchange.rsholds two subjects and is past a thousand lines #21exchange.rsholds two subjects and is past a thousand lines #21