exchange.rs passes Currency by value and by reference #10

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

Two functions in the same file take the same Copy type two different ways:

  • ExchangeRate::new(from: Currency, to: Currency, ...) — by value.
  • Exchange::rate(&self, from: &Currency, to: &Currency) — by reference.

Doc examples on adjacent lines show both spellings, so a reader has no rule to
carry from one call to the next.

The crate-wide convention is &Currency (Money::from_major,
MoneyBag::balance), which makes new the outlier — though taking references to
a Copy type is itself something the guidelines discourage, so the crate-wide
choice is worth revisiting rather than propagating.

The same question applies to set_rate(&mut self, rate: &ExchangeRate) and
cross_with(&self, other: &Self). ExchangeRate is Copy, and the reference
forces every call site into
desk.set_rate(&ExchangeRate::new(...)?).

Guideline: C-CALLER-CONTROL.

Two functions in the same file take the same `Copy` type two different ways: - `ExchangeRate::new(from: Currency, to: Currency, ...)` — by value. - `Exchange::rate(&self, from: &Currency, to: &Currency)` — by reference. Doc examples on adjacent lines show both spellings, so a reader has no rule to carry from one call to the next. The crate-wide convention is `&Currency` (`Money::from_major`, `MoneyBag::balance`), which makes `new` the outlier — though taking references to a `Copy` type is itself something the guidelines discourage, so the crate-wide choice is worth revisiting rather than propagating. The same question applies to `set_rate(&mut self, rate: &ExchangeRate)` and `cross_with(&self, other: &Self)`. `ExchangeRate` is `Copy`, and the reference forces every call site into `desk.set_rate(&ExchangeRate::new(...)?)`. Guideline: C-CALLER-CONTROL.
rosa closed this issue 2026-08-14 22:26:41 +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#10
No description provided.