ExchangeRate::from reads as a From conversion #14

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

ExchangeRate::from (src/exchange.rs:126) is a getter for the field named
from, which is what C-GETTER asks for, and clippy's should_implement_trait
does not fire because the signature takes &self and so cannot match
From::from.

The problem is at the call site rather than the definition. ExchangeRate::from(&rate)
is legal path syntax and reads as a conversion, and the collision stops being
cosmetic the moment anyone writes impl From<Currency> for ExchangeRate — which
is a natural thing to want given that identity already does exactly that job.

The FX-standard base() / quote() pair would sidestep it and is more precise
about which side of the pair is which. Keeping from / to is defensible on the
condition that this type never implements From; worth deciding deliberately
rather than by default.

`ExchangeRate::from` (`src/exchange.rs:126`) is a getter for the field named `from`, which is what C-GETTER asks for, and clippy's `should_implement_trait` does not fire because the signature takes `&self` and so cannot match `From::from`. The problem is at the call site rather than the definition. `ExchangeRate::from(&rate)` is legal path syntax and reads as a conversion, and the collision stops being cosmetic the moment anyone writes `impl From<Currency> for ExchangeRate` — which is a natural thing to want given that `identity` already does exactly that job. The FX-standard `base()` / `quote()` pair would sidestep it and is more precise about which side of the pair is which. Keeping `from` / `to` is defensible on the condition that this type never implements `From`; worth deciding deliberately rather than by default.
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#14
No description provided.