Trait Input

pub trait Input: Clone + Sized

Parser input types must implement this trait

Associated Types

type Item;

The current input type is a sequence of that Item type.

Example: u8 for &[u8] or char for &str

type Iter: Iterator<Item = Self::Item>;

An iterator over the input type, producing the item

type IterIndices: Iterator<Item = (usize, Self::Item)>;

An iterator over the input type, producing the item and its byte position If we're iterating over &str, the position corresponds to the byte index of the character

Required Methods

fn input_len(&self) -> usize

Calculates the input length, as indicated by its name, and the name of the trait itself

fn take(&self, index: usize) -> Self

Returns a slice of index bytes. panics if index > length

fn take_from(&self, index: usize) -> Self

Returns a slice starting at index bytes. panics if index > length

fn take_split(&self, index: usize) -> (Self, Self)

Split the stream at the index byte offset. panics if index > length

fn position<P>(&self, predicate: P) -> Option<usize>
where
    P: Fn(Self::Item) -> bool,

Returns the byte position of the first element satisfying the predicate

fn iter_elements(&self) -> Self::Iter

Returns an iterator over the elements

fn iter_indices(&self) -> Self::IterIndices

Returns an iterator over the elements and their byte offsets

fn slice_index(&self, count: usize) -> Result<usize, Needed>

Get the byte offset from the element's position in the stream

Provided Methods

fn split_at_position<P, E: ParseError<Self>>(&self, predicate: P) -> IResult<Self, Self, E>
where
    P: Fn(Self::Item) -> bool,

Looks for the first element of the input type for which the condition returns true, and returns the input up to this position.

streaming version: If no element is found matching the condition, this will return Incomplete

fn split_at_position1<P, E: ParseError<Self>>(&self, predicate: P, e: ErrorKind) -> IResult<Self, Self, E>
where
    P: Fn(Self::Item) -> bool,

Looks for the first element of the input type for which the condition returns true and returns the input up to this position.

Fails if the produced slice is empty.

streaming version: If no element is found matching the condition, this will return Incomplete

fn split_at_position_complete<P, E: ParseError<Self>>(&self, predicate: P) -> IResult<Self, Self, E>
where
    P: Fn(Self::Item) -> bool,

Looks for the first element of the input type for which the condition returns true, and returns the input up to this position.

complete version: If no element is found matching the condition, this will return the whole input

fn split_at_position1_complete<P, E: ParseError<Self>>(&self, predicate: P, e: ErrorKind) -> IResult<Self, Self, E>
where
    P: Fn(Self::Item) -> bool,

Looks for the first element of the input type for which the condition returns true and returns the input up to this position.

Fails if the produced slice is empty.

complete version: If no element is found matching the condition, this will return the whole input

fn split_at_position_mode<OM: OutputMode, P, E: ParseError<Self>>(&self, predicate: P) -> PResult<OM, Self, Self, E>
where
    P: Fn(Self::Item) -> bool,

mode version of split_at_position

fn split_at_position_mode1<OM: OutputMode, P, E: ParseError<Self>>(&self, predicate: P, e: ErrorKind) -> PResult<OM, Self, Self, E>
where
    P: Fn(Self::Item) -> bool,

mode version of split_at_position

Implementors