Constant expression depends on a generic parameter

I'm trying to write another yet physical unit/dimension crate, because none of the crates I've found are generic enough.

After some experiments, I tried using constant generics to represent the exponent of a dimension (L, L², L·T-1, etc.). But I need to do arithmetic with the constant parameters (L¹×L¹=L²).

See a simplified version of my code

It gives the error:

error: constant expression depends on a generic parameter
  --> src/lib.rs:23:5
   |
23 |     type Output = Meter<O, {D + RD}>;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
  --> src/lib.rs:25:40
   |
25 |     fn mul(self, rhs: Meter<R, RD>) -> Self::Output {
   |                                        ^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

Is it possible to do that? If not, I will use typenum.

I would stick to typenum for now, const-generics doesn't currently handle expressions in any way.
edit: dimensioned is a good library for handling arbitrary units (like meter, second, lumen)

It works well with typenum. (playground for the curious)

I didn't look enough time at dimensioned, it's good indeed, and it's very close to my code... I will test if it is usable with maths-traits.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.