pub struct Parser<'a> { /* private fields */ }Expand description
Implementations§
Source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
Sourcepub fn from_reader<R: BufRead + 'a>(reader: R) -> Self
pub fn from_reader<R: BufRead + 'a>(reader: R) -> Self
Creates a parser that reads its input from any BufRead.
from cannot be used for readers because of Rust coherence
(From<&str> and a blanket From<R: BufRead> cannot coexist).
Sourcepub fn options(self, options: ParserOptions) -> Self
pub fn options(self, options: ParserOptions) -> Self
Sets the parser options (buffer size, memory limits, libxml-compat, …).
Sourcepub fn parse(self) -> Result<XmlDocument>
pub fn parse(self) -> Result<XmlDocument>
Parses the input into a DOM XmlDocument.
Sourcepub fn events(self) -> Result<Vec<XmlEvent>>
pub fn events(self) -> Result<Vec<XmlEvent>>
Parses the input and returns all XML events as a buffered Vec.
This collects the full event stream into memory. For push-based
streaming without buffering, use for_each_event.
Sourcepub fn for_each_event<F>(self, on_event: F) -> Result<()>
pub fn for_each_event<F>(self, on_event: F) -> Result<()>
Streams the input, invoking on_event for every event as it is read,
with constant memory (nothing is buffered).
The callback is borrowed for the duration of the call, so it may capture
and mutate local state. Return Err(..) to stop early.
ⓘ
let mut elements = 0;
Parser::from_reader(file).for_each_event(|event| {
if matches!(event, XmlEvent::StartElement { .. }) {
elements += 1;
}
Ok(())
})?;Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Parser<'a>
impl<'a> !Send for Parser<'a>
impl<'a> !Sync for Parser<'a>
impl<'a> !UnwindSafe for Parser<'a>
impl<'a> Freeze for Parser<'a>
impl<'a> Unpin for Parser<'a>
impl<'a> UnsafeUnpin for Parser<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more