exchange.rs holds two subjects and is past a thousand lines #21
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#21
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?
src/exchange.rswent from 598 lines at v0.10.0 to 1263. The growth is mostlyprose and tests rather than code: 560 doc-comment lines, a 424-line test module,
and roughly 280 lines of everything else. By that measure the file is not dense,
and it is not an outlier —
src/lib.rs(1982),src/serde.rs(1268), andsrc/bag.rs(1086) are all past a thousand lines on the same footing.So this is not a request to split now. It is a note of where the seam is, for
whenever the file does start to hurt.
The module holds two subjects.
ExchangeRateis a value: a pair, a multiplier,and the arithmetic over them (
convert,cross_with,identity,ExchangeRateError,CrossRateError).Exchangeis a collection: a map keyedby pair, its accessors, its two iterator types, and the
Extend/FromIterator/IntoIteratorimpls. They share only the notation for a pair.Three changes would sharpen that seam rather than blur it:
Exchange::rateand into a conversion the tableperforms, which pulls the table further away from being a map of values.
pub(crate)type in this module, which is theone thing both halves would need after a split, and so names the shared piece
before it has to cross a file boundary.
Rates/IntoRates(src/exchange.rs:613) isthe same ~90 lines as
Balances/IntoBalances(src/bag.rs:367): twoopaque newtypes over
btree_mapiterators, four trait impls each, and a pairof entry-conversion functions, differing only in the item they yield. The
newtypes have to stay opaque to keep
BTreeMapout of the public signatures,but the delegating impls do not have to be written twice. Lifting them into a
private module would take a large mechanical block out of both files.
Revisit when any of those lands, or when the next feature pushes the file
further. If a line threshold is worth enforcing here at all, it should count
code and skip doc comments and
#[cfg(test)], or every module in the cratetrips it while reading fine.
The split landed:
exchange/rate.rsfor the value,exchange/table.rsfor the collection,exchange/mod.rsfor the prose and the re-exports. Public paths are unchanged and every test moved intact.The two halves turned out to share one more thing than the pair notation — the table stores multipliers, not rates, so it has to reassemble one on the way out.
ExchangeRate::new_uncheckedispub(super)and does that across the boundary.The iterator scaffolding shared with
bag.rsis not being lifted, and this issue is not staying open for it. #18 covers the pair notation on its own.