-
Notifications
You must be signed in to change notification settings - Fork 89
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
Dynamically choose unit for new/get/floor/ceil/... methods #91
Comments
Review in more detail prior to v1.0.0. Can/should this be implemented now or pushed to v2.0.0? |
Out of curiosity what is happening here? It certainly seems to be picking units dynamically in the from_str test. I'm a rust newbie at the moment, I was able to see that Quantity! macro is generating a match statement for the from_str implementations, and adding my own parse statements in that test using eg |
You're right that the Rather than use the pre-built SI system, tests use a custom system that just includes length, mass, and thermodynamic temperature. The Using let l = "1 m".parse::<uom::si::f32::Length>().unwrap(); |
That works! The trick to getting the |
For what it's worth, I am practicing Rust by making a simple GUI for converting between units, and I ran into some of these limitations. Based on this experience, here are a few things that I think would simplify the implementation for this use case:
I played with the uom source a little, and it seems that a lot of these changes would be relatively easy to implement by changing the But I don't know how useful all this is for "real" use cases, as you would usually need to add some units that are not in the enum, so you would not be able to use all this functionality implemented for the enum. So I guess this dynamic unit selection would have to accept user-defined units to be truly helpful. |
Really cool to see what you have done! The addition of the |
Add a way to dynamically choose the unit when calling methods with a generic parameter
where N: Unit
. What is the best way to do this? Add methods that acceptdyn Unit
? Add anenum
for each quantity containing a member for each unit? Allow users to createenum
s on a per-quantity basis to only include the units they are interested in (this is useful at the UI level to provide a subset of units to a user)?The text was updated successfully, but these errors were encountered: