-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Add Quantity::as_ and Quantity::cast for changing the underlying storage type. #294
base: master
Are you sure you want to change the base?
Conversation
774ac46
to
04e0f60
Compare
I think we could add a separate trait
but I am not sure how much this would add w.r.t. generality as it would still cover only the |
Thanks for the PR! I'll take a look this coming week and see if I can figure out anything with the traits. |
I don't think using The following diff compiles so it works... right? I went a slightly different way and defined a I'll do some thinking about usability over the weekend as I think the ability to do type conversions is proven, it's just a matter of determining what the interface should be.
|
The trait bound which did not work out for me was
as e.g. |
04e0f60
to
857de2b
Compare
A first go at something helping with #293.
The restriction to
$units<V>
instead ofU: Units<V>
seems a bit weird, but it was the only way I saw to enforce that the same set of base units would be used for the conversion. (The more general version fails with trait bound errors as e.g. thef32
base units do not implementUnits<i32>
and without generic associated types there is no way to ask aUnits<V>
implementor for its equivalentUnits<W>
implementor AFAIU.)Finally, while I added minimal doc tests, I am not sure where actual unit tests should end up as this involves at least two storage types by definition.