[][src]Struct xmlparser::ByteStream

pub struct ByteStream<'a> { /* fields omitted */ }

A streaming text parsing interface.

Methods

impl<'a> ByteStream<'a>[src]

pub fn span(&self) -> StrSpan<'a>[src]

Returns an underling string span.

pub fn pos(&self) -> usize[src]

Returns current position.

pub fn jump_to_end(&mut self)[src]

Sets current position equal to the end.

Used to indicate end of parsing on error.

pub fn at_end(&self) -> bool[src]

Checks if the stream is reached the end.

Any pos() value larger than original text length indicates stream end.

Accessing stream after reaching end via safe methods will produce an UnexpectedEndOfStream error.

Accessing stream after reaching end via *_unchecked methods will produce a Rust's bound checking error.

pub fn curr_byte(&self) -> Result<u8, StreamError>[src]

Returns a byte from a current stream position.

Errors

  • UnexpectedEndOfStream

pub fn curr_byte_unchecked(&self) -> u8[src]

Returns a byte from a current stream position.

Panics

  • if the current position is after the end of the data

pub fn next_byte(&self) -> Result<u8, StreamError>[src]

Returns a next byte from a current stream position.

Errors

  • UnexpectedEndOfStream

pub fn advance(&mut self, n: usize)[src]

Advances by n bytes.

Examples

use xmlparser::Stream;

let mut s = Stream::from("text");
s.advance(2); // ok
s.advance(20); // will cause a panic via debug_assert!().

pub fn starts_with(&self, text: &[u8]) -> bool[src]

Checks that the stream starts with a selected text.

We are using &[u8] instead of &str for performance reasons.

Examples

use xmlparser::Stream;

let mut s = Stream::from("Some text.");
s.advance(5);
assert_eq!(s.starts_with(b"text"), true);
assert_eq!(s.starts_with(b"long"), false);

pub fn consume_byte(&mut self, c: u8) -> Result<(), StreamError>[src]

Consumes the current byte if it's equal to the provided byte.

Errors

  • InvalidChar
  • UnexpectedEndOfStream

Examples

use xmlparser::Stream;

let mut s = Stream::from("Some text.");
assert!(s.consume_byte(b'S').is_ok());
assert!(s.consume_byte(b'o').is_ok());
assert!(s.consume_byte(b'm').is_ok());
assert!(s.consume_byte(b'q').is_err());

pub fn try_consume_byte(&mut self, c: u8) -> bool[src]

Tries to consume the current byte if it's equal to the provided byte.

Unlike consume_byte() will not return any errors.

pub fn skip_string(&mut self, text: &[u8]) -> Result<(), StreamError>[src]

Skips selected string.

Errors

  • InvalidString

pub fn consume_bytes<F>(&mut self, f: F) -> StrSpan<'a> where
    F: Fn(&ByteStream, u8) -> bool
[src]

Consumes bytes by the predicate and returns them.

The result can be empty.

pub fn skip_bytes<F>(&mut self, f: F) where
    F: Fn(&ByteStream, u8) -> bool
[src]

Skips bytes by the predicate.

pub fn consume_chars<F>(&mut self, f: F) -> StrSpan<'a> where
    F: Fn(&ByteStream, char) -> bool
[src]

Consumes chars by the predicate and returns them.

The result can be empty.

pub fn skip_chars<F>(&mut self, f: F) where
    F: Fn(&ByteStream, char) -> bool
[src]

Skips chars by the predicate.

pub fn slice_back(&self, pos: usize) -> StrSpan<'a>[src]

Slices data from pos to the current position.

pub fn slice_tail(&self) -> StrSpan<'a>[src]

Slices data from the current position to the end.

pub fn gen_text_pos(&self) -> TextPos[src]

Calculates a current absolute position.

This operation is very expensive. Use only for errors.

pub fn gen_text_pos_from(&self, pos: usize) -> TextPos[src]

Calculates an absolute position at pos.

This operation is very expensive. Use only for errors.

Examples

let s = xmlparser::Stream::from("text");

assert_eq!(s.gen_text_pos_from(2), xmlparser::TextPos::new(1, 3));
assert_eq!(s.gen_text_pos_from(9999), xmlparser::TextPos::new(1, 5));

Trait Implementations

impl<'a> PartialEq<ByteStream<'a>> for ByteStream<'a>[src]

impl<'a> Clone for ByteStream<'a>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<'a> From<ByteStream<'a>> for Stream<'a>[src]

impl<'a> Copy for ByteStream<'a>[src]

impl<'a> Debug for ByteStream<'a>[src]

Auto Trait Implementations

impl<'a> Send for ByteStream<'a>

impl<'a> Sync for ByteStream<'a>

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.