How to use whippyunits with strings as unit expression?

⚓ Rust    📅 2026-07-12    👤 surdeus    👁️ 3      

surdeus

I would like to save derived SI units, such as ohm, m/s or m/s^2 as string in a database together with a f64 value and found the crate whippyunits which at least seems like it could be capable of doing so. Unfortunately I cannot wrap my head around how to do that. In the documentation the unit expression always seems to be a TokenStream (I believe from the proc_macro2 crate?). How can I transform a string to that or is there something else? I am becoming desperate not knowing how to being able to do that. In the end I would like to do something like the whippyunits::quantity!(500.0, mm) (quantity in whippyunits - Rust) does just with the second argument (the unit_expr) being a string. Any ideas or suggestions?

1 post - 1 participant

Read full topic

🏷️ Rust_feed