Struct hl7_parser::Segment

source ·
pub struct Segment {
    pub range: Range<usize>,
    pub fields: Vec<Field>,
}
Expand description

Represents an HL7v2 segment

Fields§

§range: Range<usize>

The range (in char indices) in the original message where the segment is located

§fields: Vec<Field>

The fields found within the component

Implementations§

source§

impl Segment

source

pub fn field(&self, field: NonZeroUsize) -> Option<&Field>

Access a field via the 1-based HL7 field index

Returns

A reference to the field

source

pub fn field_mut(&mut self, field: NonZeroUsize) -> Option<&mut Field>

Mutably access a field via the 1-based HL7 field indexing

Returns

A mutable reference to the field

source

pub fn source<'s>(&self, message_source: &'s str) -> &'s str

Given the source for the original message, extract the (raw) string for this segment

Arguments
  • message_source - A string slice representing the original message source that was parsed
Examples
let message = include_str!("../test_assets/sample_oru_r01_generic.hl7");
let message = ParsedMessage::parse(&message, true).expect("can parse message");

let segment = message.segment("PID").expect("can get PID segment");

assert_eq!(segment.source(message.source), "PID|1|12345|12345^^^MIE&1.2.840.114398.1.100&ISO^MR||MOUSE^MINNIE^S||19240101|F|||123 MOUSEHOLE LN^^FORT WAYNE^IN^46808|||||||||||||||||||");
source

pub fn field_at_cursor(&self, cursor: usize) -> Option<(NonZeroUsize, &Field)>

Locate a field at the cursor position

Arguments
  • cursor - The cursor location (0-based character index of the original message)
Returns

A tuple containing the HL7 field index (1-based) and a reference to the field. If the segment doesn’t contain the cursor, returns None

Trait Implementations§

source§

impl Clone for Segment

source§

fn clone(&self) -> Segment

Returns a copy 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 Debug for Segment

source§

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

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

impl<'de> Deserialize<'de> for Segment

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<Segment> for Segments

source§

fn from(value: Segment) -> Self

Converts to this type from the input type.
source§

impl<I: Into<usize>> Index<I> for &Segment

§

type Output = Field

The returned type after indexing.
source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl PartialEq for Segment

source§

fn eq(&self, other: &Segment) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Segment

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 Eq for Segment

source§

impl StructuralEq for Segment

source§

impl StructuralPartialEq for Segment

Auto Trait Implementations§

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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,

§

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

§

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

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,