pub struct Field<'m> {
pub repeats: Vec<Repeat<'m>>,
pub range: Range<usize>,
/* private fields */
}
Expand description
A field in an HL7 message. A field is a collection of repeats, separated by the repeat separator character. Fields are separated by the field separator character.
Fields§
§repeats: Vec<Repeat<'m>>
§range: Range<usize>
Implementations§
Source§impl<'m> Field<'m>
impl<'m> Field<'m>
Sourcepub fn repeats(&self) -> impl Iterator<Item = &Repeat<'m>>
pub fn repeats(&self) -> impl Iterator<Item = &Repeat<'m>>
An iterator over the repeats of the field
Sourcepub fn display(&'m self, separators: &'m Separators) -> FieldDisplay<'m>
pub fn display(&'m self, separators: &'m Separators) -> FieldDisplay<'m>
Display the field 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!("{:#}", field.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.
Sourcepub fn raw_value(&self) -> &'m str
pub fn raw_value(&self) -> &'m str
Get the raw value of the field. This is the value as it appears in the message, without any decoding of escape sequences, and including all repeats and their separators.
§Examples
let field = hl7_parser::parser::parse_field("foo~bar").unwrap();
assert_eq!(field.repeats.len(), 2);
assert_eq!(field.raw_value(), "foo~bar");
Sourcepub fn has_repeats(&self) -> bool
pub fn has_repeats(&self) -> bool
Returns true if the field has more than one repeat. Note that
if the field has only one repeat, the value of that repeat
is essentially the value of the field, so the value of the field
can be obtained using raw_value()
.
§Examples
let field = hl7_parser::parser::parse_field("foo~bar").unwrap();
assert_eq!(field.has_repeats(), true);
let field = hl7_parser::parser::parse_field("foo").unwrap();
assert_eq!(field.has_repeats(), false);
let field = hl7_parser::parser::parse_field("foo^bar").unwrap();
assert_eq!(field.has_repeats(), false);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the field has no repeats, or if all repeats have empty values.
§Examples
let field = hl7_parser::parser::parse_field("foo~bar").unwrap();
assert_eq!(field.is_empty(), false);
let field = hl7_parser::parser::parse_field("").unwrap();
assert_eq!(field.is_empty(), true);
let field = hl7_parser::parser::parse_field("~").unwrap();
assert_eq!(field.is_empty(), true);
Sourcepub fn repeat(&self, number: usize) -> Option<&Repeat<'m>>
pub fn repeat(&self, number: usize) -> Option<&Repeat<'m>>
Get the repeat at the specified 1-based index Returns None if the index is out of bounds
§Examples
let field = hl7_parser::parser::parse_field("foo~bar").unwrap();
assert_eq!(field.repeat(1).unwrap().raw_value(), "foo");
assert_eq!(field.repeat(2).unwrap().raw_value(), "bar");
assert_eq!(field.repeat(3), None);
Sourcepub fn component(&self, number: usize) -> Option<&Component<'m>>
pub fn component(&self, number: usize) -> Option<&Component<'m>>
Get the component at the specified 1-based index
Returns None if the index is out of bounds
If the field has multiple repeats, the component will be taken from the first repeat
only.
If the field has no repeats, this will return None.
If the field has one or more repeats, this is equivalent to calling
repeat(1).component(number)
.
This is a convenience method for the common case where a field has only one repeat.
§Examples
let field = hl7_parser::parser::parse_field("foo^bar~baz^qux").unwrap();
assert_eq!(field.component(1).unwrap().raw_value(), "foo");
assert_eq!(field.component(2).unwrap().raw_value(), "bar");
assert_eq!(field.component(3), None);