Skip to main content

Reader

Struct Reader 

Source
pub struct Reader<'a> { /* private fields */ }
Expand description

A streaming parser of an XML 1.0 document with namespaces, read from a string.

Reader::next_event returns the events one by one; the reader keeps only the open elements, the namespace declarations in scope and the attributes of the current start tag. Names, and text without references or carriage returns, are slices of the input. A document is well-formed when every event up to the final None is read without error; events read before an error belong to a document that is not.

Implementations§

Source§

impl<'a> Reader<'a>

Source

pub fn new(text: &'a str) -> Self

A reader of text with the default Limits. A byte order mark at the start is skipped.

Source

pub fn with_limits(text: &'a str, limits: Limits) -> Self

A reader of text with the given limits.

Source

pub const fn text(&self) -> &'a str

The text being read.

Source

pub const fn offset(&self) -> usize

The byte offset reached.

Source

pub fn depth(&self) -> usize

The number of open elements: after a Event::Start, its element included; after an Event::End, its element still included.

Source

pub fn text_pos(&self, offset: usize) -> TextPos

The position of a byte offset of the text (see TextPos::at).

Source

pub fn lookup_namespace(&self, prefix: &str) -> Option<&str>

The namespace bound to prefix ("" for the default namespace) in the scope of the innermost open element (the element of the last Event::Start or Event::End included): None if there is none or if the default namespace is undeclared. xml is always bound to XML_NAMESPACE and xmlns to XMLNS_NAMESPACE.

Source

pub fn next_event(&mut self) -> Result<Option<Event<'_, 'a>>, Error>

The next event, Ok(None) at the end of a well-formed document. After an error, the same error again.

§Errors

The first well-formedness error from where the reader is (see Error).

Source

pub fn read_to_end(&mut self) -> Result<(), Error>

Reads to the end of the document.

§Errors

The first well-formedness error from where the reader is.

Trait Implementations§

Source§

impl<'a> Debug for Reader<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Forget for Reader<'a>

§

impl<'a> Freeze for Reader<'a>

§

impl<'a> RefUnwindSafe for Reader<'a>

§

impl<'a> Send for Reader<'a>

§

impl<'a> Sync for Reader<'a>

§

impl<'a> Unpin for Reader<'a>

§

impl<'a> UnsafeUnpin for Reader<'a>

§

impl<'a> UnwindSafe for Reader<'a>

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.