Crates
hl7-3-derive
#[derive(FromElement)] for HL7 v3 struct mode
What it is
Maps struct fields to XML element attributes and children. Like its v2 cousin it arrives through a feature rather than a direct dependency — and unlike it, nothing here returns a `Result`: a missing attribute reads as that field’s `Default`, matching `hl7-3`’s own degrade-don’t-reject choice.
hl7-3 = { version = "0.1", features = ["derive"] }Keeping the macro in a crate of its own is what lets the default build of hl7-3 keep exactly one dependency: syn and quote are
compiled only for callers who ask for it.
Usage
use hl7_3::FromElement;
use hl7_3::rim::Act;
#[derive(FromElement, Default)]
struct Observation {
#[element("classCode")] class_code: String,
#[element("moodCode")] mood_code: String,
#[element(child = "note")] note: Option<String>,
#[element(nested = "component")] component: Act, // its own FromElement
#[element(raw)] raw: hl7_3::xml::Element, // the escape hatch
}
let element = hl7_3::xml::parse(xml)?;
let observation = Observation::from_element(&element);
assert_eq!(observation.class_code, "OBS");
// The one attribute no struct field models — same object, no second parse.
assert_eq!(observation.raw.attribute("negationInd"), Some("true"));The attributes
| Attribute | Reads |
|---|---|
#[element("classCode")] | The classCode attribute. |
#[element(child = "note")] | The note child's text. |
#[element(nested = "component")] | The component child, via the field type's own FromElement. |
#[element(raw)] | The whole element, as hl7_3::xml::Element. |
| none | Default::default() |
Field types
Field types convert through hl7_3::typed::FromElementValue: String, bool, and the integer and floating-point types, plus Option<T> of any of those.
There is no Vec<T> support yet — a repeating child needs element.children_named(...) by hand for now.
Two deliberate differences from the v2 macro
No Result anywhere
Unlike hl7-2-derive's #[derive(FromHl7)], a missing attribute or child is not an error — it reads as that
field's Default, the same degrade-don't-reject choice hl7-3's own rim types make. See that
crate's typed module documentation for why.
No #[derive(ToElement)]
hl7-3 has no XML-writing capability yet, so a write-direction macro would have
nothing real to generate.
This crate has no spec/index.md of its own; its behavior is documented in its README
and in hl7-3's typed module. A fuller walkthrough is in Struct mode and derive.
Related crates
hl7-3
HL7 v3: the RIM backbone, the data types, the message envelope
hl7-2-derive
#[derive(FromHl7)] and #[derive(ToHl7)] for struct mode