Description
Implement Energy as a ValueObject in the measurement module.
Spec: non-negative f64 with unit (J, kWh, cal)
Implementation checklist
Implementation detail
Input / Output
Energy is a composite value object that carries both a numeric value and a unit.
|
Type |
| Input |
EnergyInput { value: f64, unit: EnergyUnit } |
| Output |
String — e.g. "3600.0 J", "1.0 kWh" |
Define a unit enum in the same file:
EnergyUnit { J, Kwh, Cal }
EnergyUnit must derive Debug, Clone, Copy, PartialEq.
Validation
value must be >= 0.0 and finite.
Extra methods
amount() -> f64
unit() -> EnergyUnit
to_joules() -> f64 — convert to joules at call time.
References
Description
Implement
Energyas aValueObjectin themeasurementmodule.Spec: non-negative
f64with unit (J, kWh, cal)Implementation checklist
src/measurement/energy.rsValueObjecttrait#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]src/measurement/mod.rsandprelude# ExampleblockROADMAP.mdfrom ⬜ to ✅Implementation detail
Input / Output
Energyis a composite value object that carries both a numeric value and a unit.EnergyInput { value: f64, unit: EnergyUnit }String— e.g."3600.0 J","1.0 kWh"Define a unit enum in the same file:
EnergyUnitmust deriveDebug, Clone, Copy, PartialEq.Validation
valuemust be >= 0.0 and finite.Extra methods
amount() -> f64unit() -> EnergyUnitto_joules() -> f64— convert to joules at call time.References