Skip to content
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

parse a unit type from a string #391

Closed
happysalada opened this issue Dec 8, 2022 · 4 comments
Closed

parse a unit type from a string #391

happysalada opened this issue Dec 8, 2022 · 4 comments

Comments

@happysalada
Copy link

Is there a way to parse a unit type from a string ?
I need to send some values with their unit types to databases, so I was thinking of converting the unit type to a string to store it. I don't see any way of deserializing it from a string though, did I miss something ?

@iliekturtles
Copy link
Owner

Quantity implements FromStr. Is this what you're looking for or could you provide a bit more detail?

use uom::si::f32::Mass;

let l = "1 km".parse::<Mass>().unwrap();

@happysalada
Copy link
Author

Right, i was looking to use the unit types only, not directly a quantity. I was thinking of just separating the value and the unit in a struct.
I realized that this is not how this library was designed to be used though. Thank you for yout reply !

@iliekturtles
Copy link
Owner

Yes, uom isn't designed to work at the unit level currently. May this issue be closed, or did you still have an open issue looking to be resolved?

@happysalada
Copy link
Author

Thanks again !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants