pub struct Rate<TQ, PQ>{ /* private fields */ }Expand description
The ratio between two related quantity values.
Implementations§
Source§impl<TQ, PQ> Rate<TQ, PQ>
impl<TQ, PQ> Rate<TQ, PQ>
Sourcepub const fn new(
term_amount: Decimal,
term_unit: <TQ as Quantity>::UnitType,
per_unit_multiple: Decimal,
per_unit: <PQ as Quantity>::UnitType,
) -> Rate<TQ, PQ>
pub const fn new( term_amount: Decimal, term_unit: <TQ as Quantity>::UnitType, per_unit_multiple: Decimal, per_unit: <PQ as Quantity>::UnitType, ) -> Rate<TQ, PQ>
Returns a new instance of Rate with attributes equal to given params.
Sourcepub fn from_qty_vals(term: TQ, per: PQ) -> Rate<TQ, PQ>
pub fn from_qty_vals(term: TQ, per: PQ) -> Rate<TQ, PQ>
Returns a new instance of Rate with attributes extracted from the
given quantity values.
Sourcepub const fn term_amount(&self) -> Decimal
pub const fn term_amount(&self) -> Decimal
Returns the term amount of self.
Sourcepub const fn per_unit_multiple(&self) -> Decimal
pub const fn per_unit_multiple(&self) -> Decimal
Returns the per unit multiple of self.
Sourcepub const fn reciprocal(&self) -> Rate<PQ, TQ>
pub const fn reciprocal(&self) -> Rate<PQ, TQ>
Returns the multiplicative inverse of self
Trait Implementations§
Source§impl<PQ: Quantity> Div<Rate<Money, PQ>> for Money
impl<PQ: Quantity> Div<Rate<Money, PQ>> for Money
Source§fn div(self, rhs: Rate<Self, PQ>) -> Self::Output
fn div(self, rhs: Rate<Self, PQ>) -> Self::Output
Returns an instance of PQ eqivalent to self according to rhs.
Example:
let d = Dec!(7.5) * USD;
let r = Rate::<Money, Mass>::new(Dec!(3), USD, Dec!(10), KILOGRAM);
let m = d / r;
assert_eq!(m, Dec!(25) * KILOGRAM);§Panics
The function panics in the following cases:
rhs.term_unit()is not identical toself.unit()
Source§impl<TQ: Quantity> Mul<Rate<TQ, Money>> for Money
impl<TQ: Quantity> Mul<Rate<TQ, Money>> for Money
Source§fn mul(self, rhs: Rate<TQ, Self>) -> Self::Output
fn mul(self, rhs: Rate<TQ, Self>) -> Self::Output
Returns an instance of TQ eqivalent to self according to rhs.
Example:
let d = Dec!(7.5) * USD;
let r = Rate::<Mass, Money>::new(Dec!(3.5), KILOGRAM, Dec!(10), USD);
let m = d * r;
assert_eq!(m, Dec!(2.625) * KILOGRAM);§Panics
The function panics in the following cases:
rhs.per_unit()is not identical toself.unit()
impl<TQ, PQ> Copy for Rate<TQ, PQ>
Auto Trait Implementations§
impl<TQ, PQ> Freeze for Rate<TQ, PQ>
impl<TQ, PQ> RefUnwindSafe for Rate<TQ, PQ>
impl<TQ, PQ> Send for Rate<TQ, PQ>
impl<TQ, PQ> Sync for Rate<TQ, PQ>
impl<TQ, PQ> Unpin for Rate<TQ, PQ>
impl<TQ, PQ> UnsafeUnpin for Rate<TQ, PQ>
impl<TQ, PQ> UnwindSafe for Rate<TQ, PQ>
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