Skip to main content

const_assert_dim

Macro const_assert_dim 

Source
macro_rules! const_assert_dim {
    ($computed:expr, $expected:expr, $msg:literal) => { ... };
}
Expand description

Compile-time formula dimension verification with custom error messages.

Uses const evaluation to check that a dimension formula produces the expected result. If wrong, the compiler emits the custom message as a compile-time panic.

This macro operates on ConstDim values, which carry dimension exponents as plain i8 values suitable for const fn arithmetic.

§Examples

use symplex::units::ConstDim;

// Verified at compile time — F = ma:
symplex::const_assert_dim!(
    ConstDim::MASS.mul(ConstDim::ACCELERATION),
    ConstDim::FORCE,
    "F = ma: Mass × Acceleration must equal Force"
);

// Energy = Force × Length:
symplex::const_assert_dim!(
    ConstDim::FORCE.mul(ConstDim::LENGTH),
    ConstDim::ENERGY,
    "E = F·d: Force × Length must equal Energy"
);