macro_rules! assert_dim {
($expr:expr, $expected:ty) => { ... };
}Expand description
Compile-time dimension checkpoint.
Asserts that an expression has the expected named dimension type. If the type doesn’t match, the compiler error shows “expected Force, found Velocity” (or similar clear message).
The macro evaluates the expression, binds it to a local with the expected type annotation, and returns it — so it can be used inline.
§Examples
ⓘ
use symplex::prelude::*;
use symplex::units::*;
let ctx = Context::new();
let m = Mass::symbol(&ctx, "m");
let a = Acceleration::symbol(&ctx, "a");
let f = symplex::assert_dim!(m * a, Force);If you accidentally write:
ⓘ
use symplex::prelude::*;
use symplex::units::*;
let ctx = Context::new();
let m = Mass::symbol(&ctx, "m");
let a = Acceleration::symbol(&ctx, "a");
// Wrong! Mass × Acceleration is Force, not Velocity.
let v = symplex::assert_dim!(m * a, Velocity);the compiler will report a type mismatch between Force and Velocity.