Struct xml5ever::buffer_queue::BufferQueue

source ·
pub struct BufferQueue {
    buffers: RefCell<VecDeque<Tendril<UTF8>>>,
}
Expand description

A queue of owned string buffers, which supports incrementally consuming characters.

Internally it uses VecDeque and has the same complexity properties.

Fields§

§buffers: RefCell<VecDeque<Tendril<UTF8>>>

Implementations§

source§

impl BufferQueue

source

pub fn is_empty(&self) -> bool

Returns whether the queue is empty.

source

pub fn pop_front(&self) -> Option<Tendril<UTF8>>

Get the buffer at the beginning of the queue.

source

pub fn push_front(&self, buf: Tendril<UTF8>)

Add a buffer to the beginning of the queue.

If the buffer is empty, it will be skipped.

source

pub fn push_back(&self, buf: Tendril<UTF8>)

Add a buffer to the end of the queue.

If the buffer is empty, it will be skipped.

source

pub fn peek(&self) -> Option<char>

Look at the next available character without removing it, if the queue is not empty.

source

pub fn pop_except_from(&self, set: SmallCharSet) -> Option<SetResult>

Pops and returns either a single character from the given set, or a buffer of characters none of which are in the set.

§Examples
use markup5ever::buffer_queue::{BufferQueue, SetResult};

let mut queue = BufferQueue::default();
queue.push_back(format_tendril!(r#"<some_tag attr="text">SomeText</some_tag>"#));
let set = small_char_set!(b'<' b'>' b' ' b'=' b'"' b'/');
let tag = format_tendril!("some_tag");
let attr = format_tendril!("attr");
let attr_val = format_tendril!("text");
assert_eq!(queue.pop_except_from(set), Some(SetResult::FromSet('<')));
assert_eq!(queue.pop_except_from(set), Some(SetResult::NotFromSet(tag)));
assert_eq!(queue.pop_except_from(set), Some(SetResult::FromSet(' ')));
assert_eq!(queue.pop_except_from(set), Some(SetResult::NotFromSet(attr)));
assert_eq!(queue.pop_except_from(set), Some(SetResult::FromSet('=')));
assert_eq!(queue.pop_except_from(set), Some(SetResult::FromSet('"')));
assert_eq!(queue.pop_except_from(set), Some(SetResult::NotFromSet(attr_val)));
// ...
source

pub fn eat<F>(&self, pat: &str, eq: F) -> Option<bool>
where F: Fn(&u8, &u8) -> bool,

Consume bytes matching the pattern, using a custom comparison function eq.

Returns Some(true) if there is a match, Some(false) if there is no match, or None if it wasn’t possible to know (more data is needed).

The custom comparison function is used elsewhere to compare ascii-case-insensitively.

§Examples
use markup5ever::buffer_queue::BufferQueue;

let mut queue = BufferQueue::default();
queue.push_back(format_tendril!("testtext"));
let test_str = "test";
assert_eq!(queue.eat("test", |&a, &b| a == b), Some(true));
assert_eq!(queue.eat("text", |&a, &b| a == b), Some(true));
assert!(queue.is_empty());
source

pub fn next(&self) -> Option<char>

Get the next character if one is available, removing it from the queue.

This function manages the buffers, removing them as they become empty.

source

pub fn replace_with(&self, other: BufferQueue)

source

pub fn swap_with(&self, other: &BufferQueue)

Trait Implementations§

source§

impl Debug for BufferQueue

source§

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

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

impl Default for BufferQueue

source§

fn default() -> BufferQueue

Create an empty BufferQueue.

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

§

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

§

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.