pub struct FxRate {
pub base: Currency,
pub quote: Currency,
pub rate: f64,
pub timestamp: i64,
}Expand description
An FX quote between two currencies: base_currency / quote_currency = rate.
Example: EUR / USD = 1.08 means 1 EUR = 1.08 USD.
Fields§
§base: Currency§quote: Currency§rate: f64§timestamp: i64Epoch timestamp of the quote in seconds or milliseconds (caller-defined convention).
Implementations§
Source§impl FxRate
impl FxRate
pub fn new( base: impl Into<Currency>, quote: impl Into<Currency>, rate: f64, ) -> Self
Sourcepub fn convert(
&self,
amount: f64,
from: &Currency,
to: &Currency,
) -> Result<f64, FxConversionError>
pub fn convert( &self, amount: f64, from: &Currency, to: &Currency, ) -> Result<f64, FxConversionError>
Converts an amount from from currency to to currency using this FX rate.
If from == to, returns Ok(amount) without needing a valid FX quote.
If missing or inverted, computes the direct or reciprocal rate.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for FxRate
impl<'de> Deserialize<'de> for FxRate
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for FxRate
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