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: SeparatorsMethods from Deref<Target = Separators>§
Sourcepub fn validate(&self) -> Result<(), Error>
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).
Sourcepub fn is_delimiter(&self, c: char) -> bool
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'));Sourcepub fn encoding_characters(&self) -> String
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
impl Clone for Separators
Source§fn clone(&self) -> Separators
fn clone(&self) -> Separators
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more