iliekturtles / uom

Units of measurement -- type-safe zero-cost dimensional analysis
Apache License 2.0
1.02k stars 97 forks source link

Types for new combined quantities are really difficult to write #174

Open nakedible opened 4 years ago

nakedible commented 4 years ago

I had to store the molar gas constant in a place where I had to write the type of the variable for Rust. The SI unit is "joule per kelvin per mole". Heat capacity is "joule per kelvin" and molar energy is "joule per mole", so neither will do directly.

What I finally came up with much trial and error was:

type HeatCapacityPerAmountOfSubstance = Quantity<ISQ<P2, P1, N2, Z0, N1, N1, Z0>, SI<f64>, f64>;

However, this is not really user friendly. Perhaps there could be a macro to help with this?

iliekturtles commented 4 years ago

Another good suggestion. Your code snippet above is the best way currently.