pub struct ConstDim {
pub l: i8,
pub m: i8,
pub t: i8,
pub i: i8,
pub th: i8,
pub n: i8,
pub j: i8,
}Expand description
A const-evaluable dimension vector for compile-time formula verification.
Unlike Dim, which uses type-level integers, ConstDim stores exponents
as plain i8 values so that dimension arithmetic can be performed in
const fn contexts (e.g. inside const_assert_dim!).
Fields§
§l: i8Length exponent (m).
m: i8Mass exponent (kg).
t: i8Time exponent (s).
i: i8Electric current exponent (A).
th: i8Thermodynamic temperature exponent (K).
n: i8Amount of substance exponent (mol).
j: i8Luminous intensity exponent (cd).
Implementations§
Source§impl ConstDim
impl ConstDim
Sourcepub const fn new(l: i8, m: i8, t: i8, i: i8, th: i8, n: i8, j: i8) -> Self
pub const fn new(l: i8, m: i8, t: i8, i: i8, th: i8, n: i8, j: i8) -> Self
Create a new ConstDim with the given exponents.
Sourcepub const fn mul(self, rhs: Self) -> Self
pub const fn mul(self, rhs: Self) -> Self
Multiply two dimension vectors (add exponents).
An exponent beyond the i8 range saturates at ±127/−128 (no
physical formula comes near it); use checked_mul
to refuse instead. Up to 0.45 it overflowed: a panic in debug
builds, a wrapped (wrong) dimension in release builds.
Sourcepub const fn div(self, rhs: Self) -> Self
pub const fn div(self, rhs: Self) -> Self
Divide two dimension vectors (subtract exponents), saturating like
mul; see checked_div.
Sourcepub const fn checked_mul(self, rhs: Self) -> Option<Self>
pub const fn checked_mul(self, rhs: Self) -> Option<Self>
mul, or None when an exponent leaves the i8 range.
use symplex::units::ConstDim;
assert_eq!(ConstDim::MASS.checked_mul(ConstDim::ACCELERATION), Some(ConstDim::FORCE));
let big = ConstDim::LENGTH.pow(100);
assert_eq!(big.checked_mul(big), None);
assert_eq!(big.mul(big).l, 127); // saturates, never wrapsSourcepub const fn checked_div(self, rhs: Self) -> Option<Self>
pub const fn checked_div(self, rhs: Self) -> Option<Self>
div, or None when an exponent leaves the i8 range.
Sourcepub const fn checked_pow(self, n: i8) -> Option<Self>
pub const fn checked_pow(self, n: i8) -> Option<Self>
pow, or None when an exponent leaves the i8 range.
use symplex::units::ConstDim;
assert_eq!(ConstDim::LENGTH.checked_pow(3), Some(ConstDim::VOLUME));
assert_eq!(ConstDim::LENGTH.pow(100).checked_pow(2), None);Sourcepub const fn eq(self, rhs: Self) -> bool
pub const fn eq(self, rhs: Self) -> bool
Check equality of two dimension vectors (const-compatible).
Sourcepub const fn pow(self, n: i8) -> Self
pub const fn pow(self, n: i8) -> Self
Raise dimension to an integer power (multiply all exponents by n),
saturating like mul; see checked_pow.
Source§impl ConstDim
impl ConstDim
Sourcepub const DIMENSIONLESS: Self
pub const DIMENSIONLESS: Self
Dimensionless dimension: all exponents zero.
Sourcepub const TEMPERATURE: Self
pub const TEMPERATURE: Self
Temperature dimension: Θ¹.
Sourcepub const ACCELERATION: Self
pub const ACCELERATION: Self
Acceleration dimension: L¹·T⁻².
Sourcepub const ANGULAR_VELOCITY: Self
pub const ANGULAR_VELOCITY: Self
Angular velocity dimension: T⁻¹.
Sourcepub const ANGULAR_ACCELERATION: Self
pub const ANGULAR_ACCELERATION: Self
Angular acceleration dimension: T⁻².
Sourcepub const ANGULAR_MOMENTUM: Self
pub const ANGULAR_MOMENTUM: Self
Angular momentum dimension: L²·M¹·T⁻¹.
Sourcepub const MOMENT_OF_INERTIA: Self
pub const MOMENT_OF_INERTIA: Self
Moment of inertia dimension: L²·M¹.
Sourcepub const RESISTANCE: Self
pub const RESISTANCE: Self
Resistance dimension: L²·M¹·T⁻³·I⁻².
Sourcepub const INDUCTANCE: Self
pub const INDUCTANCE: Self
Inductance dimension: L²·M¹·T⁻²·I⁻².
Sourcepub const CAPACITANCE: Self
pub const CAPACITANCE: Self
Capacitance dimension: L⁻²·M⁻¹·T⁴·I².
Sourcepub const MAGNETIC_FLUX: Self
pub const MAGNETIC_FLUX: Self
Magnetic flux dimension: L²·M¹·T⁻²·I⁻¹.
Trait Implementations§
impl Copy for ConstDim
impl Eq for ConstDim
impl StructuralPartialEq for ConstDim
Auto Trait Implementations§
impl Freeze for ConstDim
impl RefUnwindSafe for ConstDim
impl Send for ConstDim
impl Sync for ConstDim
impl Unpin for ConstDim
impl UnsafeUnpin for ConstDim
impl UnwindSafe for ConstDim
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more