Skip to main content

Component

Struct Component 

Source
pub struct Component(pub Component);
Expand description

A Serde-enabled er7::Component.

A component is nothing but its subcomponents in order (er7::Component::subcomponents), so it serializes as a plain array rather than as a one-field object: ACME&1.2.3&ISO becomes ["ACME", "1.2.3", "ISO"]. The same shape Subcomponent chose for itself, one level up.

Example:

use serde_er7::Component;

let message = er7::parse(r"MSH|^~\&|LAB|ACME&1.2.3&ISO")?;
let component = er7::Component {
    subcomponents: vec![
        er7::Subcomponent::new("ACME"),
        er7::Subcomponent::new("1.2.3"),
        er7::Subcomponent::new("ISO"),
    ],
};
let wrapped = Component(component);

assert_eq!(serde_json::to_string(&wrapped)?, r#"["ACME","1.2.3","ISO"]"#);
let back: Component = serde_json::from_str(r#"["ACME","1.2.3","ISO"]"#)?;
// Subcomponents join on `&`, one level below where components join on `^`.
assert_eq!(back.to_er7(&message.separators), "ACME&1.2.3&ISO");

Tuple Fields§

§0: Component

Methods from Deref<Target = Component>§

Source

pub fn subcomponent(&self, n: usize) -> Option<&Subcomponent>

The 1-based subcomponent n, if the message carried one.

Index 0 returns None rather than element 1: HL7 numbering starts at 1, so a 0 is a caller’s off-by-one and must not read as a valid position (spec §5.4).

Example:

let message = er7::parse("MSH|^~\\&|LAB\rPID|1||9^^^ACME&1.2.3&ISO")?;
let assigning = message.segment("PID").unwrap().component(3, 4).unwrap();

assert_eq!(assigning.subcomponent(1).unwrap().raw, "ACME");
assert_eq!(assigning.subcomponent(2).unwrap().raw, "1.2.3");
assert!(assigning.subcomponent(9).is_none());
assert!(assigning.subcomponent(0).is_none());

See also Component::subcomponent_mut to edit one.

Source

pub fn subcomponent_mut(&mut self, n: usize) -> Option<&mut Subcomponent>

Mutable access to the 1-based subcomponent n, for editing it with Subcomponent::set.

Source

pub fn is_empty(&self) -> bool

True when every subcomponent is empty. See Component::is_null for the distinction that matters.

Source

pub fn is_null(&self) -> bool

True when this component is exactly the explicit null "" — one subcomponent, and that subcomponent null.

Example:

let message = er7::parse("MSH|^~\\&|LAB\rPID|\"\"^X")?;
let repetition = message.segment("PID").unwrap()
    .field(1).unwrap().repetition(1).unwrap();

assert!(repetition.component(1).unwrap().is_null());
assert!(!repetition.component(2).unwrap().is_null());
Source

pub fn to_er7(&self, separators: &Separators) -> String

Write this component as ER7, exactly as a receiver would read it.

Escape sequences are left intact, so the result can be sent, stored, or parsed again. This is the form the round-trip guarantee applies to (R16).

Example:

let message = er7::parse(r"MSH|^~\&|LAB|Smith \T\ Jones^X")?;
let separators = &message.separators;
let field = message.segment("MSH").unwrap().field(4).unwrap();

assert_eq!(field.to_er7(separators), r"Smith \T\ Jones^X");
Source

pub fn to_text(&self, separators: &Separators) -> String

Write this component with its leaf text escape-decoded.

Structural delimiters remain, so the result shows the shape of the value as well as its content (R17). That also means the result is not re-parseable: a decoded \F\ becomes a literal field separator. Use this for display, logging, and database writes; use to_er7 for anything that goes back into a message.

Example:

let message = er7::parse(r"MSH|^~\&|LAB|Smith \T\ Jones^X")?;
let separators = &message.separators;
let field = message.segment("MSH").unwrap().field(4).unwrap();

// The escape decodes; the component separator stays.
assert_eq!(field.to_text(separators), "Smith & Jones^X");

Trait Implementations§

Source§

impl Clone for Component

Source§

fn clone(&self) -> Component

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Component

Source§

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

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

impl Default for Component

Source§

fn default() -> Component

Returns the “default value” for a type. Read more
Source§

impl Deref for Component

Source§

type Target = Component

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Component

Dereferences the value.
Source§

impl DerefMut for Component

Source§

fn deref_mut(&mut self) -> &mut Component

Mutably dereferences the value.
Source§

impl<'de> Deserialize<'de> for Component

Source§

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

Read an array of strings into subcomponents.

Source§

impl Eq for Component

Source§

impl From<Component> for Component

Source§

fn from(inner: Component) -> Component

Converts to this type from the input type.
Source§

impl From<Component> for Component

Source§

fn from(outer: Component) -> Component

Converts to this type from the input type.
Source§

impl PartialEq for Component

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Component

Source§

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

Write each subcomponent as one array element.

This clones every subcomponent to borrow it as a Subcomponent, which is the price of keeping one owning wrapper type per tree level instead of a second, borrowing family — a fair trade for an HL7 message, which is kilobytes, not gigabytes.

Source§

impl StructuralPartialEq for Component

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
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.