#[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§meter: i32§kilogram: i32§ampere: i32§kelvin: i32§mol: i32§candela: i32Implementations§
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
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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
Returns the “default value” for a type. Read more
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)
Performs the
/= 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)
Performs the
*= operation. Read moreSource§impl PartialEq for UnitExponents
impl PartialEq for UnitExponents
impl Eq for UnitExponents
impl StructuralPartialEq for UnitExponents
Auto Trait Implementations§
impl Freeze for UnitExponents
impl RefUnwindSafe for UnitExponents
impl Send for UnitExponents
impl Sync for UnitExponents
impl Unpin for UnitExponents
impl UnwindSafe for UnitExponents
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