Description
Implement Weight as a ValueObject in the measurement module.
Spec: non-negative f64 with unit (kg, g, lb, oz)
Implementation checklist
Implementation detail
Input / Output
Weight is a composite value object that carries both a numeric value and a unit.
|
Type |
| Input |
WeightInput { value: f64, unit: WeightUnit } |
| Output |
String — e.g. "70.0 kg", "154.32 lb" |
Define a unit enum in the same file:
WeightUnit { Kg, G, Lb, Oz }
WeightUnit must derive Debug, Clone, Copy, PartialEq.
Validation
value must be >= 0.0 and finite.
Extra methods
amount() -> f64
unit() -> WeightUnit
to_kilograms() -> f64 — convert to the SI base unit at call time.
References
Description
Implement
Weightas aValueObjectin themeasurementmodule.Spec: non-negative
f64with unit (kg, g, lb, oz)Implementation checklist
src/measurement/weight.rsValueObjecttrait#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]src/measurement/mod.rsandprelude# ExampleblockROADMAP.mdfrom ⬜ to ✅Implementation detail
Input / Output
Weightis a composite value object that carries both a numeric value and a unit.WeightInput { value: f64, unit: WeightUnit }String— e.g."70.0 kg","154.32 lb"Define a unit enum in the same file:
WeightUnitmust deriveDebug, Clone, Copy, PartialEq.Validation
valuemust be >= 0.0 and finite.Extra methods
amount() -> f64unit() -> WeightUnitto_kilograms() -> f64— convert to the SI base unit at call time.References