Skip to main content

Crate rubo4e

Crate rubo4e 

Source
Expand description

§rubo4e

Rust implementation of the BO4E energy-market data standard.

§Feature gates

FeatureDefaultDescription
identifiers✓Identifier types (MaloId, EicCode, ObisCode, …) + serde
serde✓Serde derives + extension-data map
jsonserde_json helpers (to_json_*, from_json_*)
timetime crate for timestamps; also utoipa/time
decimalrust_decimal::Decimal for amounts/prices (see note below); also schemars/rust_decimal1 and utoipa/decimal
buildertyped-builder derives with setter(into) — accepts both T and Option<T>
validategarde validation
schemarsJSON Schema generation
sqlxsqlx type integrations
utoipautoipa OpenAPI integrations
strumEnum iteration and string conversion
versionedExpose the versioned schema module (v202607)
tracingStructured diagnostics via the tracing crate
metricsOptional export hooks via the metrics crate

§Identifiers without schema overhead

Every identifier type always provides Display, FromStr, TryFrom<&str>, TryFrom<String>, Into<String>, AsRef<str>, Borrow<str>, and Deref<Target = str> without any feature flag — the minimum needed for EDIFACT wire-format encoding and decoding.

To use only identifier types without pulling in the versioned BO4E schema:

rubo4e = { version = "...", default-features = false, features = ["identifiers"] }

This gives serde support on all identifiers with zero versioned-schema overhead.

§serde is enabled by default

The default feature set is default = ["identifiers"], and identifiers enables serde. Targets that only need the type definitions for in-memory processing can opt out:

rubo4e = { version = "...", default-features = false, features = ["versioned"] }

§Feature-conditional field types (decimal and time)

Enabling decimal or time changes the Rust type of certain struct fields:

FeatureWithout featureWith featureAffected fields
decimalOption<String>Option<rust_decimal::Decimal>wert, preis, amounts, quantities
timeOption<String>Option<time::OffsetDateTime> or Option<time::Date>beginn/ende fields → OffsetDateTime; *datum fields → Date

This means code that compiles under one feature configuration may not compile under the other. For code that must be feature-agnostic, either:

  • Always enable decimal/time and use the strong types, or
  • Access fields through JSON round-trip (to_json_german / from_json_german) which is feature-independent.

The string fallback keeps the value’s lexical form, so nothing is lost when these features are absent.

Decimal fields read a JSON number as well as a JSON string, because BO4E producers use both — but only the string spelling is exact. A number has already passed through f64 before this crate sees it, losing its scale (119.00 → 119) and any precision past ~15 significant digits. decimal_serde documents the whole picture and counts every such read.

§Eq and Hash on generated structs

Generated BO and COM structs always derive PartialEq. They additionally derive Eq and Hash when the json feature is off, which is what lets them key a HashMap or a HashSet.

One type blocks both: serde_json::Value, which appears in a generated struct twice when json is on — inside LimitedExtensionMap (the _additional field) and as ZusatzAttribut::wert. Value is neither Eq nor Hash, because it wraps f64 and NaN != NaN. With json off both degrade to a ZST stub and a String, and the whole tree becomes Eq + Hash.

Generated enums are always Eq + Ord + Hash, whatever the features.

For content-addressed equality across every feature set, compare to_json_canonical() (from Bo4eJsonExt in the json module), which produces a deterministic byte string.

Modules§

convenienceversioned
Hand-written convenience methods on generated BO4E types.
currentversioned
Current stable BO4E schema version — always resolves to the latest stable schema (v202607 in this release).
decimal_serdeserde
Decimal deserialization, and what BO4E’s two spellings of a number cost.
error
Error types returned by identifier construction.
identifiers
Domain identifier newtypes for BO4E energy-market entities.
iso8601_durationtime
ISO 8601 duration parsing for BO4E’s dauer fields.
jsonjson
JSON serialization helpers: json::Bo4eJsonExt with to_json_german(), to_json_snake_case(), and to_json_canonical(). JSON serialization helpers for BO4E types.
offset_timetime
Time-of-day parsing for BO4E’s format: "time" fields.
prelude
Re-exports the most commonly used types.
schema_helpersschemars
Schema helper functions used by generated schemars attributes.
strictversioned
Strict-decoding support: reject out-of-schema (Unknown) enum values anywhere in a deserialized payload. See Bo4eStrict and strict::StrictError. Strict-decoding support for BO4E payloads.
time_serdeserde and time
Serde modules for time::Date fields in generated structs.
v202607versioned
BO4E schema v202607 types.
validationvalidate
Cross-field business-rule validators for BO4E types (requires validate + versioned). Also exports Validated<T> which only requires validate. Cross-field business-rule validators for BO4E types, plus the Validated wrapper.

Structs§

LimitedExtensionMapjson
Always-available re-export of json::extension::LimitedExtensionMap.

Traits§

Bo4eComponentversioned
Marks a generated component (COM) — the BO4E types that appear nested inside a Geschäftsobjekt rather than on their own.
Bo4eEnumversioned
Uniform introspection & strict-parsing surface implemented by every generated BO4E enum (Zaehlertyp, Marktrolle, BdewArtikelnummer, …).
Bo4eObjectversioned
Marks a generated Geschäftsobjekt — the BO4E types that stand on their own as a message payload.
Bo4eStrictversioned
Recursive strict-decode check: find every out-of-schema (Unknown) enum value anywhere inside a deserialized BO4E value.
Bo4eTypedversioned
The _typ discriminant, as constants — implemented by every generated BO and COM.