set_rate discards the quote it displaces #8

Closed
opened 2026-08-14 21:13:03 +00:00 by rosa · 0 comments
Owner

Exchange::set_rate (src/exchange.rs:362) overwrites whatever the pair held
and returns (), throwing away the Option<Decimal> that BTreeMap::insert
hands back. A caller who wants the quote that was displaced — reasonable when
quotes arrive from a live feed and the movement is worth logging or acting on —
has to perform a separate rate() lookup beforehand, repeating the work the
insert already did.

Return Option<ExchangeRate>.

While here: rate / set_rate diverges both from the standard map vocabulary
the type otherwise mirrors and from MoneyBag's shape. Worth deciding whether
get / insert reads better, though the current names are defensible.

Guideline: C-INTERMEDIATE.

`Exchange::set_rate` (`src/exchange.rs:362`) overwrites whatever the pair held and returns `()`, throwing away the `Option<Decimal>` that `BTreeMap::insert` hands back. A caller who wants the quote that was displaced — reasonable when quotes arrive from a live feed and the movement is worth logging or acting on — has to perform a separate `rate()` lookup beforehand, repeating the work the insert already did. Return `Option<ExchangeRate>`. While here: `rate` / `set_rate` diverges both from the standard map vocabulary the type otherwise mirrors and from `MoneyBag`'s shape. Worth deciding whether `get` / `insert` reads better, though the current names are defensible. Guideline: C-INTERMEDIATE.
rosa closed this issue 2026-08-14 21:54:16 +00:00
Sign in to join this conversation.
No labels
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#8
No description provided.