UnitExponents

Struct UnitExponents 

Source
#[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: i32

Exponent for the SI base unit of time.

§meter: i32

Exponent for the SI base unit of length.

§kilogram: i32

Exponent for the SI base unit of mass.

§ampere: i32

Exponent for the SI base unit of electrical current.

§kelvin: i32

Exponent for the SI base unit of temperature.

§mol: i32

Exponent for the SI base unit of amount of substance.

§candela: i32

Exponent for the SI base unit of luminous intensity

Implementations§

Source§

impl UnitExponents

Source

pub const fn time() -> Self

Returns the UnitExponents for time.

Source

pub const fn length() -> Self

Returns the UnitExponents for length.

Source

pub const fn mass() -> Self

Returns the UnitExponents for mass.

Source

pub const fn electric_current() -> Self

Returns the UnitExponents for (electric) current.

Source

pub const fn temperature() -> Self

Returns the UnitExponents for temperature.

Source

pub const fn amount_of_substance() -> Self

Returns the UnitExponents for amount of substance.

Source

pub const fn luminous_intensity() -> Self

Returns the UnitExponents for luminous intensity.

Source

pub const fn area() -> Self

Returns the UnitExponents for surface area.

Source

pub const fn volume() -> Self

Returns the UnitExponents for volume.

Source

pub const fn electric_voltage() -> Self

Returns the UnitExponents for (electric) voltage.

Source

pub const fn force() -> Self

Returns the UnitExponents for force.

Source

pub const fn torque() -> Self

Returns the UnitExponents for torque.

Source

pub const fn power() -> Self

Returns the UnitExponents for power.

Source

pub const fn energy() -> Self

Returns the UnitExponents for energy.

Source

pub const fn frequency() -> Self

Returns the UnitExponents for frequency.

Source

pub const fn velocity() -> Self

Returns the UnitExponents for (linear) velocity.

Source

pub const fn angular_velocity() -> Self

Returns the UnitExponents for (angular) velocity.

Source

pub const fn magnetic_flux() -> Self

Returns the UnitExponents for magnetic flux.

Source

pub const fn magnetic_flux_density() -> Self

Returns the UnitExponents for magnetic flux density.

Source

pub const fn magnetic_field_strength() -> Self

Returns the UnitExponents for magnetic field strength.

Source

pub const fn inductance() -> Self

Returns the UnitExponents for inductance.

Source

pub const fn electric_conductance() -> Self

Returns the UnitExponents for (electric) conductance.

Source

pub const fn electric_resistance() -> Self

Returns the UnitExponents for (electric) resistance.

Source

pub const fn electric_conductivity() -> Self

Returns the UnitExponents for (electric) conductivity.

Source

pub const fn electric_resistivity() -> Self

Returns the UnitExponents for (electric) resistivity.

Source§

impl UnitExponents

Source

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

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

Source§

fn clone(&self) -> UnitExponents

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 Debug for UnitExponents

Source§

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

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

impl Default for UnitExponents

Source§

fn default() -> UnitExponents

Returns the “default value” for a type. Read more
Source§

impl Display for UnitExponents

Source§

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

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

impl Div for UnitExponents

Source§

type Output = UnitExponents

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign for UnitExponents

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl From<[i32; 7]> for UnitExponents

Source§

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 second
  • array[1]: Exponent of meter
  • array[2]: Exponent of kilogram
  • array[3]: Exponent of ampere
  • array[4]: Exponent of kelvin
  • array[5]: Exponent of mol
  • array[6]: Exponent of candela
Source§

impl From<UnitExponents> for [i32; 7]

Source§

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 second
  • array[1]: Exponent of meter
  • array[2]: Exponent of kilogram
  • array[3]: Exponent of ampere
  • array[4]: Exponent of kelvin
  • array[5]: Exponent of mol
  • array[6]: Exponent of candela
Source§

impl Mul for UnitExponents

Source§

type Output = UnitExponents

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign for UnitExponents

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl PartialEq for UnitExponents

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for UnitExponents

Source§

impl StructuralPartialEq for UnitExponents

Auto Trait Implementations§

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.