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
impl Reader
pub fn new() -> Self
Sourcepub fn parse_slice<V: Visitor>(
&mut self,
buf: &[u8],
visitor: &mut V,
) -> Result<u64, ParseError<V::Error>>
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.
Sourcepub fn parse<V: Visitor>(
&mut self,
buf: &[u8],
stream_offset: u64,
is_final: bool,
visitor: &mut V,
) -> Result<u64, ParseError<V::Error>>
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 parsestream_offset: absolute byte offset ofbuf[0]in the overall streamis_final:trueif 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.