pub struct Segment<'m> {
pub name: &'m str,
pub fields: Vec<Field<'m>>,
pub range: Range<usize>,
/* private fields */
}
Expand description
A segment in an HL7 message. A segment is a collection of fields, separated by the field separator character. Each segment has a name, which is the first field in the segment. Segments are separated by the segment separator character.
Fields§
§name: &'m str
The name of the segment
fields: Vec<Field<'m>>
The fields of the segment
range: Range<usize>
The range of the segment in the original message
Implementations§
Source§impl<'m> Segment<'m>
impl<'m> Segment<'m>
Sourcepub fn fields(&self) -> impl Iterator<Item = &Field<'m>>
pub fn fields(&self) -> impl Iterator<Item = &Field<'m>>
An iterator over the fields of the segment
Sourcepub fn display(&'m self, separators: &'m Separators) -> SegmentDisplay<'m>
pub fn display(&'m self, separators: &'m Separators) -> SegmentDisplay<'m>
Display the segment value, using the separators to decode escape sequences
by default. Note: if you want to display the raw value without decoding escape
sequences, use the #
flag, e.g. format!("{:#}", segment.display(separators))
.
Repeats will be separated by the repeat separator character.
Fields will be separated by the field separator character.
Components will be separated by the component separator character.
Subcomponents will be separated by the subcomponent separator character.
Segments will be separated by the segment separator character.
Escape sequences will be decoded using the escape character.
Sourcepub fn raw_value(&self) -> &'m str
pub fn raw_value(&self) -> &'m str
Get the raw value of the segment. This is the value as it appears in the message, without any decoding of escape sequences, and including all fields and their separators.
§Examples
let segment = hl7_parser::parser::parse_segment("ZFO|foo|bar").unwrap();
assert_eq!(segment.name, "ZFO");
assert_eq!(segment.fields.len(), 2);
assert_eq!(segment.raw_value(), "ZFO|foo|bar");
Sourcepub fn field(&self, number: usize) -> Option<&Field<'m>>
pub fn field(&self, number: usize) -> Option<&Field<'m>>
Get a specific field of the segment by number. Fields are numbered starting at 1.
Returns None
if the field number is out of range.
§Examples
let segment = hl7_parser::parser::parse_segment("ZFO|foo|bar").unwrap();
assert_eq!(segment.field(1).unwrap().raw_value(), "foo");
assert_eq!(segment.field(2).unwrap().raw_value(), "bar");
assert_eq!(segment.field(3), None);