Skip to content

Add ExchangeRate (finance) #28

@vhrcgcom

Description

@vhrcgcom

Description

Implement ExchangeRate as a ValueObject in the finance module.

Spec: positive Decimal, from/to currency pair

Implementation checklist

  • Create src/finance/exchangerate.rs
  • Implement ValueObject trait
  • Add #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
  • Export from src/finance/mod.rs and prelude
  • Unit tests: valid input · empty input · invalid format · normalisation
  • Doc comment with # Example block
  • Update status in ROADMAP.md from ⬜ to ✅

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions