uom icon indicating copy to clipboard operation
uom copied to clipboard

serde: Generate `serialize()` and `deserialize()` fns for each unit

Open Turbo87 opened this issue 2 months ago • 0 comments

This adds a private unit_serde! macro to automatically generate unit-specific serialization and deserialization functions when the serde feature is enabled. These functions are generic over storage types (f32, f64, etc.) and can be used with serde's serialize_with and deserialize_with attributes to handle JSON values in non-base units:

#[derive(Serialize, Deserialize)]
struct MyStruct {
    #[serde(serialize_with = "millimeter::serialize")]
    #[serde(deserialize_with = "millimeter::deserialize")]
    width: uom::si::f64::Length,
}

Turbo87 avatar Nov 08 '25 10:11 Turbo87