ISO 9735 · Rust

EDIFACT for Rust that refuses to guess.

Zero-copy parsing, typed derive macros, layered validation and a writer that computes its own envelope. Malformed input is an error, never a plausible-looking wrong value.

cargo add edifact

edifact on crates.io API documentation on docs.rs CI status

Parse, address, validate

Borrow straight from the bytes

use edifact::from_bytes;

let input = b"UNA:+.? 'BGM+220+PO-4711+9'";
let segments: Vec<_> = from_bytes(input).collect::<Result<_, _>>()?;

assert_eq!(segments[0].tag, "BGM");
assert_eq!(segments[0].element_str(1), Some("PO-4711"));

Address fields by identifier, not index

// A stale or mistyped identifier is a compile error,
// not a quiet read of the neighbouring element.
#[derive(EdifactDeserialize)]
#[edifact(segment = "NAD", layout = NAD_DEF)]
struct Nad {
    #[edifact(element = "3035")] qualifier: String,
    #[edifact(element = "3039")] party_id: String,
}

Why edifact

Frequently asked

What is EDIFACT?

EDIFACT — Electronic Data Interchange For Administration, Commerce and Transport — is the UN standard for structured business messages, defined in ISO 9735. An interchange is flat text: segments separated by a terminator, each carrying data elements, optionally split into components. It is used in supply chain, logistics, energy, healthcare and banking. See Core Concepts.

How is this different from a split-on-delimiters parser?

The UNA can redefine every delimiter, any delimiter can appear in a value when release-escaped, and syntax version 4 adds a repetition separator. A naive split merges or truncates values in all three cases.

Can edifact stream files larger than memory?

Yes. A reader iterator holds one segment (at most 64 KiB) and a read buffer. A message window holds one UNH…UNT message of at most max_message_bytes (16 MiB by default), parsed into at most 128× that in heap. See Streaming.

Is it safe against hostile input?

Every entry point is bounded by default; ReaderConfig::unbounded() opts out for trusted input. Error text escapes control and bidirectional characters. The crate denies unsafe and is property- and fuzz-tested. See the threat model.

Can the writer produce a broken interchange?

It computes UNT and UNZ from what it wrote and validates the typed UNB header. A message dropped without finish() gets no UNT; after a failed write the writer is poisoned (E072). See Writing.

Does it ship UN/EDIFACT directories?

No. The UNTDID licence forbids distributing modified copies of the Directory without UNECE's permission. The crate ships the validation engine, the table types and the ISO 9735 service segments; supply your directory definitions at compile time or load them at startup. See Validation.

Start reading

All guides