Description
Implement Speed as a ValueObject in the measurement module.
Spec: non-negative f64 with unit (m/s, km/h, mph)
Implementation checklist
Implementation detail
Input / Output
Speed is a composite value object that carries both a numeric value and a unit.
|
Type |
| Input |
SpeedInput { value: f64, unit: SpeedUnit } |
| Output |
String — e.g. "100.0 km/h", "27.78 m/s" |
Define a unit enum in the same file:
SpeedUnit { Ms, Kmh, Mph }
SpeedUnit must derive Debug, Clone, Copy, PartialEq.
Validation
value must be >= 0.0 and finite.
Extra methods
amount() -> f64
unit() -> SpeedUnit
to_meters_per_second() -> f64 — convert to m/s at call time.
References
Description
Implement
Speedas aValueObjectin themeasurementmodule.Spec: non-negative
f64with unit (m/s, km/h, mph)Implementation checklist
src/measurement/speed.rsValueObjecttrait#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]src/measurement/mod.rsandprelude# ExampleblockROADMAP.mdfrom ⬜ to ✅Implementation detail
Input / Output
Speedis a composite value object that carries both a numeric value and a unit.SpeedInput { value: f64, unit: SpeedUnit }String— e.g."100.0 km/h","27.78 m/s"Define a unit enum in the same file:
SpeedUnitmust deriveDebug, Clone, Copy, PartialEq.Validation
valuemust be >= 0.0 and finite.Extra methods
amount() -> f64unit() -> SpeedUnitto_meters_per_second() -> f64— convert to m/s at call time.References