rustmax::nom

Trait Input

Source
pub trait Input: Sized + Clone {
    type Item;
    type Iter: Iterator<Item = Self::Item>;
    type IterIndices: Iterator<Item = (usize, Self::Item)>;

Show 14 methods // Required methods fn input_len(&self) -> usize; fn take(&self, index: usize) -> Self; fn take_from(&self, index: usize) -> Self; fn take_split(&self, index: usize) -> (Self, Self); fn position<P>(&self, predicate: P) -> Option<usize> where P: Fn(Self::Item) -> bool; fn iter_elements(&self) -> Self::Iter; fn iter_indices(&self) -> Self::IterIndices; fn slice_index(&self, count: usize) -> Result<usize, Needed>; // Provided methods fn split_at_position<P, E>( &self, predicate: P, ) -> Result<(Self, Self), Err<E>> where E: ParseError<Self>, P: Fn(Self::Item) -> bool { ... } fn split_at_position1<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, Self), Err<E>> where E: ParseError<Self>, P: Fn(Self::Item) -> bool { ... } fn split_at_position_complete<P, E>( &self, predicate: P, ) -> Result<(Self, Self), Err<E>> where E: ParseError<Self>, P: Fn(Self::Item) -> bool { ... } fn split_at_position1_complete<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, Self), Err<E>> where E: ParseError<Self>, P: Fn(Self::Item) -> bool { ... } fn split_at_position_mode<OM, P, E>( &self, predicate: P, ) -> Result<(Self, <<OM as OutputMode>::Output as Mode>::Output<Self>), Err<E, <<OM as OutputMode>::Error as Mode>::Output<E>>> where OM: OutputMode, E: ParseError<Self>, P: Fn(Self::Item) -> bool { ... } fn split_at_position_mode1<OM, P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, <<OM as OutputMode>::Output as Mode>::Output<Self>), Err<E, <<OM as OutputMode>::Error as Mode>::Output<E>>> where OM: OutputMode, E: ParseError<Self>, P: Fn(Self::Item) -> bool { ... }
}
Expand description

Parser input types must implement this trait

Required Associated Types§

Source

type Item

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

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

Source

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

An iterator over the input type, producing the item

Source

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§

Source

fn input_len(&self) -> usize

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

Source

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

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

Source

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

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

Source

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

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

Source

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

Source

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

Returns an iterator over the elements

Source

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

Returns an iterator over the elements and their byte offsets

Source

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

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

Provided Methods§

Source

fn split_at_position<P, E>(&self, predicate: P) -> Result<(Self, Self), Err<E>>
where E: ParseError<Self>, 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

Source

fn split_at_position1<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, Self), Err<E>>
where E: ParseError<Self>, 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

Source

fn split_at_position_complete<P, E>( &self, predicate: P, ) -> Result<(Self, Self), Err<E>>
where E: ParseError<Self>, 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

Source

fn split_at_position1_complete<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, Self), Err<E>>
where E: ParseError<Self>, 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

Source

fn split_at_position_mode<OM, P, E>( &self, predicate: P, ) -> Result<(Self, <<OM as OutputMode>::Output as Mode>::Output<Self>), Err<E, <<OM as OutputMode>::Error as Mode>::Output<E>>>
where OM: OutputMode, E: ParseError<Self>, P: Fn(Self::Item) -> bool,

mode version of split_at_position

Source

fn split_at_position_mode1<OM, P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, <<OM as OutputMode>::Output as Mode>::Output<Self>), Err<E, <<OM as OutputMode>::Error as Mode>::Output<E>>>
where OM: OutputMode, E: ParseError<Self>, P: Fn(Self::Item) -> bool,

mode version of split_at_position

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a> Input for &'a str

Source§

fn split_at_position_mode<OM, P, E>( &self, predicate: P, ) -> Result<(&'a str, <<OM as OutputMode>::Output as Mode>::Output<&'a str>), Err<E, <<OM as OutputMode>::Error as Mode>::Output<E>>>
where OM: OutputMode, E: ParseError<&'a str>, P: Fn(<&'a str as Input>::Item) -> bool,

mode version of split_at_position

Source§

fn split_at_position_mode1<OM, P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(&'a str, <<OM as OutputMode>::Output as Mode>::Output<&'a str>), Err<E, <<OM as OutputMode>::Error as Mode>::Output<E>>>
where OM: OutputMode, E: ParseError<&'a str>, P: Fn(<&'a str as Input>::Item) -> bool,

mode version of split_at_position

Source§

type Item = char

Source§

type Iter = Chars<'a>

Source§

type IterIndices = CharIndices<'a>

Source§

fn input_len(&self) -> usize

Source§

fn take(&self, index: usize) -> &'a str

Source§

fn take_from(&self, index: usize) -> &'a str

Source§

fn take_split(&self, index: usize) -> (&'a str, &'a str)

Source§

fn position<P>(&self, predicate: P) -> Option<usize>
where P: Fn(<&'a str as Input>::Item) -> bool,

Source§

fn iter_elements(&self) -> <&'a str as Input>::Iter

Source§

fn iter_indices(&self) -> <&'a str as Input>::IterIndices

Source§

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

Source§

fn split_at_position<P, E>( &self, predicate: P, ) -> Result<(&'a str, &'a str), Err<E>>
where E: ParseError<&'a str>, P: Fn(<&'a str as Input>::Item) -> bool,

Source§

fn split_at_position1<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(&'a str, &'a str), Err<E>>
where E: ParseError<&'a str>, P: Fn(<&'a str as Input>::Item) -> bool,

Source§

fn split_at_position_complete<P, E>( &self, predicate: P, ) -> Result<(&'a str, &'a str), Err<E>>
where E: ParseError<&'a str>, P: Fn(<&'a str as Input>::Item) -> bool,

Source§

fn split_at_position1_complete<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(&'a str, &'a str), Err<E>>
where E: ParseError<&'a str>, P: Fn(<&'a str as Input>::Item) -> bool,

Source§

impl<'a> Input for &'a [u8]

Source§

fn split_at_position_mode<OM, P, E>( &self, predicate: P, ) -> Result<(&'a [u8], <<OM as OutputMode>::Output as Mode>::Output<&'a [u8]>), Err<E, <<OM as OutputMode>::Error as Mode>::Output<E>>>
where OM: OutputMode, E: ParseError<&'a [u8]>, P: Fn(<&'a [u8] as Input>::Item) -> bool,

mode version of split_at_position

Source§

fn split_at_position_mode1<OM, P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(&'a [u8], <<OM as OutputMode>::Output as Mode>::Output<&'a [u8]>), Err<E, <<OM as OutputMode>::Error as Mode>::Output<E>>>
where OM: OutputMode, E: ParseError<&'a [u8]>, P: Fn(<&'a [u8] as Input>::Item) -> bool,

mode version of split_at_position

Source§

type Item = u8

Source§

type Iter = Copied<Iter<'a, u8>>

Source§

type IterIndices = Enumerate<<&'a [u8] as Input>::Iter>

Source§

fn input_len(&self) -> usize

Source§

fn take(&self, index: usize) -> &'a [u8]

Source§

fn take_from(&self, index: usize) -> &'a [u8]

Source§

fn take_split(&self, index: usize) -> (&'a [u8], &'a [u8])

Source§

fn position<P>(&self, predicate: P) -> Option<usize>
where P: Fn(<&'a [u8] as Input>::Item) -> bool,

Source§

fn iter_elements(&self) -> <&'a [u8] as Input>::Iter

Source§

fn iter_indices(&self) -> <&'a [u8] as Input>::IterIndices

Source§

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

Source§

fn split_at_position<P, E>( &self, predicate: P, ) -> Result<(&'a [u8], &'a [u8]), Err<E>>
where E: ParseError<&'a [u8]>, P: Fn(<&'a [u8] as Input>::Item) -> bool,

Source§

fn split_at_position1<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(&'a [u8], &'a [u8]), Err<E>>
where E: ParseError<&'a [u8]>, P: Fn(<&'a [u8] as Input>::Item) -> bool,

Source§

fn split_at_position_complete<P, E>( &self, predicate: P, ) -> Result<(&'a [u8], &'a [u8]), Err<E>>
where E: ParseError<&'a [u8]>, P: Fn(<&'a [u8] as Input>::Item) -> bool,

Source§

fn split_at_position1_complete<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(&'a [u8], &'a [u8]), Err<E>>
where E: ParseError<&'a [u8]>, P: Fn(<&'a [u8] as Input>::Item) -> bool,

Implementors§