Base unit type constants for stable conversion
zmrocze opened this issue · comments
Karol Ochman-Milarski commented
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?
Mike Boutin commented
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, };
Mike Boutin commented
Closing this specific issue as the problem is covered elsewhere.