ISO 9735 · Rust

EDIFACT for Rust that refuses to guess.

Zero-copy parsing, streaming deserialization, typed derive macros, and composable validation — built so that malformed input produces an error, never a plausible-looking wrong value.

cargo add edifact-rs

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

Parse, address, validate

Borrow straight from the bytes

use edifact_rs::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-rs

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, each of those optionally split into components. It is used across supply chain, logistics, energy, healthcare, and banking. See Core Concepts.

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

Delimiters can be redefined per interchange by the UNA service string advice, any delimiter can appear inside a value when release-escaped, and syntax version 4 adds a repetition separator that changes an element's shape rather than its text. A naive split silently merges or truncates values in all three cases.

Is it safe against hostile input?

The crate forbids unsafe. Parsing is guarded by a per-segment size limit plus optional segment-count, message-count, and byte budgets, and the parser, writer, and validators are exercised by property and fuzz tests on every commit. See Parsing.

Does it ship UN/EDIFACT directories?

No — directory data is versioned, large, and licensed separately. The crate provides the validation engine and the table types; supply your own definitions at compile time or load them at startup. See Validation.

Start reading

All guides