pub(super) struct ReaderState {
pub offset: u64,
pub last_error_offset: u64,
pub state: ParseState,
pub config: Config,
opened_buffer: Vec<u8>,
opened_starts: Vec<usize>,
}Expand description
A struct that holds a current reader state and a parser configuration.
It is independent on a way of reading data: the reader feed data into it and
get back produced Events.
Fields§
§offset: u64Number of bytes read from the source of data since the reader was created
last_error_offset: u64A snapshot of an offset of the last error returned. It can be less than
offset, because some errors conveniently report at earlier position,
and changing offset is not possible, because Error::IllFormed errors
are recoverable.
state: ParseStateDefines how to process next byte
config: ConfigUser-defined settings that affect parsing
opened_buffer: Vec<u8>All currently Started elements which didn’t have a matching End element yet.
For an XML
<root><one/><inner attr="value">|<tag></inner></root>when cursor at the | position buffer contains:
rootinner
^ ^The ^ symbols shows which positions stored in the Self::opened_starts
(0 and 4 in that case).
opened_starts: Vec<usize>Opened name start indexes into Self::opened_buffer. See documentation
for that field for details
Implementations§
Source§impl ReaderState
impl ReaderState
Sourcepub fn emit_text<'b>(&mut self, bytes: &'b [u8]) -> BytesText<'b>
pub fn emit_text<'b>(&mut self, bytes: &'b [u8]) -> BytesText<'b>
Trims end whitespaces from bytes, if required, and returns a text event.
§Parameters
bytes: data from the start of stream to the first<or from>to<
Sourcepub fn emit_bang<'b>(
&mut self,
bang_type: BangType,
buf: &'b [u8],
) -> Result<Event<'b>>
pub fn emit_bang<'b>( &mut self, bang_type: BangType, buf: &'b [u8], ) -> Result<Event<'b>>
Returns Comment, CData or DocType event.
buf contains data between < and >:
- CDATA:
![CDATA[...]] - Comment:
!--...-- - Doctype (uppercase):
!D... - Doctype (lowercase):
!d...
Sourcepub fn emit_end<'b>(&mut self, buf: &'b [u8]) -> Result<Event<'b>>
pub fn emit_end<'b>(&mut self, buf: &'b [u8]) -> Result<Event<'b>>
Wraps content of buf into the Event::End event. Does the check that
end name matches the last opened start name if self.config.check_end_names is set.
buf contains data between < and >, for example /tag.
Sourcepub fn emit_question_mark<'b>(&mut self, buf: &'b [u8]) -> Result<Event<'b>>
pub fn emit_question_mark<'b>(&mut self, buf: &'b [u8]) -> Result<Event<'b>>
buf contains data between < and > and the first byte is ?.
self.offset already after the >
Returns Decl or PI event
Sourcepub fn emit_start<'b>(&mut self, content: &'b [u8]) -> Event<'b>
pub fn emit_start<'b>(&mut self, content: &'b [u8]) -> Event<'b>
Converts content of a tag to a Start or an Empty event
§Parameters
content: Content of a tag between<and>
pub fn close_expanded_empty(&mut self) -> BytesEnd<'static>
Sourcepub const fn decoder(&self) -> Decoder
pub const fn decoder(&self) -> Decoder
Get the decoder, used to decode bytes, read by this reader, to the strings.
If encoding feature is enabled, the used encoding may change after
parsing the XML declaration, otherwise encoding is fixed to UTF-8.
If encoding feature is enabled and no encoding is specified in declaration,
defaults to UTF-8.
Trait Implementations§
Source§impl Clone for ReaderState
impl Clone for ReaderState
Source§fn clone(&self) -> ReaderState
fn clone(&self) -> ReaderState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more