Description
Implement Volume as a ValueObject in the measurement module.
Spec: non-negative f64 with unit (l, ml, m³, fl oz)
Implementation checklist
Implementation detail
Input / Output
Volume is a composite value object that carries both a numeric value and a unit.
|
Type |
| Input |
VolumeInput { value: f64, unit: VolumeUnit } |
| Output |
String — e.g. "1.50 l", "500.00 ml" |
Define a unit enum in the same file:
VolumeUnit { L, Ml, M3, FlOz }
VolumeUnit must derive Debug, Clone, Copy, PartialEq.
Validation
value must be >= 0.0 and finite.
Extra methods
amount() -> f64
unit() -> VolumeUnit
to_liters() -> f64 — convert to litres at call time.
References
Description
Implement
Volumeas aValueObjectin themeasurementmodule.Spec: non-negative
f64with unit (l, ml, m³, fl oz)Implementation checklist
src/measurement/volume.rsValueObjecttrait#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]src/measurement/mod.rsandprelude# ExampleblockROADMAP.mdfrom ⬜ to ✅Implementation detail
Input / Output
Volumeis a composite value object that carries both a numeric value and a unit.VolumeInput { value: f64, unit: VolumeUnit }String— e.g."1.50 l","500.00 ml"Define a unit enum in the same file:
VolumeUnitmust deriveDebug, Clone, Copy, PartialEq.Validation
valuemust be >= 0.0 and finite.Extra methods
amount() -> f64unit() -> VolumeUnitto_liters() -> f64— convert to litres at call time.References