iliekturtles / uom

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

Allow subtracting two thermodynamic temperatures #447

Closed ISibboI closed 8 months ago

ISibboI commented 10 months ago

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.

jacg commented 10 months ago

See

ISibboI commented 10 months ago

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.

iliekturtles commented 8 months ago

Closing as a duplicate of #380.