Description
Implement Length as a ValueObject in the measurement module.
Spec: non-negative f64 with unit (m, cm, mm, in, ft)
Implementation checklist
Implementation detail
Input / Output
Length is a composite value object that carries both a numeric value and a unit.
|
Type |
| Input |
LengthInput { value: f64, unit: LengthUnit } |
| Output |
String — e.g. "1.80 m", "5.00 ft" |
Define a unit enum in the same file:
LengthUnit { M, Cm, Mm, In, Ft }
LengthUnit must derive Debug, Clone, Copy, PartialEq.
Validation
value must be >= 0.0 and finite (not NaN, not infinite).
Extra methods
amount() -> f64 — the numeric value as supplied.
unit() -> LengthUnit — the unit as supplied.
to_meters() -> f64 — convert to the SI base unit at call time.
References
Description
Implement
Lengthas aValueObjectin themeasurementmodule.Spec: non-negative
f64with unit (m, cm, mm, in, ft)Implementation checklist
src/measurement/length.rsValueObjecttrait#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]src/measurement/mod.rsandprelude# ExampleblockROADMAP.mdfrom ⬜ to ✅Implementation detail
Input / Output
Lengthis a composite value object that carries both a numeric value and a unit.LengthInput { value: f64, unit: LengthUnit }String— e.g."1.80 m","5.00 ft"Define a unit enum in the same file:
LengthUnitmust deriveDebug, Clone, Copy, PartialEq.Validation
valuemust be >= 0.0 and finite (not NaN, not infinite).Extra methods
amount() -> f64— the numeric value as supplied.unit() -> LengthUnit— the unit as supplied.to_meters() -> f64— convert to the SI base unit at call time.References