iliekturtles / uom

Units of measurement -- type-safe zero-cost dimensional analysis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow subtracting two thermodynamic temperatures

ISibboI opened this issue · comments

Hi, thanks for making uom! It has caught a few errors already in my small hobby project.

Currently, when I subtract two thermodynamic temperatures, I get the following error:

error[E0308]: mismatched types
   --> src\substance\water.rs:122:57
    |
122 |         let temperature_difference = self.temperature - target_temperature;
    |                                                         ^^^^^^^^^^^^^^^^^^ expected trait `Kind`, found trait `TemperatureKind`
    |
    = note: expected struct `Quantity<dyn Dimension<I = Z0, J = Z0, Kind = dyn Kind, L = Z0, M = Z0, N = Z0, T = Z0, Th = ...>, ..., ...>`
               found struct `Quantity<dyn Dimension<I = Z0, J = Z0, Kind = ..., L = ..., M = ..., N = ..., T = ..., Th = ...>, ..., ...>`

However, I would expect this to work and the result to be a TemperatureInterval.

How about adding another type parameter to Quantity that specifies if it can be added/subbed with itself or not? Then the default add/sub impl can be made only for some default value of that type parameter, and ThermodynamicTemperature could get its own implementation by having another value for this type parameter.

Closing as a duplicate of #380.