rubo4e ⚡
A Rust implementation of the BO4E energy-market data standard — the canonical data model for the German energy industry.
⚠️ This is not an official BO4E implementation. The official reference implementation is BO4E-python. This crate aims for idiomatic Rust ergonomics, strong domain types, and ecosystem integration.
✨ Features
- 🏗️ Generated types from the official BO4E JSON Schema (v202501)
- 🔒 Strong domain identifiers —
MaloId,MeloId,EicCode,ObisCode, … with embedded validation - ✅ Three-layer validation — constructor checks,
gardestruct rules, cross-field business logic - 🔧 Typed builders — compile-time required-field enforcement via
typed-builder; optional-field setters accept bothTandOption<T> - 🌍 German / English / Canonical JSON — BO4E wire format out of the box
- 📐 JSON Schema via
schemars, OpenAPI viautoipa, DB viasqlx - 🧪 Golden corpus and fuzz harnesses included; proptest round-trip tests run as dev tests
📦 Installation
Add to your Cargo.toml:
[]
= "0.3"
Enable optional features as needed:
= { = "0.3", = ["json", "versioned", "validate", "builder"] }
🚀 Quick Start
use *;
use ;
🎛️ Feature Gates
| Feature | Default | Description |
|---|---|---|
serde |
✓ | Serde derives + extension-data map |
json |
serde_json helpers (to_json_german(), …) |
|
simd-json |
SIMD-accelerated JSON parsing backend | |
time |
time crate for timestamps |
|
decimal |
rust_decimal::Decimal for amounts and prices |
|
builder |
typed-builder derives |
|
validate |
garde validation |
|
schemars |
JSON Schema generation | |
sqlx |
sqlx type integrations (PostgreSQL) |
|
utoipa |
utoipa OpenAPI integration |
|
strum |
Enum iteration and string conversion | |
versioned |
Versioned schema modules (v202501, current) |
|
tracing |
Structured diagnostics via the tracing crate |
|
metrics |
Counter export hooks (metrics ecosystem) |
🗂️ Schema Versions
| Module | Status |
|---|---|
v202501 |
✅ Current stable |
Use the versioned module to pin a stable schema:
use Marktlokation; // pin to v202501
use Marktlokation; // always the latest stable — advances with crate updates
🏷️ Identifiers
All domain identifiers validate their format on construction:
| Type | Format / Rule |
|---|---|
MaloId |
11 digits, BDEW alternating-weight checksum |
SrId |
11 digits, BDEW alternating-weight checksum (same algorithm as MaloId) |
TrId |
11 digits, BDEW alternating-weight checksum (same algorithm as MaloId) |
MeloId |
33 characters: 2-char ISO country code + 31 alphanumeric |
NeloId |
11 alphanumeric characters |
EicCode |
16-character EIC with check character (types A, T, V, W, X, Y, Z) |
ObisCode |
OBIS identifier (e.g. 1-0:1.8.1); C ≥ 1 enforced |
MarktpartnerId |
13 decimal digits, no checksum |
Identifier Utilities
Beyond construction, identifiers expose domain-specific helpers:
// Compute check digit / build from base (MaloId, SrId, TrId)
let check = check_digit?; // → 0
let id = from_base?; // → "51238696780"
// Country code extraction (MeloId)
let melo = new?;
assert_eq!;
assert!;
// Integer round-trip for legacy systems (MarktpartnerId)
let mp = new?;
assert_eq!;
// Serde as integer instead of string (opt-in, field-level)
pub partner_id: MarktpartnerId,
Convenience Methods on Generated Types
The convenience module adds ergonomic helpers on generated BO types
(requires versioned + time features):
use ;
// Rechnung — closed billing period
if let Some = rechnung.billing_period
// PreisblattNetznutzung — open-ended or closed validity
match preisblatt.validity
// Zeitraum — low-level range helpers (also available on all types with gueltigkeit)
let z: Zeitraum = todo!;
let closed = z.as_closed_range; // Option<(Date, Date)>
let half_open = z.as_half_open_range; // Option<(Date, Option<Date>)>
📚 Documentation
- docs/architecture.md — Workspace layout, module tree, Mermaid diagram
- docs/generator.md — Internal code generator
- docs/identifiers.md — All identifier types and validation rules
- docs/versioning.md — Schema versions and migration
- docs/validation.md — Three-layer validation
- docs/serialization.md — Serialization modes
- docs/ecosystem.md — schemars, sqlx, utoipa, strum integrations
- docs/testing.md — Test categories, golden corpus, fuzz harness
🔗 Related Projects
| Project | Language | Notes |
|---|---|---|
| BO4E-python | Python | Official reference implementation |
| BO4E-Schemas | JSON Schema | Canonical schema source |
| go-bo4e | Go | Most mature non-Python implementation |
| bo4e-rust | Rust | Hochfrequenz's Rust implementation |
📜 License
Dual-licensed under MIT or Apache 2.0 — your choice.
The BO4E standard itself is maintained by the Interessengemeinschaft Geschäftsobjekte Energiewirtschaft e. V..