[][src]Struct autumn::list::List

pub struct List<T>(_, _);

Persistent linked-list data structure

This list data structure is used as it reduces the number of duplicates maintained in the parser as it considers multiple potentially valid alternative parses.

It is used internally to maintain the set of errors produces for a particular parse as well as for parsers returning lists of values.

The list is actually implemented as a first-in last-out stack structure so items in a parser that produce a list will be the reverse of the order in which they were parsed.

Lists are also iterators over their elements. The iterator item of the list is an Rc of its elements.

let values = &[0, 1, 2, 3, 4, 5, 6, 7, 8];
let list_a = values[1..5].iter().fold(List::single(0), |list, value| list.push(*value));
let list_b = values[5..9].iter().fold(List::new(), |list, value| list.push(*value));
let joined = list_a.concat(&list_b);

for (list_value, array_value) in joined.reverse().zip(values.iter()) {
    assert_eq!(*list_value, *array_value);
}

Methods

impl<T> List<T>[src]

pub fn new() -> Self[src]

Create a new, empty list

pub fn single(value: T) -> Self[src]

Create a list with a single element

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

Get the number of items in the list

let list = List::single(1).push(2).push(3);
assert_eq!(list.length(), 3);

pub fn push(&self, value: T) -> Self[src]

Push an item onto the list

pub fn reverse(&self) -> Self[src]

Create the reversed copy of the list

let values = &[1, 2, 3, 4, 5, 6];
let list = values.iter().fold(List::new(), |list, value| list.push(*value));

for (list_value, array_value) in list.reverse().zip(values.iter()) {
    assert_eq!(*array_value, *list_value);
}

pub fn concat(&self, other: &Self) -> Self[src]

Concatenate two lists

let list = List::single(1).push(2).push(3).concat(&List::single(4).push(5).push(6));

pub fn drain(self) -> Drain<T>[src]

Drain all of the elements from a list in reverse order

Will produce an iterator over all of the elements in the list.

The iterator will panic if there are multiple references to the list or elements within the list.

pub fn iter(&self) -> Iter<T>[src]

Create an iterator over references to elements of the list

Trait Implementations

impl<T> Clone for List<T>[src]

impl<T> Concat for List<T>[src]

impl<T: Debug> Debug for List<T>[src]

impl<T> FromIterator<Rc<T>> for List<T>[src]

impl<T> FromIterator<T> for List<T>[src]

impl<T> Iterator for List<T>[src]

type Item = Rc<T>

The type of the elements being iterated over.

impl<T, E, P: Parser<T, E>> Parser<List<T>, E> for ListMap<P, E>[src]

impl<T, D, E, R, P, S> Parser<List<T>, E> for DelimitedBy<P, S, D, R, E> where
    T: Clone,
    R: RangeBounds<usize> + Clone,
    P: Parser<T, E>,
    S: Parser<D, E>, 
[src]

impl<T, D, E, R, P, S> Parser<List<T>, E> for StrictlyDelimitedBy<P, S, D, R, E> where
    T: Clone,
    R: RangeBounds<usize> + Clone,
    P: Parser<T, E>,
    S: Parser<D, E>, 
[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for List<T>

impl<T> !Send for List<T>

impl<T> !Sync for List<T>

impl<T> Unpin for List<T>

impl<T> !UnwindSafe for List<T>

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.