Struct Field

Source
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>

Source

pub fn repeats(&self) -> impl Iterator<Item = &Repeat<'m>>

An iterator over the repeats of the field

Source

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.

Source

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");
Source

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);
Source

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);
Source

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);
Source

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);

Trait Implementations§

Source§

impl<'m> Clone for Field<'m>

Source§

fn clone(&self) -> Field<'m>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'m> Debug for Field<'m>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'m> From<&'m Field<'m>> for FieldBuilder

Source§

fn from(field: &'m Field<'_>) -> Self

Converts to this type from the input type.
Source§

impl<'m> PartialEq for Field<'m>

Source§

fn eq(&self, other: &Field<'m>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'m> Serialize for Field<'m>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'m> Eq for Field<'m>

Source§

impl<'m> StructuralPartialEq for Field<'m>

Auto Trait Implementations§

§

impl<'m> Freeze for Field<'m>

§

impl<'m> RefUnwindSafe for Field<'m>

§

impl<'m> Send for Field<'m>

§

impl<'m> Sync for Field<'m>

§

impl<'m> Unpin for Field<'m>

§

impl<'m> UnwindSafe for Field<'m>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.