quick_xml::reader

Trait XmlSource

source
trait XmlSource<'r, B> {
    // Required methods
    fn remove_utf8_bom(&mut self) -> Result<()>;
    fn read_text(&mut self, buf: B, position: &mut u64) -> ReadTextResult<'r, B>;
    fn read_with<P>(
        &mut self,
        parser: P,
        buf: B,
        position: &mut u64,
    ) -> Result<&'r [u8]>
       where P: Parser;
    fn read_bang_element(
        &mut self,
        buf: B,
        position: &mut u64,
    ) -> Result<(BangType, &'r [u8])>;
    fn skip_whitespace(&mut self, position: &mut u64) -> Result<()>;
    fn peek_one(&mut self) -> Result<Option<u8>>;
}
Expand description

Represents an input for a reader that can return borrowed data.

There are two implementors of this trait: generic one that read data from Self, copies some part of it into a provided buffer of type B and then returns data that borrow from that buffer.

The other implementor is for &[u8] and instead of copying data returns borrowed data from Self instead. This implementation allows zero-copy deserialization.

§Parameters

  • 'r: lifetime of a buffer from which events will borrow
  • B: a type of a buffer that can be used to store data read from Self and from which events can borrow

Required Methods§

source

fn remove_utf8_bom(&mut self) -> Result<()>

Removes UTF-8 BOM if it is present

source

fn read_text(&mut self, buf: B, position: &mut u64) -> ReadTextResult<'r, B>

Read input until start of markup (the <) is found or end of input is reached.

§Parameters
  • buf: Buffer that could be filled from an input (Self) and from which events could borrow their data
  • position: Will be increased by amount of bytes consumed
source

fn read_with<P>( &mut self, parser: P, buf: B, position: &mut u64, ) -> Result<&'r [u8]>
where P: Parser,

Read input until processing instruction is finished.

This method expect that start sequence of a parser already was read.

Returns a slice of data read up to the end of the thing being parsed. The end of thing and the returned content is determined by the used parser.

If input (Self) is exhausted and no bytes was read, or if the specified parser could not find the ending sequence of the thing, returns SyntaxError.

§Parameters
  • buf: Buffer that could be filled from an input (Self) and from which events could borrow their data
  • position: Will be increased by amount of bytes consumed

A P type parameter is used to preserve state between calls to the underlying reader which provides bytes fed into the parser.

source

fn read_bang_element( &mut self, buf: B, position: &mut u64, ) -> Result<(BangType, &'r [u8])>

Read input until comment or CDATA is finished.

This method expect that < already was read.

Returns a slice of data read up to end of comment or CDATA (>), which does not include into result.

If input (Self) is exhausted and nothing was read, returns None.

§Parameters
  • buf: Buffer that could be filled from an input (Self) and from which events could borrow their data
  • position: Will be increased by amount of bytes consumed
source

fn skip_whitespace(&mut self, position: &mut u64) -> Result<()>

Consume and discard all the whitespace until the next non-whitespace character or EOF.

§Parameters
  • position: Will be increased by amount of bytes consumed
source

fn peek_one(&mut self) -> Result<Option<u8>>

Return one character without consuming it, so that future read_* calls will still include it. On EOF, return None.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a> XmlSource<'a, ()> for &'a [u8]

Implementation of XmlSource for &[u8] reader using a Self as buffer that will be borrowed by events. This implementation provides a zero-copy deserialization

source§

fn remove_utf8_bom(&mut self) -> Result<()>

source§

fn read_text(&mut self, _buf: (), position: &mut u64) -> ReadTextResult<'a, ()>

source§

fn read_with<P>( &mut self, parser: P, _buf: (), position: &mut u64, ) -> Result<&'a [u8]>
where P: Parser,

source§

fn read_bang_element( &mut self, _buf: (), position: &mut u64, ) -> Result<(BangType, &'a [u8])>

source§

fn skip_whitespace(&mut self, position: &mut u64) -> Result<()>

source§

fn peek_one(&mut self) -> Result<Option<u8>>

Implementors§

source§

impl<'b, R: BufRead> XmlSource<'b, &'b mut Vec<u8>> for R

Implementation of XmlSource for any BufRead reader using a user-given Vec<u8> as buffer that will be borrowed by events.