Description
Implement ExchangeRate as a ValueObject in the finance module.
Spec: positive Decimal, from/to currency pair
Implementation checklist
Implementation detail
Input / Output
ExchangeRate is a composite value object.
|
Type |
| Input |
ExchangeRateInput { from: CurrencyCode, to: CurrencyCode, rate: rust_decimal::Decimal } |
| Output |
String — e.g. "EUR/USD 1.0850" |
Validation
rate must be strictly positive (> 0).
from and to must differ — an exchange rate from a currency to itself is meaningless.
- Both
from and to are already validated CurrencyCode instances.
Extra methods
from() -> &CurrencyCode
to() -> &CurrencyCode
rate() -> &rust_decimal::Decimal
References
Description
Implement
ExchangeRateas aValueObjectin thefinancemodule.Spec: positive
Decimal, from/to currency pairImplementation checklist
src/finance/exchangerate.rsValueObjecttrait#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]src/finance/mod.rsandprelude# ExampleblockROADMAP.mdfrom ⬜ to ✅Implementation detail
Input / Output
ExchangeRateis a composite value object.ExchangeRateInput { from: CurrencyCode, to: CurrencyCode, rate: rust_decimal::Decimal }String— e.g."EUR/USD 1.0850"Validation
ratemust be strictly positive (> 0).fromandtomust differ — an exchange rate from a currency to itself is meaningless.fromandtoare already validatedCurrencyCodeinstances.Extra methods
from() -> &CurrencyCodeto() -> &CurrencyCoderate() -> &rust_decimal::DecimalReferences