pub struct Qty<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8>(/* private fields */);Expand description
A quantity, with the seven SI base dimensions in its type.
The parameters are the exponents of metre, kilogram, second, ampere, kelvin,
mole and candela, in that order, so a velocity (m·s⁻¹) is Qty<1,0,-1,0,0,0,0>
— which is what Velocity names.
Addition, subtraction, negation, comparison and scaling by a plain f64 work
for every dimension. Multiplication and division between two quantities work
for the pairs declared in this module.
Implementations§
Source§impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Qty<L, M, T, I, K, N, J>
impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Qty<L, M, T, I, K, N, J>
Sourcepub const fn from_si(value: f64) -> Qty<L, M, T, I, K, N, J>
pub const fn from_si(value: f64) -> Qty<L, M, T, I, K, N, J>
Wrap a number already in SI base units. The escape hatch: use it when a dimension has no name here, and name it if you use it twice.
const, so a dimensioned constant can be written without a lazy static.
Sourcepub const fn dimension() -> [i8; 7]
pub const fn dimension() -> [i8; 7]
The seven exponents, for diagnostics and for a runtime dimension check at a boundary the type system does not cross (deserialisation, FFI).
Sourcepub fn abs(self) -> Qty<L, M, T, I, K, N, J>
pub fn abs(self) -> Qty<L, M, T, I, K, N, J>
Magnitude without its sign, in the same dimension.
Sourcepub fn min(self, other: Qty<L, M, T, I, K, N, J>) -> Qty<L, M, T, I, K, N, J>
pub fn min(self, other: Qty<L, M, T, I, K, N, J>) -> Qty<L, M, T, I, K, N, J>
The smaller of two quantities of the same dimension.
Sourcepub fn max(self, other: Qty<L, M, T, I, K, N, J>) -> Qty<L, M, T, I, K, N, J>
pub fn max(self, other: Qty<L, M, T, I, K, N, J>) -> Qty<L, M, T, I, K, N, J>
The larger of two quantities of the same dimension.
Source§impl Qty<1, 0, 0, 0, 0, 0, 0>
impl Qty<1, 0, 0, 0, 0, 0, 0>
Source§impl Qty<0, 0, 0, 0, 1, 0, 0>
impl Qty<0, 0, 0, 0, 1, 0, 0>
Sourcepub fn celsius(v: f64) -> Qty<0, 0, 0, 0, 1, 0, 0>
pub fn celsius(v: f64) -> Qty<0, 0, 0, 0, 1, 0, 0>
Celsius is an offset scale, not a scaled one, which is why it gets a named constructor rather than a factor: 20 °C is 293.15 K, and a temperature difference of 20 K is a different thing entirely.
Sourcepub fn in_celsius(self) -> f64
pub fn in_celsius(self) -> f64
As degrees Celsius. Subtracts the offset; see Temperature::celsius.
Source§impl Qty<2, 0, -2, 0, -1, 0, 0>
impl Qty<2, 0, -2, 0, -1, 0, 0>
Sourcepub fn j_per_kg_k(v: f64) -> Qty<2, 0, -2, 0, -1, 0, 0>
pub fn j_per_kg_k(v: f64) -> Qty<2, 0, -2, 0, -1, 0, 0>
J·kg⁻¹·K⁻¹, the unit a materials table uses.
Source§impl Qty<2, 1, -2, 0, -1, 0, 0>
impl Qty<2, 1, -2, 0, -1, 0, 0>
Sourcepub fn j_per_k(v: f64) -> Qty<2, 1, -2, 0, -1, 0, 0>
pub fn j_per_k(v: f64) -> Qty<2, 1, -2, 0, -1, 0, 0>
Joules per kelvin. The companion to Conductance::w_per_k: their ratio is a time
constant, and the type system says so.
Trait Implementations§
Source§impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Add for Qty<L, M, T, I, K, N, J>
impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Add for Qty<L, M, T, I, K, N, J>
Source§impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> AddAssign for Qty<L, M, T, I, K, N, J>
impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> AddAssign for Qty<L, M, T, I, K, N, J>
Source§fn add_assign(&mut self, rhs: Qty<L, M, T, I, K, N, J>)
fn add_assign(&mut self, rhs: Qty<L, M, T, I, K, N, J>)
+= operation. Read moreSource§impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Clone for Qty<L, M, T, I, K, N, J>
impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Clone for Qty<L, M, T, I, K, N, J>
impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Copy for Qty<L, M, T, I, K, N, J>
Source§impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Debug for Qty<L, M, T, I, K, N, J>
impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Debug for Qty<L, M, T, I, K, N, J>
Source§impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Default for Qty<L, M, T, I, K, N, J>
impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Default for Qty<L, M, T, I, K, N, J>
Source§impl<'de, const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Deserialize<'de> for Qty<L, M, T, I, K, N, J>
impl<'de, const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Deserialize<'de> for Qty<L, M, T, I, K, N, J>
Source§fn deserialize<D>(
d: D,
) -> Result<Qty<L, M, T, I, K, N, J>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
d: D,
) -> Result<Qty<L, M, T, I, K, N, J>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Display for Qty<L, M, T, I, K, N, J>
impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Display for Qty<L, M, T, I, K, N, J>
Source§impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Div for Qty<L, M, T, I, K, N, J>
Dividing two quantities of the same dimension gives a plain number — which
is the one product rule that needs no exponent arithmetic, and the one every
tolerance check uses.
impl<const L: i8, const M: i8, const T: i8, const I: i8, const K: i8, const N: i8, const J: i8> Div for Qty<L, M, T, I, K, N, J>
Dividing two quantities of the same dimension gives a plain number — which is the one product rule that needs no exponent arithmetic, and the one every tolerance check uses.