Skip to main content

Rate

Struct Rate 

Source
pub struct Rate<TQ, PQ>
where TQ: Quantity, PQ: Quantity,
{ /* private fields */ }
Expand description

The ratio between two related quantity values.

Implementations§

Source§

impl<TQ, PQ> Rate<TQ, PQ>
where TQ: Quantity, PQ: Quantity,

Source

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.

Source

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.

Source

pub const fn term_amount(&self) -> Decimal

Returns the term amount of self.

Source

pub const fn term_unit(&self) -> <TQ as Quantity>::UnitType

Returns the term unit of self.

Source

pub const fn per_unit_multiple(&self) -> Decimal

Returns the per unit multiple of self.

Source

pub const fn per_unit(&self) -> <PQ as Quantity>::UnitType

Returns the per unit of self.

Source

pub const fn reciprocal(&self) -> Rate<PQ, TQ>

Returns the multiplicative inverse of self

Trait Implementations§

Source§

impl<TQ, PQ> Clone for Rate<TQ, PQ>
where TQ: Clone + Quantity, PQ: Clone + Quantity, <TQ as Quantity>::UnitType: Clone, <PQ as Quantity>::UnitType: Clone,

Source§

fn clone(&self) -> Rate<TQ, PQ>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<TQ, PQ> Debug for Rate<TQ, PQ>
where TQ: Debug + Quantity, PQ: Debug + Quantity, <TQ as Quantity>::UnitType: Debug, <PQ as Quantity>::UnitType: Debug,

Source§

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

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

impl<TQ, PQ> Display for Rate<TQ, PQ>
where TQ: Quantity, PQ: Quantity,

Source§

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

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

impl<PQ: Quantity> Div<Rate<Money, PQ>> for Money

Source§

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 to self.unit()
Source§

type Output = PQ

The resulting type after applying the / operator.
Source§

impl<TQ, PQ> Mul<PQ> for Rate<TQ, PQ>
where TQ: Quantity, PQ: Quantity + Div<Output = Decimal>,

Source§

type Output = TQ

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: PQ) -> <Rate<TQ, PQ> as Mul<PQ>>::Output

Performs the * operation. Read more
Source§

impl<TQ: Quantity> Mul<Rate<TQ, Money>> for Money

Source§

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 to self.unit()
Source§

type Output = TQ

The resulting type after applying the * operator.
Source§

impl<TQ, PQ> Copy for Rate<TQ, PQ>
where TQ: Copy + Quantity, PQ: Copy + Quantity, <TQ as Quantity>::UnitType: Copy, <PQ as Quantity>::UnitType: Copy,

Auto Trait Implementations§

§

impl<TQ, PQ> Freeze for Rate<TQ, PQ>
where <TQ as Quantity>::UnitType: Freeze, <PQ as Quantity>::UnitType: Freeze,

§

impl<TQ, PQ> RefUnwindSafe for Rate<TQ, PQ>

§

impl<TQ, PQ> Send for Rate<TQ, PQ>
where <TQ as Quantity>::UnitType: Send, <PQ as Quantity>::UnitType: Send,

§

impl<TQ, PQ> Sync for Rate<TQ, PQ>
where <TQ as Quantity>::UnitType: Sync, <PQ as Quantity>::UnitType: Sync,

§

impl<TQ, PQ> Unpin for Rate<TQ, PQ>
where <TQ as Quantity>::UnitType: Unpin, <PQ as Quantity>::UnitType: Unpin,

§

impl<TQ, PQ> UnsafeUnpin for Rate<TQ, PQ>

§

impl<TQ, PQ> UnwindSafe for Rate<TQ, PQ>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.