quick_xml::reader::state

Struct ReaderState

source
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: 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

source

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 <
source

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

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.

source

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

source

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 >
source

pub fn close_expanded_empty(&mut self) -> BytesEnd<'static>

source

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

source§

fn clone(&self) -> ReaderState

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ReaderState

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ReaderState

source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.