uom's Quantity::from_str implementation is quite strict. It requires a number, a space and then an abbreviated unit. It does not support strings like "100g" or even "100 grams", even though these are natural ways for humans to write measurements.
I have implemented my own layer on top of uom's from_str to relax the requirement for a space, but there is no way for me to make it work for full units without manually listing all of the units in my code because uom doesn't seem to provide any functionality to work with full unit strings rather than abbreviations.
Could uom provide a function like Mass::from_str_unit(100.0f64, "grams") -> Result<...> (which would also accept "gram" and "g", but also "pounds" and "kg" and so on)? From my perspective, this would actually be better than changing from_str, as it makes it possible for me to implement my own human-friendly parsing code without needing to incorporate my opinions about human-friendly parsing into uom itself.
If this is not practical, could the from_str implementation be extended to allow the singular and plural units? Right now my human-friendly parsing layer works by creating a temporary string which does fit uom's desired format and then asking uom to parse that.
uom's
Quantity::from_strimplementation is quite strict. It requires a number, a space and then an abbreviated unit. It does not support strings like "100g" or even "100 grams", even though these are natural ways for humans to write measurements.I have implemented my own layer on top of uom's
from_strto relax the requirement for a space, but there is no way for me to make it work for full units without manually listing all of the units in my code because uom doesn't seem to provide any functionality to work with full unit strings rather than abbreviations.Could uom provide a function like
Mass::from_str_unit(100.0f64, "grams") -> Result<...>(which would also accept "gram" and "g", but also "pounds" and "kg" and so on)? From my perspective, this would actually be better than changingfrom_str, as it makes it possible for me to implement my own human-friendly parsing code without needing to incorporate my opinions about human-friendly parsing into uom itself.If this is not practical, could the
from_strimplementation be extended to allow the singular and plural units? Right now my human-friendly parsing layer works by creating a temporary string which does fit uom's desired format and then asking uom to parse that.