pub struct FxRate {
pub pair: CurrencyPair,
pub rate_type: RateType,
pub effective_date: NaiveDate,
pub rate: Decimal,
pub inverse_rate: Decimal,
pub source: String,
pub valid_until: Option<NaiveDate>,
}Expand description
An exchange rate for a currency pair on a specific date.
Fields§
§pair: CurrencyPairCurrency pair.
rate_type: RateTypeRate type.
effective_date: NaiveDateEffective date.
rate: DecimalExchange rate (units of to_currency per 1 unit of from_currency).
inverse_rate: DecimalInverse rate (for convenience).
source: StringRate source (e.g., “ECB”, “FED”, “INTERNAL”).
valid_until: Option<NaiveDate>Validity end date (if rate has limited validity).
Implementations§
Source§impl FxRate
impl FxRate
Sourcepub fn new(
from_currency: &str,
to_currency: &str,
rate_type: RateType,
effective_date: NaiveDate,
rate: Decimal,
source: &str,
) -> Self
pub fn new( from_currency: &str, to_currency: &str, rate_type: RateType, effective_date: NaiveDate, rate: Decimal, source: &str, ) -> Self
Creates a new FX rate.
Sourcepub fn with_validity(self, valid_until: NaiveDate) -> Self
pub fn with_validity(self, valid_until: NaiveDate) -> Self
Creates a rate with validity period.
Sourcepub fn convert(&self, amount: Decimal) -> Decimal
pub fn convert(&self, amount: Decimal) -> Decimal
Converts an amount from source to target currency.
Sourcepub fn convert_inverse(&self, amount: Decimal) -> Decimal
pub fn convert_inverse(&self, amount: Decimal) -> Decimal
Converts an amount from target to source currency (inverse).
Sourcepub fn is_valid_on(&self, date: NaiveDate) -> bool
pub fn is_valid_on(&self, date: NaiveDate) -> bool
Returns true if the rate is valid on the given date.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FxRate
impl RefUnwindSafe for FxRate
impl Send for FxRate
impl Sync for FxRate
impl Unpin for FxRate
impl UnwindSafe for FxRate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more