pub struct Repeat<'m> {
pub components: Vec<Component<'m>>,
pub range: Range<usize>,
/* private fields */
}
Expand description
A repeat represents an item in a list of field values. Most fields have a single value, but some fields can have multiple values, called repeats. Each repeat is separated by the repetition separator character and is composed of 0 or more components.
Fields§
§components: Vec<Component<'m>>
The components of the repeat
range: Range<usize>
The range of the repeat in the original message
Implementations§
Source§impl<'m> Repeat<'m>
impl<'m> Repeat<'m>
Sourcepub fn components(&self) -> impl Iterator<Item = &Component<'m>>
pub fn components(&self) -> impl Iterator<Item = &Component<'m>>
An iterator over the components of the repeat
Sourcepub fn display(&'m self, separators: &'m Separators) -> RepeatDisplay<'m>
pub fn display(&'m self, separators: &'m Separators) -> RepeatDisplay<'m>
Display the repeat 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!("{:#}", repeat.display(separators))
.
Repeats will be separated by the repeat separator character.
Sourcepub fn raw_value(&self) -> &'m str
pub fn raw_value(&self) -> &'m str
Get the raw value of the repeat. This is the value as it appears in the message, without any decoding of escape sequences, and including all components and their separators.
§Examples
let repeat = hl7_parser::parser::parse_repeat("foo^bar").unwrap();
assert_eq!(repeat.components.len(), 2);
assert_eq!(repeat.raw_value(), "foo^bar");
Sourcepub fn has_components(&self) -> bool
pub fn has_components(&self) -> bool
Returns true if the repeat has more than one component. Note that
if the repeat has only one component, the value of that components
is essentially the value of the repeat, so the value of the repeat
can be obtained using raw_value()
.
§Examples
let repeat = hl7_parser::parser::parse_repeat("foo^bar").unwrap();
assert_eq!(repeat.has_components(), true);
let repeat = hl7_parser::parser::parse_repeat("foo").unwrap();
assert_eq!(repeat.has_components(), false);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the repeat has no components, or if all components have empty values.
§Examples
let repeat = hl7_parser::parser::parse_repeat("foo^bar").unwrap();
assert_eq!(repeat.is_empty(), false);
let repeat = hl7_parser::parser::parse_repeat("").unwrap();
assert_eq!(repeat.is_empty(), true);
let repeat = hl7_parser::parser::parse_repeat("^").unwrap();
assert_eq!(repeat.is_empty(), true);
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
§Examples
let repeat = hl7_parser::parser::parse_repeat("foo^bar").unwrap();
assert_eq!(repeat.component(1).unwrap().raw_value(), "foo");
assert_eq!(repeat.component(2).unwrap().raw_value(), "bar");
assert_eq!(repeat.component(3), None);