#[repr(C)]pub struct UnitExponents {
pub second: i32,
pub meter: i32,
pub kilogram: i32,
pub ampere: i32,
pub kelvin: i32,
pub mol: i32,
pub candela: i32,
}Expand description
Struct representing a unit of measurement in the SI system via the exponents of the base units.
Fields§
§second: i32Exponent for the SI base unit of time.
meter: i32Exponent for the SI base unit of length.
kilogram: i32Exponent for the SI base unit of mass.
ampere: i32Exponent for the SI base unit of electrical current.
kelvin: i32Exponent for the SI base unit of temperature.
mol: i32Exponent for the SI base unit of amount of substance.
candela: i32Exponent for the SI base unit of luminous intensity
Implementations§
Source§impl UnitExponents
impl UnitExponents
Sourcepub const fn time() -> Self
pub const fn time() -> Self
Returns the UnitExponents for time.
Sourcepub const fn length() -> Self
pub const fn length() -> Self
Returns the UnitExponents for length.
Sourcepub const fn mass() -> Self
pub const fn mass() -> Self
Returns the UnitExponents for mass.
Sourcepub const fn electric_current() -> Self
pub const fn electric_current() -> Self
Returns the UnitExponents for (electric) current.
Sourcepub const fn temperature() -> Self
pub const fn temperature() -> Self
Returns the UnitExponents for temperature.
Sourcepub const fn amount_of_substance() -> Self
pub const fn amount_of_substance() -> Self
Returns the UnitExponents for amount of substance.
Sourcepub const fn luminous_intensity() -> Self
pub const fn luminous_intensity() -> Self
Returns the UnitExponents for luminous intensity.
Sourcepub const fn area() -> Self
pub const fn area() -> Self
Returns the UnitExponents for surface area.
Sourcepub const fn volume() -> Self
pub const fn volume() -> Self
Returns the UnitExponents for volume.
Sourcepub const fn electric_voltage() -> Self
pub const fn electric_voltage() -> Self
Returns the UnitExponents for (electric) voltage.
Sourcepub const fn force() -> Self
pub const fn force() -> Self
Returns the UnitExponents for force.
Sourcepub const fn torque() -> Self
pub const fn torque() -> Self
Returns the UnitExponents for torque.
Sourcepub const fn power() -> Self
pub const fn power() -> Self
Returns the UnitExponents for power.
Sourcepub const fn energy() -> Self
pub const fn energy() -> Self
Returns the UnitExponents for energy.
Sourcepub const fn frequency() -> Self
pub const fn frequency() -> Self
Returns the UnitExponents for frequency.
Sourcepub const fn velocity() -> Self
pub const fn velocity() -> Self
Returns the UnitExponents for (linear) velocity.
Sourcepub const fn angular_velocity() -> Self
pub const fn angular_velocity() -> Self
Returns the UnitExponents for (angular) velocity.
Sourcepub const fn magnetic_flux() -> Self
pub const fn magnetic_flux() -> Self
Returns the UnitExponents for magnetic flux.
Sourcepub const fn magnetic_flux_density() -> Self
pub const fn magnetic_flux_density() -> Self
Returns the UnitExponents for magnetic flux density.
Sourcepub const fn magnetic_field_strength() -> Self
pub const fn magnetic_field_strength() -> Self
Returns the UnitExponents for magnetic field strength.
Sourcepub const fn inductance() -> Self
pub const fn inductance() -> Self
Returns the UnitExponents for inductance.
Sourcepub const fn electric_conductance() -> Self
pub const fn electric_conductance() -> Self
Returns the UnitExponents for (electric) conductance.
Sourcepub const fn electric_resistance() -> Self
pub const fn electric_resistance() -> Self
Returns the UnitExponents for (electric) resistance.
Sourcepub const fn electric_conductivity() -> Self
pub const fn electric_conductivity() -> Self
Returns the UnitExponents for (electric) conductivity.
Sourcepub const fn electric_resistivity() -> Self
pub const fn electric_resistivity() -> Self
Returns the UnitExponents for (electric) resistivity.
Source§impl UnitExponents
impl UnitExponents
Sourcepub fn powi(self, n: i32) -> Self
pub fn powi(self, n: i32) -> Self
Raises self to an integer power.
§Examples
use dyn_quantity::UnitExponents;
let exponents = UnitExponents::from([0, 1, 0, 2, 0, -2, 0]);
let array: [i32; 7] = exponents.powi(2).into();
assert_eq!(array, [0, 2, 0, 4, 0, -4, 0]);Sourcepub fn try_nthroot(self, n: i32) -> Result<Self, RootError>
pub fn try_nthroot(self, n: i32) -> Result<Self, RootError>
Tries to calculate the nth root of self. This operation fails if any
of the exponents is not divisible by n.
§Examples
use dyn_quantity::UnitExponents;
let exponents = UnitExponents::from([0, 2, 0, 2, 0, -4, 0]);
// It is possible to calculate the square root:
let array: [i32; 7] = exponents.clone().try_nthroot(2).unwrap().into();
assert_eq!(array, [0, 1, 0, 1, 0, -2, 0]);
// But not the cubic root (not all exponents are divisible by 3):
assert!(exponents.try_nthroot(3).is_err());Trait Implementations§
Source§impl Clone for UnitExponents
impl Clone for UnitExponents
Source§fn clone(&self) -> UnitExponents
fn clone(&self) -> UnitExponents
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UnitExponents
impl Debug for UnitExponents
Source§impl Default for UnitExponents
impl Default for UnitExponents
Source§fn default() -> UnitExponents
fn default() -> UnitExponents
Source§impl Display for UnitExponents
impl Display for UnitExponents
Source§impl Div for UnitExponents
impl Div for UnitExponents
Source§impl DivAssign for UnitExponents
impl DivAssign for UnitExponents
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl From<[i32; 7]> for UnitExponents
impl From<[i32; 7]> for UnitExponents
Source§fn from(array: [i32; 7]) -> Self
fn from(array: [i32; 7]) -> Self
Converts an array of seven i32 values into UnitExponents.
The individual array elements are interpreted as follows:
array[0]: Exponent of secondarray[1]: Exponent of meterarray[2]: Exponent of kilogramarray[3]: Exponent of amperearray[4]: Exponent of kelvinarray[5]: Exponent of molarray[6]: Exponent of candela
Source§impl From<UnitExponents> for [i32; 7]
impl From<UnitExponents> for [i32; 7]
Source§fn from(value: UnitExponents) -> Self
fn from(value: UnitExponents) -> Self
Converts an UnitExponents into an array of seven i32.
The exponents are put into the array in the following order:
array[0]: Exponent of secondarray[1]: Exponent of meterarray[2]: Exponent of kilogramarray[3]: Exponent of amperearray[4]: Exponent of kelvinarray[5]: Exponent of molarray[6]: Exponent of candela
Source§impl Mul for UnitExponents
impl Mul for UnitExponents
Source§impl MulAssign for UnitExponents
impl MulAssign for UnitExponents
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read more