Tehforsch / diman

Define rust compile time unit systems using const generics
52 stars 2 forks source link

Add a `diman_lib` crate #68

Closed Tehforsch closed 8 months ago

Tehforsch commented 8 months ago

Certain types such as the Ratio type which is used for dimensions if rational dimensions are enabled and in the near future the type containing magnitudes (a const float type of thing) are needed by both diman_unit_system (to compute dimensions while parsing the macro) and by the calling crate (for the const generics). Now, there is no way to export them from diman_unit_system because it's a proc_macro crate and not allowed to export any non-proc_macros. They also can't be exported from diman because that would introduce a cyclic dependency.

I think adding a diman_lib that contains this shared functionality is useful.

  1. It solves the problem with duplicate code.
  2. Less code generated by the macro probably means slightly better compile behavior when the user uses their own custom unit_system and changes something in it.
  3. It doesnt require writing the code in the macro itself which is always a bit more bug-prone and just unfun in general.