macro_rules! impl_si_serialize_as {
($prefix:ident, $qty_type:ty, $unit:path) => { ... };
}Expand description
Generate a family of #[serde(serialize_with)]-compatible helpers that
serialize a UOM SI quantity as a specific (non-base) unit.
Expands to helper functions covering wrapper combinations used in this codebase:
| Generated function | Field type |
|---|---|
$prefix | $qty_type |
tracked_$prefix | TrackedState<$qty_type> |
opt_$prefix | Option<$qty_type> |
vec_$prefix | Vec<$qty_type> |
vec_tracked_$prefix | Vec<TrackedState<$qty_type>> |
tracked_opt_$prefix | TrackedState<Option<$qty_type>> |
opt_tracked_$prefix | Option<TrackedState<$qty_type>> |
vec_tracked_opt_$prefix | Vec<TrackedState<Option<$qty_type>>> |
§Example
ⓘ
// In serde_helpers.rs:
use crate::{si, utils::tracked_state::TrackedState};
crate::impl_si_serialize_as!(power_as_kilowatts, si::Power, uom::si::power::kilowatt);
// In serde_api/serde_utils.rs serialize_with match:
"Power" => Some("crate::serde_helpers::power_as_kilowatts"),
// In the unit_impls match (must match the target unit):
"Power" => extract_units!(uom::si::power::kilowatt),