mamrhein / quantities.rs

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

Why require at least one unit, if a ref_unit is also present? #5

Closed ttencate closed 2 years ago

ttencate commented 2 years ago

This does not compile:

#[quantity]
#[ref_unit(Bar, "bar")]
struct Foo;
error: At least one unit description must be given via attribute `unit`.

Kudos for the clear error message though!

I worked around it by adding an unused dummy unit, but that seems silly.

mamrhein commented 2 years ago

What's the use of a quantity which has only one unit?

mamrhein commented 2 years ago

Anyway, you can define a quantity with only one unit when not giving a reference unit:

#[quantity]
#[unit(Bar, "bar")]
struct Foo;
ttencate commented 2 years ago

What's the use of a quantity which has only one unit?

To avoid confusion with other quantities, and to combine them into new units. I mean, m and s and their derived units m/s and m/s² would be useful even if kilometers and hours didn't exist, right?

In my concrete use case, I'm working on an optimizer that optimizes for cost, so my quantity is euros, and I'm using other units like €/kWh for energy price and €/m/y for yearly depreciation of conduits.

It's just a small inconvenience, but it seemed to me there was no reason for the restriction.