mamrhein/quantities.rs

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

Closed this issue · 3 comments

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.

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

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

#[quantity]
#[unit(Bar, "bar")]
struct Foo;

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.