Skip to main content

XmlByteStreamReader

Struct XmlByteStreamReader 

Source
pub struct XmlByteStreamReader<R>
where R: Read,
{ /* private fields */ }
Expand description

Streaming XML reader that pulls bytes from an io::Read source on demand.

Constructed via Self::new or Self::with_size_hint and then driven via Self::next_event (pull events one at a time) or Self::validate (drive to EOF for a well-formedness check).

Implementations§

Source§

impl<R> XmlByteStreamReader<R>
where R: Read,

Source

pub fn new( inner: R, buffer_size: usize, ) -> Result<XmlByteStreamReader<R>, XmlError>

Construct with no size hint (e.g. stdin). Starts with a 64 KiB buffer that grows as needed up to buffer_size.

Source

pub fn with_size_hint( inner: R, size_hint: Option<usize>, buffer_size: usize, ) -> Result<XmlByteStreamReader<R>, XmlError>

Construct with an optional size hint. When the input’s total size is known (file with stat-derived length), pass it — the wrapper pre-allocates exactly that much (capped by buffer_size), avoiding the per-growth memcpy cost. For stdin / pipes, pass None and the buffer grows incrementally from a 64 KiB seed.

Source

pub fn with_options(self, opts: ParseOptions) -> XmlByteStreamReader<R>

Override the inner reader’s ParseOptions. See XmlBytesReader::with_options for what’s tunable.

Note: opts.stream_owned_names is forced to true regardless of what the caller passes — the streaming wrapper requires owned element names to survive buffer compaction between events.

Source

pub fn xml_decl(&self) -> Option<&XmlDeclInfo>

XML declaration fields parsed from the prolog, if any. Returns None before the first event has been pulled.

Source

pub fn recovered_errors(&self) -> &[XmlError]

Non-fatal errors logged while ParseOptions::recovery_mode is enabled. Empty otherwise.

Source

pub fn next_event(&mut self) -> Result<BytesEvent<'_, '_>, XmlError>

Pull the next parse event, streaming more bytes from the source as needed.

The returned BytesEvent borrows the reader’s internal rolling buffer and is valid only until the next call to next_event (or any other &mut self method): its lifetime is tied to the &mut self borrow, so the borrow checker forbids pulling the next event while one is still held. Consume each event (copy out what you need) before requesting the next — the same zero-copy contract as XmlBytesReader::next.

Yields BytesEvent::Eof once the document is exhausted; a well-formedness violation surfaces as Err.

Source

pub fn validate(self) -> Result<(), XmlError>

Drive the parser to EOF. Returns Ok(()) if every event up through BytesEvent::Eof parses without error. This is the CLI’s lint workload — we don’t need the events themselves, just the well-formedness verdict.

Auto Trait Implementations§

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.