Skip to main content

Rate

Struct Rate 

Source
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

Source

pub fn units_per_gbp(&self) -> Decimal

The canonical HMRC figure: how many currency units £1 buys.

Source

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));
Source

pub fn from_gbp(&self, gbp: Decimal) -> Decimal

Converts a GBP amount to this rate’s currency (gbp * units_per_gbp).

Source

pub fn currency(&self) -> Currency

The currency this rate quotes against GBP.

Source

pub fn period(&self) -> Period

The period the rate was published for. Reveals the substituted month after Rates::monthly_rate_or_earlier.

Trait Implementations§

Source§

impl Clone for Rate

Source§

fn clone(&self) -> Rate

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Rate

Source§

impl Debug for Rate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Rate

Source§

impl PartialEq for Rate

Source§

fn eq(&self, other: &Rate) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.