Description
Implement Area as a ValueObject in the measurement module.
Spec: non-negative f64 with unit (m², cm², ft²)
Implementation checklist
Implementation detail
Input / Output
Area is a composite value object that carries both a numeric value and a unit.
|
Type |
| Input |
AreaInput { value: f64, unit: AreaUnit } |
| Output |
String — e.g. "50.0 m²", "538.20 ft²" |
Define a unit enum in the same file:
AreaUnit { M2, Cm2, Ft2 }
AreaUnit must derive Debug, Clone, Copy, PartialEq.
Validation
value must be >= 0.0 and finite.
Extra methods
amount() -> f64
unit() -> AreaUnit
to_square_meters() -> f64 — convert to m² at call time.
References
Description
Implement
Areaas aValueObjectin themeasurementmodule.Spec: non-negative
f64with unit (m², cm², ft²)Implementation checklist
src/measurement/area.rsValueObjecttrait#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]src/measurement/mod.rsandprelude# ExampleblockROADMAP.mdfrom ⬜ to ✅Implementation detail
Input / Output
Areais a composite value object that carries both a numeric value and a unit.AreaInput { value: f64, unit: AreaUnit }String— e.g."50.0 m²","538.20 ft²"Define a unit enum in the same file:
AreaUnitmust deriveDebug, Clone, Copy, PartialEq.Validation
valuemust be >= 0.0 and finite.Extra methods
amount() -> f64unit() -> AreaUnitto_square_meters() -> f64— convert to m² at call time.References