exchange.rs holds two subjects and is past a thousand lines #21

Closed
opened 2026-08-14 23:59:01 +00:00 by rosa · 1 comment
Owner

src/exchange.rs went from 598 lines at v0.10.0 to 1263. The growth is mostly
prose 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), and
src/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. ExchangeRate is a value: a pair, a multiplier,
and the arithmetic over them (convert, cross_with, identity,
ExchangeRateError, CrossRateError). Exchange is a collection: a map keyed
by pair, its accessors, its two iterator types, and the Extend /
FromIterator / IntoIterator impls. They share only the notation for a pair.

Three changes would sharpen that seam rather than blur it:

  • #17 moves the par rule out of Exchange::rate and into a conversion the table
    performs, which pulls the table further away from being a map of values.
  • #18 gives the pair notation a pub(crate) type in this module, which is the
    one thing both halves would need after a split, and so names the shared piece
    before it has to cross a file boundary.
  • The iterator scaffolding in Rates / IntoRates (src/exchange.rs:613) is
    the same ~90 lines as Balances / IntoBalances (src/bag.rs:367): two
    opaque newtypes over btree_map iterators, four trait impls each, and a pair
    of entry-conversion functions, differing only in the item they yield. The
    newtypes have to stay opaque to keep BTreeMap out 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 crate
trips it while reading fine.

`src/exchange.rs` went from 598 lines at v0.10.0 to 1263. The growth is mostly prose 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), and `src/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. `ExchangeRate` is a value: a pair, a multiplier, and the arithmetic over them (`convert`, `cross_with`, `identity`, `ExchangeRateError`, `CrossRateError`). `Exchange` is a collection: a map keyed by pair, its accessors, its two iterator types, and the `Extend` / `FromIterator` / `IntoIterator` impls. They share only the notation for a pair. Three changes would sharpen that seam rather than blur it: - #17 moves the par rule out of `Exchange::rate` and into a conversion the table performs, which pulls the table further away from being a map of values. - #18 gives the pair notation a `pub(crate)` type in this module, which is the one thing both halves would need after a split, and so names the shared piece before it has to cross a file boundary. - The iterator scaffolding in `Rates` / `IntoRates` (`src/exchange.rs:613`) is the same ~90 lines as `Balances` / `IntoBalances` (`src/bag.rs:367`): two opaque newtypes over `btree_map` iterators, four trait impls each, and a pair of entry-conversion functions, differing only in the item they yield. The newtypes have to stay opaque to keep `BTreeMap` out 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 crate trips it while reading fine.
Author
Owner

The split landed: exchange/rate.rs for the value, exchange/table.rs for the collection, exchange/mod.rs for 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_unchecked is pub(super) and does that across the boundary.

The iterator scaffolding shared with bag.rs is not being lifted, and this issue is not staying open for it. #18 covers the pair notation on its own.

The split landed: `exchange/rate.rs` for the value, `exchange/table.rs` for the collection, `exchange/mod.rs` for 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_unchecked` is `pub(super)` and does that across the boundary. The iterator scaffolding shared with `bag.rs` is not being lifted, and this issue is not staying open for it. #18 covers the pair notation on its own.
rosa closed this issue 2026-08-15 01:52:27 +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#21
No description provided.