pub struct Table<'a> { /* private fields */ }Expand description
A borrowed view of one period’s table — resolve once, convert many times.
Implementations§
Source§impl<'a> Table<'a>
impl<'a> Table<'a>
Sourcepub fn rate(&self, code: &str) -> Result<Rate, LookupError>
pub fn rate(&self, code: &str) -> Result<Rate, LookupError>
The rate for code in this period. "GBP" always resolves to the identity rate.
Errors distinguish a code the series has never published
(LookupError::UnknownCurrency) from one merely absent this period
(LookupError::NotInPeriod).
§Examples
use hmrc_rates::{YearMonth, Rates};
use rust_decimal::Decimal;
let rates = Rates::new();
let table = rates.monthly(YearMonth::new(2025, 8).unwrap())?;
let eur = table.rate("EUR")?;
let total: Decimal = [1200, 450, 80]
.into_iter()
.map(|amount| eur.to_gbp(Decimal::from(amount)))
.sum();Sourcepub fn get(&self, code: &str) -> Option<Rate>
pub fn get(&self, code: &str) -> Option<Rate>
Like Table::rate but None on any miss, for when absence isn’t exceptional.
Sourcepub fn iter(&self) -> impl ExactSizeIterator<Item = (Currency, Rate)> + use<'a>
pub fn iter(&self) -> impl ExactSizeIterator<Item = (Currency, Rate)> + use<'a>
All (currency, rate) pairs in this table, ascending by code.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Table<'a>
impl<'a> RefUnwindSafe for Table<'a>
impl<'a> Send for Table<'a>
impl<'a> Sync for Table<'a>
impl<'a> Unpin for Table<'a>
impl<'a> UnsafeUnpin for Table<'a>
impl<'a> UnwindSafe for Table<'a>
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