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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.