Skip to main content

Crate datex2

Crate datex2 

Source
Expand description

An unofficial Rust implementation of DATEX II, the European standard for road traffic and travel information.

This release reads DATEX II version 3, in XML and in JSON, into typed data, and writes it. To read, one call is enough:

let xml = br#"<d2:payload xmlns:d2="http://datex2.eu/schema/3/d2Payload"
    xmlns:com="http://datex2.eu/schema/3/common" xmlns:sit="http://datex2.eu/schema/3/situation"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:type="sit:SituationPublication" lang="en" modelBaseVersion="3">
  <com:publicationTime>2026-11-19T12:00:00Z</com:publicationTime>
  <com:publicationCreator>
    <com:country>NL</com:country>
    <com:nationalIdentifier>EXAMPLE</com:nationalIdentifier>
  </com:publicationCreator>
</d2:payload>"#;

let doc = datex2::v3::read(&xml[..])?;
for publication in &doc.publications {
    println!("published at {:?}", publication.publication_time());
    if let datex2::v3::Publication::Situation(p) = publication {
        println!("{} situations", p.situation.len());
    }
}

§What the reader does for you

  • No setup. The envelope (payload, messageContainer, a bare publication, SOAP around any of them), namespace prefixes and the publication type are detected.
  • Tolerant, and it tells you. Real feeds deviate from the standard. The reader accepts the deviations it knows and lists each one in v3::Document::warnings. Nothing is dropped silently and no value is invented.
  • Errors you can act on. An Error names the element path, the byte offset, what was expected and what was found.
  • Safe on untrusted input. Limits bound nesting, attributes and text; document type declarations are refused. The threat model lists what is defended against and what is not.

§Large files

v3::stream delivers the records of a document one at a time and keeps only one in memory.

§Writing

v3::write turns a publication or a message container into a document the official schema accepts, or says which rule of the schema it breaks.

§JSON and the Mobilithek

v3::json reads and writes the same model as JSON: the official DATEX II 3.7 mapping, and the German AFIR Recharging profile the Mobilithek requires (v3::json::mobilithek). Numbers keep their exact value; the crate has no JSON dependency.

§What it does not do

DATEX II versions 1 and 2, and any network or file access. The crate reads the bytes you give it and writes to the sink you give it.

This crate is not affiliated with or endorsed by the DATEX II organisation.

Modules§

threat_model
Threat model
v3
DATEX II version 3.

Structs§

Date
A calendar date, with the time-zone offset if the document gave one.
DateTime
A point in time as written in the document.
Decimal
A decimal number kept exactly as written, so that prices never pass through a float.
Error
Why a read or a write failed.
Extension
Content of an extension slot, kept as it was written.
LangString
A text in one language.
Limits
Bounds applied to input, which is assumed to be untrusted.
MultilingualString
A text given in zero or more languages.
ParseValueError
The text is not a value of the type asked for.
Time
A time of day with nanosecond precision.
Warning
A deviation the reader tolerated.

Enums§

ErrorKind
The class of an Error.
WarningKind
The class of a Warning.