EscapeSequence

Struct EscapeSequence 

Source
pub struct EscapeSequence { /* private fields */ }
Expand description

This struct provides the decoding functionality to parse escape sequences from the source string back to their original chars.

For more info see here or here

§Example:

let delims = Separators::default();
let decoder = EscapeSequence::new(delims);
let hl7_field_value = r#"Obstetrician \T\ Gynaecologist"#;
let decoded = decoder.decode(hl7_field_value);
assert_eq!(decoded, r#"Obstetrician & Gynaecologist"#);

§Details

This decoder will replace some, but not all of the standard HL7 escape sequences.

  • \E\,\F\, ’\R`, \S\, \T\ are all handled, and replaced with the Escape, Field, Repeat, Component and Sub-Component separator chars respectively
  • \X..\ hexidecimal erscape sequences are supported (2 hex digits per char)

The following sequences are NOT replaced by design and will be left in the string:

  • \H\ Indicates the start of highlighted text, this is a consuming application problem and will not be replaced.
  • \N\ Indicates the end of highlighted text and resumption of normal text. This is a consuming application problem and will not be replaced.
  • \Z...\ Custom application escape sequences, these are custom (as are most Z items in HL7) and will not be replaced.

Also, not all of the sequences that should be replaced are currently being handled, specifically: /// - \Cxxyy\, ’\Mxxyyzz\ arguably should be handled, but aren’t currently. There’s some suggestion that these are discouraged in lieu of html-escaped values

If there’s no possibility of escape sequences (because there’s no escape characters, typically backslashes) in the value, this function short circuits as early as possible and returns the original string slice for optimum performance.

Implementations§

Source§

impl<'a> EscapeSequence

Source

pub fn new(delims: Separators) -> EscapeSequence

Create a new struct ready for processing of escape sequences. Escape sequences in HL7 are dependent on the actual delimiters used for that message, and so we need a Separators instance to know what chars we’re working with.

Creating a new EscapeSequence does involve some non-trivial work in order to improve the performance of the decode() operations. It’s expected that instances of this struct will be cached per message, or per sending application if it will always use the same separators, or for the lifetime of the process if you’re only dealing with known (often default) separators.

Source

pub fn decode<S>(&self, input: S) -> Cow<'a, str>
where S: Into<Cow<'a, str>>,

This is where the magic happens. Call this to update any escape sequences in the given &str.

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