mamrhein / quantities.rs

Unit-safe computations with quantities.
BSD 3-Clause "New" or "Revised" License
25 stars 10 forks source link

Power = Energy / Time, but Energy / Power != Time #6

Closed ttencate closed 2 years ago

ttencate commented 2 years ago

This does not compile:

assert_eq!(
    (6.0 * KILOWATT_HOUR) / (2.0 * KILOWATT),
    3.0 * HOUR);
error[E0277]: cannot divide `Energy` by `Power`
   --> src/units.rs:108:35
    |
108 |             (6.0 * KILOWATT_HOUR) / (2.0 * KILOWATT),
    |                                   ^ no implementation for `Energy / Power`
    |
    = help: the trait `Div<Power>` is not implemented for `Energy`

More generally, if a unit U is defined as the quotient N / D, then operators should be defined both for N / D -> U and for N / U ->D, right?

mamrhein commented 2 years ago

Solved in version '0.11.0'.

ttencate commented 2 years ago

Works great, thank you for the super speedy response!