Diman - compile time dimensional analysis library

68 points tehforsch_

I wanted to share a library that I've been working on for a while. It provides zero-cost compile-time unit checking using (unstable) const-generics. It is very much work in progress, but I've been using it for my simulations for quite a while now and been pretty happy with it. It provides a unit_system macro that one can use to define a quantity type within their own library. Quantity types and units constructors / conversion functions as well as all the numerical trait implementations are then automatically generated.
The macro attempts to make this as convenient as possible by allowing self-referential quantity/unit definitions such as

def Velocity = Length / Time,
unit meters_per_second = meters / seconds,

which are then automatically parsed and translated into code.

This started because I wanted to play with const generics and wanted full freedom for the unit types in my simulation and over time developed into a slightly more mature library. It still doesn't come close to non-const-generics unit libraries such as uom in terms of features, but doesn't rely on typenum which adds simplcitiy and makes error messages prettier.

If you're interested, please take a look:

https://crates.io/crates/diman

https://github.com/tehforsch/diman