iliekturtles / uom

Units of measurement -- type-safe zero-cost dimensional analysis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

parse a unit type from a string

happysalada opened this issue · comments

commented

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 ?

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();
commented

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 !

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?

commented

Thanks again !