pub fn from_reader_decoded<R: Read>(reader: R) -> DecodingSegmentStream<R> ⓘExpand description
Parse a reader, decoding it from the repertoire the stream’s own UNB
declares — lazily.
decode_reader has to read far enough to find the UNB before it can
answer, so it returns a Result — and a ? on it turns a lazy pipeline
eager, forcing the caller to box the iterator or wrap the error in a
one-item chain. This does the sniff on the first next() instead, so the
signature stays a plain Iterator and a decode failure arrives as its first
item, exactly like a parse failure does.
§Example
let mut raw = b"UNB+UNOC:3+S+R+260101:0900+IC1'NAD+BY+M".to_vec();
raw.push(0xFC);
raw.extend_from_slice(b"ller'UNZ+0+IC1'");
// No `?` before the loop: the pipeline stays lazy.
let segments: Vec<_> = edifact_rs::from_reader_decoded(std::io::Cursor::new(raw))
.collect::<Result<Vec<_>, _>>()?;
assert_eq!(segments[1].element_str(1), Some("Müller"));