pub enum Error {
Empty,
MissingHeader(String),
BadHeader(String),
BadPath(String),
}Expand description
What can go wrong.
Four variants, arising from exactly two situations: a message with no usable header, and a path that is not a path. Everything else about ER7 is recoverable, and this crate recovers rather than refusing, because a receiver that rejects a message it could have read is worse than one that reads it as written (spec §11, rules R6 and R23).
Example:
use er7::Error;
assert!(matches!(er7::parse(""), Err(Error::Empty)));
assert!(matches!(er7::parse("PID|1"), Err(Error::MissingHeader(_))));
assert!(matches!(er7::parse("MSH"), Err(Error::BadHeader(_))));
assert!(matches!("PID-0".parse::<er7::Path>(), Err(Error::BadPath(_))));
// Everything below the header parses, however odd it is.
assert!(er7::parse("MSH|^~\\&|LAB\rZZZ\rPID||||||||||").is_ok());Variants§
Empty
The input held no segments at all — it was empty, or held only blank lines.
MissingHeader(String)
The first segment is not MSH, FHS, or BHS, so the message
never declared its delimiters. Carries the segment name that was
found instead.
BadHeader(String)
The header segment declared a delimiter set that cannot be used: missing, alphanumeric, a line ending, or reusing one character for two roles (spec §3.3). Carries a sentence naming the problem.
BadPath(String)
A path such as PID-5.1 could not be read (spec §8.1). Carries the
path and the reason.
Trait Implementations§
impl Eq for Error
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()