pub struct Repetition(pub Repetition);Expand description
A Serde-enabled er7::Repetition.
A repetition is nothing but its components in order
(er7::Repetition::components), so — like Component one level
down — it serializes as a plain array: SMITH^JOHN becomes
["SMITH", "JOHN"].
Example:
use serde_er7::Repetition;
let message = er7::parse(r"MSH|^~\&|LAB|SMITH^JOHN")?;
let repetition = message
.segment("MSH")
.unwrap()
.field(4)
.unwrap()
.repetition(1)
.unwrap()
.clone();
let json = serde_json::to_string(&Repetition(repetition))?;
let back: Repetition = serde_json::from_str(&json)?;
assert_eq!(back.to_er7(&message.separators), "SMITH^JOHN");Tuple Fields§
§0: RepetitionMethods from Deref<Target = Repetition>§
Sourcepub fn component(&self, n: usize) -> Option<&Component>
pub fn component(&self, n: usize) -> Option<&Component>
The 1-based component n, if the message carried one.
Example:
let message = er7::parse("MSH|^~\\&|LAB\rPID|1||9|4|SMITH^JOHN")?;
let name = message.segment("PID").unwrap()
.field(5).unwrap().repetition(1).unwrap();
assert_eq!(name.component(1).unwrap().to_er7(&message.separators), "SMITH");
assert_eq!(name.component(2).unwrap().to_er7(&message.separators), "JOHN");
assert!(name.component(3).is_none());Sourcepub fn component_mut(&mut self, n: usize) -> Option<&mut Component>
pub fn component_mut(&mut self, n: usize) -> Option<&mut Component>
Mutable access to the 1-based component n.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
True when every component is empty. See Repetition::is_null for
the distinction that matters.
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
True when this repetition is exactly the explicit null "" — one
component, and that component null.
Sourcepub fn to_er7(&self, separators: &Separators) -> String
pub fn to_er7(&self, separators: &Separators) -> String
Write this repetition 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");Sourcepub fn to_text(&self, separators: &Separators) -> String
pub fn to_text(&self, separators: &Separators) -> String
Write this repetition 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 Repetition
impl Clone for Repetition
Source§fn clone(&self) -> Repetition
fn clone(&self) -> Repetition
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Repetition
impl Debug for Repetition
Source§impl Default for Repetition
impl Default for Repetition
Source§fn default() -> Repetition
fn default() -> Repetition
Source§impl Deref for Repetition
impl Deref for Repetition
Source§type Target = Repetition
type Target = Repetition
Source§fn deref(&self) -> &Repetition
fn deref(&self) -> &Repetition
Source§impl DerefMut for Repetition
impl DerefMut for Repetition
Source§fn deref_mut(&mut self) -> &mut Repetition
fn deref_mut(&mut self) -> &mut Repetition
Source§impl<'de> Deserialize<'de> for Repetition
impl<'de> Deserialize<'de> for Repetition
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Read an array of components into components.
impl Eq for Repetition
Source§impl From<Repetition> for Repetition
impl From<Repetition> for Repetition
Source§fn from(inner: Repetition) -> Repetition
fn from(inner: Repetition) -> Repetition
Source§impl From<Repetition> for Repetition
impl From<Repetition> for Repetition
Source§fn from(outer: Repetition) -> Repetition
fn from(outer: Repetition) -> Repetition
Source§impl PartialEq for Repetition
impl PartialEq for Repetition
Source§impl Serialize for Repetition
impl Serialize for Repetition
Source§fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
Write each component as one array element. See Component::serialize
for the cost of the clone this involves.