Skip to content

Add Energy (measurement) #63

@vhrcgcom

Description

@vhrcgcom

Description

Implement Energy as a ValueObject in the measurement module.

Spec: non-negative f64 with unit (J, kWh, cal)

Implementation checklist

  • Create src/measurement/energy.rs
  • Implement ValueObject trait
  • Add #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
  • Export from src/measurement/mod.rs and prelude
  • Unit tests: valid input · empty input · invalid format · normalisation
  • Doc comment with # Example block
  • Update status in ROADMAP.md from ⬜ to ✅

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions