pub struct Component<'m> {
pub subcomponents: Vec<Subcomponent<'m>>,
pub range: Range<usize>,
/* private fields */
}
Expand description
A component is a part of a field, and is separated from other components by the component separator character. A component is composed of 0 or more subcomponents.
Fields§
§subcomponents: Vec<Subcomponent<'m>>
The subcomponents of the component
range: Range<usize>
The range of the component in the original message
Implementations§
Source§impl<'m> Component<'m>
impl<'m> Component<'m>
Sourcepub fn subcomponents(&self) -> impl Iterator<Item = &Subcomponent<'m>>
pub fn subcomponents(&self) -> impl Iterator<Item = &Subcomponent<'m>>
An iterator over the subcomponents of the component
Sourcepub fn display(&'m self, separators: &'m Separators) -> ComponentDisplay<'m>
pub fn display(&'m self, separators: &'m Separators) -> ComponentDisplay<'m>
Display the component 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!("{:#}", component.display(separators))
.
Components will be separated by the component separator character.
Sourcepub fn raw_value(&self) -> &'m str
pub fn raw_value(&self) -> &'m str
Get the raw value of the component. This is the value as it appears in the message, without any decoding of escape sequences, and including all subcomponents and their separators.
§Examples
let component = hl7_parser::parser::parse_component("foo&bar").unwrap();
assert_eq!(component.subcomponents.len(), 2);
assert_eq!(component.raw_value(), "foo&bar");
Sourcepub fn has_subcomponents(&self) -> bool
pub fn has_subcomponents(&self) -> bool
Returns true if the component has more than one subcomponent. Note that
if the component has only one subcomponent, the value of that subcomponent
is essentially the value of the component, so the value of the component
can be obtained using raw_value()
.
§Examples
let component = hl7_parser::parser::parse_component("foo&bar").unwrap();
assert_eq!(component.has_subcomponents(), true);
let component = hl7_parser::parser::parse_component("foo").unwrap();
assert_eq!(component.has_subcomponents(), false);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the component has no subcomponents, or if all subcomponents have empty values.
§Examples
let component = hl7_parser::parser::parse_component("foo&bar").unwrap();
assert_eq!(component.is_empty(), false);
let component = hl7_parser::parser::parse_component("foo").unwrap();
assert_eq!(component.is_empty(), false);
let component = hl7_parser::parser::parse_component("foo&").unwrap();
assert_eq!(component.is_empty(), false);
let component = hl7_parser::parser::parse_component("").unwrap();
assert_eq!(component.is_empty(), true);
let component = hl7_parser::parser::parse_component("&").unwrap();
assert_eq!(component.is_empty(), true);
Sourcepub fn subcomponent(&self, number: usize) -> Option<&Subcomponent<'m>>
pub fn subcomponent(&self, number: usize) -> Option<&Subcomponent<'m>>
Get a subcomponent by its number. Subcomponent numbers are 1-based.
Returns None
if the subcomponent number is out of range.
§Examples
let component = hl7_parser::parser::parse_component("foo&bar").unwrap();
assert_eq!(component.subcomponent(1).unwrap().value, "foo");
assert_eq!(component.subcomponent(2).unwrap().value, "bar");
assert_eq!(component.subcomponent(3), None);