pub struct Rate { /* private fields */ }Expand description
A resolved HMRC rate: currency units per £1, with exact Decimal arithmetic.
The crate never rounds. Callers apply whatever rounding their tax context requires.
Implementations§
Source§impl Rate
impl Rate
Sourcepub fn units_per_gbp(&self) -> Decimal
pub fn units_per_gbp(&self) -> Decimal
The canonical HMRC figure: how many currency units £1 buys.
Sourcepub fn to_gbp(&self, amount: Decimal) -> Decimal
pub fn to_gbp(&self, amount: Decimal) -> Decimal
Converts an amount in this rate’s currency to GBP (amount / units_per_gbp).
Exact division, round the result yourself.
§Examples
use hmrc_rates::{YearMonth, Rates};
use rust_decimal::Decimal;
let rates = Rates::new();
let usd = rates.monthly_rate("USD", YearMonth::new(2025, 8).unwrap())?;
let gbp = usd.to_gbp(Decimal::from(2500));
println!("£{}", gbp.round_dp(2));Sourcepub fn from_gbp(&self, gbp: Decimal) -> Decimal
pub fn from_gbp(&self, gbp: Decimal) -> Decimal
Converts a GBP amount to this rate’s currency (gbp * units_per_gbp).
Sourcepub fn period(&self) -> Period
pub fn period(&self) -> Period
The period the rate was published for.
Reveals the substituted month after
Rates::monthly_rate_or_earlier.
Trait Implementations§
impl Copy for Rate
impl Eq for Rate
impl StructuralPartialEq for Rate
Auto Trait Implementations§
impl Freeze for Rate
impl RefUnwindSafe for Rate
impl Send for Rate
impl Sync for Rate
impl Unpin for Rate
impl UnsafeUnpin for Rate
impl UnwindSafe for Rate
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