Skip to main content

Module unit_arithmetic

Module unit_arithmetic 

Source
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 → Unitless
  • N / Per<N, D> → D
  • Per<N, D> * D → N
  • D * 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> (when A ≠ 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§

SameDivOutput
Marker returned by UnitDiv<U> when the numerator and denominator units are identical. It is not a Unit; the Div impl uses it to produce the raw scalar S instead of a Quantity.

Traits§

QuantityDivOutput
Converts a UnitDiv::Output token into the concrete type returned by Div.
UnitDiv
Determines the unit type produced by dividing a quantity of unit Self by a quantity of unit Rhs.
UnitMul
Determines the unit type produced by multiplying a quantity of unit Self by a quantity of unit Rhs.
UnitSqrt
Inverse of squaring at the type level: maps a “squared” unit back to its scalar root unit.