Skip to main content

Module iterparse

Module iterparse 

Source
Expand description

Streaming-iterator wrapper for the SAX reader.

The lower-level crate::XmlReader / crate::XmlBytesReader deliver events whose borrows tie back to the reader’s source buffer — that’s the right shape for zero-copy consumers, but it prevents the reader from implementing Iterator directly (each next() would borrow &mut self, so callers can hold at most one event at a time).

Iterparse addresses the common case where the caller wants an actual Iterator and is willing to pay one String allocation per event for owned names and text. Events arrive alongside the current ancestor path so handlers don’t need to maintain their own depth tracker.

§Quick example

use sup_xml_core::iterparse::{Iterparse, IterEvent};

let xml = b"<catalog><book id='1'/><book id='2'/></catalog>";
for ev in Iterparse::from_bytes(xml).unwrap() {
    let ev = ev.unwrap();
    if let IterEvent::EndElement { name, path, .. } = ev {
        if name == "book" { println!("done with {}", path); }
    }
}

For consumers that need byte-exact zero-copy events (every payload borrowed from the source buffer), reach for crate::XmlBytesReader directly.

Structs§

Iterparse
Owns an XmlReader plus the bookkeeping needed to produce owned iterator items: a path stack, per-frame sibling counters (so book[2] etc. show up in the path), and an attribute scratch buffer.

Enums§

IterEvent
One streamed event. Names, attribute values, and text content are owned Strings so the iterator can yield items independent of the reader’s source buffer lifetime.