Reference
API surface
The complete public API in one page. Rendered rustdoc with full signatures is at docs.rs/er7.
Entry points
| Item | Signature | Notes |
|---|---|---|
er7::parse | fn(&str) -> Result<Message, Error> | needs an MSH/FHS/BHS header |
er7::parse_with | fn(&str, Separators) -> Message | headerless fragment; cannot fail |
er7::split_messages | fn(&str) -> Vec<&str> | batch input; slices borrow |
er7::parse names both a module and a function. That is legal — they live in
different namespaces — so er7::parse(text) calls the function and er7::parse::split_messages resolves the module path.
The value tree
Six types, one per level of the ER7 hierarchy. All fields are pub, so a message
can be built from literals as well as parsed. All derive Debug, Clone, PartialEq, Eq; the four below Segment also derive Default.
Message { separators: Separators, segments: Vec<Segment> }
Segment { name: String, fields: Vec<Field> }
Field { repetitions: Vec<Repetition> }
Repetition { components: Vec<Component> }
Component { subcomponents: Vec<Subcomponent> }
Subcomponent { raw: String } Only Subcomponent holds text, in raw, exactly as sent. Decoding
happens on demand — that single decision is what makes the byte-for-byte round trip possible.
Message
| Method | Returns | Purpose |
|---|---|---|
segment(&str) | Option<&Segment> | the first segment with that name |
segment_at(&str, usize) | Option<&Segment> | the 1-based Nth of that name |
segment_at_mut(&str, usize) | Option<&mut Segment> | the same, mutable |
segments_named(&str) | impl Iterator | every segment with that name |
header() | Option<&Segment> | the segment that declared the delimiters |
query(&str) | Result<Option<String>, Error> | first match at a path, decoded |
query_all(&str) | Result<Vec<String>, Error> | every match, decoded |
query_path(&Path) | Vec<String> | every match, path pre-parsed |
query_path_raw(&Path) | Vec<String> | every match, exactly as sent |
message_code() | Option<String> | MSH-9.1 |
trigger_event() | Option<String> | MSH-9.2 |
message_structure() | Option<String> | MSH-9.3 |
control_id() | Option<String> | MSH-10 |
version() | Option<String> | MSH-12.1 |
to_er7() | String | write with default options |
to_er7_with(RenderOptions) | String | write, choosing the terminator |
Also impl Display for Message, equivalent to to_er7().
Levels below Message
Every level exposes 1-based accessors matching HL7’s own numbering, each returning Option, plus a _mut variant. Index 0 returns None rather than element 1.
- Segment
field(n),field_mut(n),component(field, component),is_header(),to_er7(&seps),to_text(&seps)- Field
repetition(n),repetition_mut(n),component(n),is_empty(),is_null(),to_er7,to_text- Repetition
component(n),component_mut(n),is_empty(),is_null(),to_er7,to_text- Component
subcomponent(n),subcomponent_mut(n),is_empty(),is_null(),to_er7,to_text- Subcomponent
new(text),value(&seps),set(value, &seps),is_empty(),is_null(),to_er7,to_text
to_text decodes leaf text but keeps the structural delimiters, so its output is not re-parseable: a decoded \F\ becomes a literal |.
Use to_er7 for anything that will be sent, stored, or parsed again.
Configuration
- Separators
- Fields
field,component,repetition,escape,subcomponent:char;truncation:Option<char>. Methodsdefault(),from_header(&str),validate(),is_delimiter(char),encoding_characters(). DerivesCopy. - Terminator
Cr(default),Lf,CrLf. Methodas_str().- RenderOptions
terminator: Terminator,trailing_terminator: bool. DerivesDefault(Cr,false).- Path
segment: String;segment_occurrence,field,repetition,component,subcomponent:Option<usize>. ImplementsFromStr,Display,Hash.
Escape sequences
Module er7::escape.
| Item | Signature |
|---|---|
escapes | fn(&str, &Separators) -> Escapes |
unescape | fn(&str, &Separators) -> Cow<str> |
escape | fn(&str, &Separators) -> Cow<str> |
decode_hex | fn(&str) -> Option<String> |
Escape variants: Text, Field, Component, Subcomponent, Repetition, EscapeCharacter, Hex, Highlight, Normal, Formatting, Local, SingleByteCharacterSet, MultiByteCharacterSet, Unknown, Unterminated.
Errors
Four variants, arising from exactly two situations: a message with no usable header, and a path that is not a path.
| Variant | When |
|---|---|
Empty | the input held no non-blank lines |
MissingHeader(String) | the first segment is not MSH, FHS, or BHS; carries the name found |
BadHeader(String) | the declared delimiters are unusable |
BadPath(String) | a path could not be read |
Everything else about ER7 is recovered rather than refused: unknown segments, local Z segments, ragged field counts, undecodable escapes, and missing positions are all data.
Not in the API
No dictionary, no validator, no transport, no dependencies. See the ecosystem for the crates that add the HL7 v2.5 dictionary on top.