Skip to main content

ConstDim

Struct ConstDim 

Source
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: i8

Length exponent (m).

§m: i8

Mass exponent (kg).

§t: i8

Time exponent (s).

§i: i8

Electric current exponent (A).

§th: i8

Thermodynamic temperature exponent (K).

§n: i8

Amount of substance exponent (mol).

§j: i8

Luminous intensity exponent (cd).

Implementations§

Source§

impl ConstDim

Source

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.

Source

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.

Source

pub const fn div(self, rhs: Self) -> Self

Divide two dimension vectors (subtract exponents), saturating like mul; see checked_div.

Source

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 wraps
Source

pub const fn checked_div(self, rhs: Self) -> Option<Self>

div, or None when an exponent leaves the i8 range.

Source

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

pub const fn eq(self, rhs: Self) -> bool

Check equality of two dimension vectors (const-compatible).

Source

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

pub fn name(&self) -> &'static str

Return a human-readable name for well-known dimensions, or a raw exponent string for exotic ones.

Source

pub fn from_name(name: &str) -> Option<ConstDim>

Look up a named dimension constant by its human-readable name.

Returns None for unrecognized names. This is the inverse of name() for all known dimensions.

Source§

impl ConstDim

Source

pub const DIMENSIONLESS: Self

Dimensionless dimension: all exponents zero.

Source

pub const ANGLE: Self

Angle dimension: dimensionless (all exponents zero).

Source

pub const LENGTH: Self

Length dimension: L¹.

Source

pub const MASS: Self

Mass dimension: M¹.

Source

pub const TIME: Self

Time dimension: T¹.

Source

pub const CURRENT: Self

Electric current dimension: I¹.

Source

pub const TEMPERATURE: Self

Temperature dimension: Θ¹.

Source

pub const AREA: Self

Area dimension: L².

Source

pub const VOLUME: Self

Volume dimension: L³.

Source

pub const VELOCITY: Self

Velocity dimension: L¹·T⁻¹.

Source

pub const ACCELERATION: Self

Acceleration dimension: L¹·T⁻².

Source

pub const ANGULAR_VELOCITY: Self

Angular velocity dimension: T⁻¹.

Source

pub const ANGULAR_ACCELERATION: Self

Angular acceleration dimension: T⁻².

Source

pub const FREQUENCY: Self

Frequency dimension: T⁻¹.

Source

pub const FORCE: Self

Force dimension: L¹·M¹·T⁻².

Source

pub const ENERGY: Self

Energy dimension: L²·M¹·T⁻².

Source

pub const TORQUE: Self

Torque dimension: L²·M¹·T⁻².

Source

pub const POWER: Self

Power dimension: L²·M¹·T⁻³.

Source

pub const MOMENTUM: Self

Momentum dimension: L¹·M¹·T⁻¹.

Source

pub const ANGULAR_MOMENTUM: Self

Angular momentum dimension: L²·M¹·T⁻¹.

Source

pub const MOMENT_OF_INERTIA: Self

Moment of inertia dimension: L²·M¹.

Source

pub const PRESSURE: Self

Pressure dimension: L⁻¹·M¹·T⁻².

Source

pub const STIFFNESS: Self

Stiffness dimension: M¹·T⁻².

Source

pub const DAMPING: Self

Damping dimension: M¹·T⁻¹.

Source

pub const VOLTAGE: Self

Voltage dimension: L²·M¹·T⁻³·I⁻¹.

Source

pub const RESISTANCE: Self

Resistance dimension: L²·M¹·T⁻³·I⁻².

Source

pub const INDUCTANCE: Self

Inductance dimension: L²·M¹·T⁻²·I⁻².

Source

pub const CAPACITANCE: Self

Capacitance dimension: L⁻²·M⁻¹·T⁴·I².

Source

pub const CHARGE: Self

Charge dimension: T¹·I¹.

Source

pub const MAGNETIC_FLUX: Self

Magnetic flux dimension: L²·M¹·T⁻²·I⁻¹.

Trait Implementations§

Source§

impl Clone for ConstDim

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ConstDim

Source§

impl Debug for ConstDim

Source§

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

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

impl Display for ConstDim

Source§

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

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

impl Eq for ConstDim

Source§

impl PartialEq for ConstDim

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ConstDim

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more