Skip to main content

Reader

Struct Reader 

Source
pub struct Reader { /* private fields */ }
Expand description

Streaming XML syntax reader.

The reader borrows the caller’s buffer on each parse() call, processes as many bytes as possible, and returns the number of bytes consumed. Unconsumed bytes (if any) must be shifted to the front of the buffer by the caller before the next call.

Implementations§

Source§

impl Reader

Source

pub fn new() -> Self

Source

pub fn reset(&mut self)

Reset the reader to initial state for parsing a new document.

Source

pub fn parse_slice<V: Visitor>( &mut self, buf: &[u8], visitor: &mut V, ) -> Result<u64, ParseError<V::Error>>

Parse a complete, in-memory document in a single call.

This is a convenience wrapper around parse() for when the entire input is available in a single buffer. It calls parse() once with stream_offset = 0 and is_final = true.

Source

pub fn parse<V: Visitor>( &mut self, buf: &[u8], stream_offset: u64, is_final: bool, visitor: &mut V, ) -> Result<u64, ParseError<V::Error>>

Parse as much of buf as possible.

  • buf: the input bytes to parse
  • stream_offset: absolute byte offset of buf[0] in the overall stream
  • is_final: true if this is the last chunk (no more data coming)
  • visitor: receives fine-grained parsing events

Returns Ok(consumed) where consumed <= buf.len(), indicating how many bytes were fully processed. The caller must shift buf[consumed..] to the front of the buffer, read more data, and call parse() again.

When is_final is false and the buffer ends with an incomplete multi-byte UTF-8 sequence, the returned consumed count excludes the incomplete bytes so that characters() callbacks never split a multi-byte character across calls. Callers can therefore trust that std::str::from_utf8() on any &[u8] slice delivered to characters() will not fail due to a buffer boundary split - only due to genuinely invalid UTF-8 in the source data. If the trailing bytes are provably invalid UTF-8 (continuation bytes with no leading byte), parse() returns ErrorKind::InvalidUtf8.

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, 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.