Skip to main content

Separators

Struct Separators 

Source
pub struct Separators(pub Separators);
Expand description

A Serde-enabled er7::Separators.

This is the plainest wrapper in the crate: six named, scalar fields, no recursion — the same shape as the Point { x, y } example in serde’s own manual-implementation guide, just with six fields instead of two. Each char serializes through Serializer::serialize_char, which every common format maps to a one-character string.

Example:

use serde_er7::Separators;

let wrapped = Separators(er7::Separators::default());
let json = serde_json::to_string(&wrapped)?;
assert_eq!(
    json,
    r#"{"field":"|","component":"^","repetition":"~","escape":"\\","subcomponent":"&","truncation":null}"#
);

let back: Separators = serde_json::from_str(&json)?;
assert_eq!(back.0, er7::Separators::default());

Tuple Fields§

§0: Separators

Methods from Deref<Target = Separators>§

Source

pub fn validate(&self) -> Result<(), Error>

Check that this set can encode a message unambiguously: no delimiter may be alphanumeric, a carriage return, or a line feed, and no two delimiters may be the same character.

Separators::from_header applies this to every message it reads, because a message that reuses one character for two roles cannot be parsed back into the values the sender meant (R2, spec §3.3).

This is the crate’s only strictness. Everywhere else, odd input is data rather than an error (R6) — but an ambiguous delimiter set would produce confidently wrong values rather than merely ugly ones.

Example:

use er7::Separators;

assert!(Separators::default().validate().is_ok());

// Unusual is fine; ambiguous is not.
let unusual = Separators { field: '#', component: '*', repetition: '!',
                           escape: '?', subcomponent: '@', truncation: None };
assert!(unusual.validate().is_ok());

let repeated = Separators { component: '&', ..Separators::default() };
assert!(repeated.validate().is_err());

let alphanumeric = Separators { field: 'X', ..Separators::default() };
assert!(alphanumeric.validate().is_err());

let terminator = Separators { repetition: '\r', ..Separators::default() };
assert!(terminator.validate().is_err());
§Errors

Error::BadHeader naming the offending character, when a delimiter is alphanumeric, is a line ending, or is used for two roles at once (R2, spec §3.3).

Source

pub fn is_delimiter(&self, c: char) -> bool

True when c plays any structural role in this delimiter set.

The truncation character counts, because a message may not reuse it for another role — but note it is not escaped when it appears in a value, since it is structural only inside MSH-2 (spec §6.3).

Example:

use er7::Separators;

let separators = Separators::default();
assert!(separators.is_delimiter('|'));
assert!(separators.is_delimiter('&'));
assert!(!separators.is_delimiter('#'));
assert!(!separators.is_delimiter('A'));
Source

pub fn encoding_characters(&self) -> String

The encoding-characters string this set writes as MSH-2, e.g. ^~\&. Note this excludes the field separator, which is MSH-1.

Example:

use er7::Separators;

assert_eq!(Separators::default().encoding_characters(), r"^~\&");

let v27 = Separators { truncation: Some('#'), ..Separators::default() };
assert_eq!(v27.encoding_characters(), r"^~\&#");

Trait Implementations§

Source§

impl Clone for Separators

Source§

fn clone(&self) -> Separators

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 Copy for Separators

Source§

impl Debug for Separators

Source§

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

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

impl Default for Separators

Source§

fn default() -> Separators

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

impl Deref for Separators

Source§

type Target = Separators

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Separators

Dereferences the value.
Source§

impl DerefMut for Separators

Source§

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

Mutably dereferences the value.
Source§

impl<'de> Deserialize<'de> for Separators

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

Source§

impl From<Separators> for Separators

Source§

fn from(inner: Separators) -> Separators

Converts to this type from the input type.
Source§

impl From<Separators> for Separators

Source§

fn from(outer: Separators) -> Separators

Converts to this type from the input type.
Source§

impl PartialEq for Separators

Source§

fn eq(&self, other: &Separators) -> 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 Separators

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 StructuralPartialEq for Separators

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.