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 Event
s.
Fields§
§offset: u64
Number of bytes read from the source of data since the reader was created
last_error_offset: u64
A 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: ParseState
Defines how to process next byte
config: Config
User-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 moresource§impl Debug for ReaderState
impl Debug for ReaderState
Auto Trait Implementations§
impl Freeze for ReaderState
impl RefUnwindSafe for ReaderState
impl Send for ReaderState
impl Sync for ReaderState
impl Unpin for ReaderState
impl UnwindSafe for ReaderState
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)