Skip to main content

StreamParser

Struct StreamParser 

Source
pub struct StreamParser<'src> { /* private fields */ }
Expand description

Pull-based streaming parser that yields arena-allocated subtrees.

Implementations§

Source§

impl<'src> StreamParser<'src>

Source

pub fn from_str(input: &'src str) -> StreamParser<'src>

Source

pub fn from_bytes(input: &'src [u8]) -> Result<StreamParser<'src>, XmlError>

Source

pub fn with_options(self, opts: &ParseOptions) -> StreamParser<'src>

Replace ParseOptions on the underlying reader. Takes a reference (the reader internally clones once — amortized over the whole stream).

Source

pub fn emit_at_depth(self, depth: u32) -> StreamParser<'src>

Emit elements at the given depth. depth = 1 matches direct children of the root. Memory-bounded.

Source

pub fn emit_at_path(self, path: &[&str]) -> StreamParser<'src>

Emit elements whose ancestor chain (from root) matches path exactly. path[0] is the root’s name, path[1] its child, …, path[N-1] the element to emit. Memory-bounded.

Source

pub fn emit_when<F>(self, predicate: F) -> StreamParser<'src>
where F: Fn(&[String]) -> bool + Send + Sync + 'static,

Emit elements whose ancestor chain satisfies predicate. The predicate receives a slice of QNames from root to the just-opened element (inclusive at the end); return true to emit that element’s subtree.

More flexible than emit_at_path / emit_at_depth: handy when the emission criterion is “any <item> regardless of where it appears in the tree” or “any element under <rss> that is itself named entry”.

Memory profile matches the fixed-depth modes — elements above the matching boundary cost only the ancestor stack.

§Example
use sup_xml_core::StreamParser;
let xml = r#"<root>
  <section><item>a</item></section>
  <other><item>b</item></other>
</root>"#;
let mut sp = StreamParser::from_str(xml)
    .emit_when(|chain| chain.last().map(String::as_str) == Some("item"));
while sp.next().unwrap().is_some() {}
Source

pub fn next(&mut self) -> Result<Option<Document>, XmlError>

Pull the next emitted subtree. Returns Ok(Some(doc)) for each match, Ok(None) on EOF, Err(_) on parse error.

Auto Trait Implementations§

§

impl<'src> !Freeze for StreamParser<'src>

§

impl<'src> !RefUnwindSafe for StreamParser<'src>

§

impl<'src> !Send for StreamParser<'src>

§

impl<'src> !Sync for StreamParser<'src>

§

impl<'src> !UnwindSafe for StreamParser<'src>

§

impl<'src> Unpin for StreamParser<'src>

§

impl<'src> UnsafeUnpin for StreamParser<'src>

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> 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<T> Same for T

Source§

type Output = T

Should always be Self
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.