Expand description
Stable unit arithmetic layer: UnitDiv and UnitMul traits.
Stable, macro-generated unit arithmetic layer.
This module provides the UnitDiv and UnitMul traits that control what
unit type results from dividing or multiplying two quantities. The blanket
Quantity<N> / Quantity<D> and Quantity<A> * Quantity<B> operator impls
delegate to these traits to determine the output unit.
Generic “recovery” impls are provided for common structural patterns:
U / U → UnitlessN / Per<N, D> → DPer<N, D> * D → ND * Per<N, D> → N
For all built-in unit pairs (plain marker types), fallback impls produce the default composite types:
A / B → Per<A, B>(whenA ≠ B)A * B → Prod<A, B>
Downstream crates can use the exported macros
impl_unit_division_pairs!, impl_unit_multiplication_pairs!,
impl_unit_arithmetic_pairs!, and their *_between! variants to
register their own custom units into the same fallback tables without
regenerating built-in/built-in impls.
Structs§
- Same
DivOutput - Marker returned by
UnitDiv<U>when the numerator and denominator units are identical. It is not aUnit; theDivimpl uses it to produce the raw scalarSinstead of aQuantity.
Traits§
- Quantity
DivOutput - Converts a
UnitDiv::Outputtoken into the concrete type returned byDiv. - UnitDiv
- Determines the unit type produced by dividing a quantity of unit
Selfby a quantity of unitRhs. - UnitMul
- Determines the unit type produced by multiplying a quantity of unit
Selfby a quantity of unitRhs. - Unit
Sqrt - Inverse of squaring at the type level: maps a “squared” unit back to its scalar root unit.