iliekturtles / uom

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Base unit type constants for stable conversion

zmrocze opened this issue · comments

Hey,
I'd like to serialize values to floats, casually:

let position: Length;
let position_ser : f64 = position.value;  // in base unit

and now to deserialize I'd just need to know the base unit for the given quantity:

let position_deser = Length::new::<Length::BASE_UNIT>(positition_ser);

would it be possible to define such a constant? or is there another way?

This is one of uom's warts right now. The best way at the current time is to skip the new constructor and create the struct directly:

let position_deser = Length { dimension: PhantomData, units: PhantomData, value: position_ser, };

Closing this specific issue as the problem is covered elsewhere.