A currency pair cannot be named in a const #26

Closed
opened 2026-08-15 04:17:22 +00:00 by rosa · 0 comments
Owner

Every currency is an associated constant — Currency::USD and the rest are
generated as pub const by build.rs — so a caller can name one wherever a
constant is allowed. A pair of them cannot follow:

const USD_EUR: Pair = Pair::new(Currency::USD, Currency::EUR); // rejected

Pair::new (src/exchange/rate.rs:392), base, and quote are plain
functions, though nothing in any of them needs to run at runtime: the struct is
two Copy fields, the constructor moves them into place, and the accessors read
them back. Marking all three const fn lets a caller keep a static table of the
pairs their system quotes, which is what anyone assembling a rate feed writes
first.

ExchangeRate cannot join them — its constructor compares a Decimal against
zero, and that comparison is not a const operation — so this stops at Pair.

Additive; nothing breaks.

Every currency is an associated constant — `Currency::USD` and the rest are generated as `pub const` by `build.rs` — so a caller can name one wherever a constant is allowed. A pair of them cannot follow: ```rust const USD_EUR: Pair = Pair::new(Currency::USD, Currency::EUR); // rejected ``` `Pair::new` (`src/exchange/rate.rs:392`), `base`, and `quote` are plain functions, though nothing in any of them needs to run at runtime: the struct is two `Copy` fields, the constructor moves them into place, and the accessors read them back. Marking all three `const fn` lets a caller keep a static table of the pairs their system quotes, which is what anyone assembling a rate feed writes first. `ExchangeRate` cannot join them — its constructor compares a `Decimal` against zero, and that comparison is not a const operation — so this stops at `Pair`. Additive; nothing breaks.
rosa closed this issue 2026-08-15 05:03:31 +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#26
No description provided.