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§
Sourcetype Item
type Item
The current input type is a sequence of that Item
type.
Example: u8
for &[u8]
or char
for &str
Sourcetype IterIndices: Iterator<Item = (usize, Self::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§
Sourcefn input_len(&self) -> usize
fn input_len(&self) -> usize
Calculates the input length, as indicated by its name, and the name of the trait itself
Sourcefn take_from(&self, index: usize) -> Self
fn take_from(&self, index: usize) -> Self
Returns a slice starting at index
bytes. panics if index > length
Sourcefn take_split(&self, index: usize) -> (Self, Self)
fn take_split(&self, index: usize) -> (Self, Self)
Split the stream at the index
byte offset. panics if index > length
Sourcefn position<P>(&self, predicate: P) -> Option<usize>
fn position<P>(&self, predicate: P) -> Option<usize>
Returns the byte position of the first element satisfying the predicate
Sourcefn iter_elements(&self) -> Self::Iter
fn iter_elements(&self) -> Self::Iter
Returns an iterator over the elements
Sourcefn iter_indices(&self) -> Self::IterIndices
fn iter_indices(&self) -> Self::IterIndices
Returns an iterator over the elements and their byte offsets
Provided Methods§
Sourcefn split_at_position<P, E>(&self, predicate: P) -> Result<(Self, Self), Err<E>>
fn split_at_position<P, E>(&self, predicate: P) -> Result<(Self, Self), Err<E>>
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
Sourcefn split_at_position1<P, E>(
&self,
predicate: P,
e: ErrorKind,
) -> Result<(Self, Self), Err<E>>
fn split_at_position1<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, Self), Err<E>>
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
Sourcefn split_at_position_complete<P, E>(
&self,
predicate: P,
) -> Result<(Self, Self), Err<E>>
fn split_at_position_complete<P, E>( &self, predicate: P, ) -> Result<(Self, Self), Err<E>>
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
Sourcefn split_at_position1_complete<P, E>(
&self,
predicate: P,
e: ErrorKind,
) -> Result<(Self, Self), Err<E>>
fn split_at_position1_complete<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, Self), Err<E>>
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
Sourcefn 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>>>
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>>>
mode version of split_at_position
Sourcefn 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>>>
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>>>
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
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>>>
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>>>
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>>>
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>>>
mode version of split_at_position
type Item = char
type Iter = Chars<'a>
type IterIndices = CharIndices<'a>
fn input_len(&self) -> usize
fn take(&self, index: usize) -> &'a str
fn take_from(&self, index: usize) -> &'a str
fn take_split(&self, index: usize) -> (&'a str, &'a str)
fn position<P>(&self, predicate: P) -> Option<usize>
fn iter_elements(&self) -> <&'a str as Input>::Iter
fn iter_indices(&self) -> <&'a str as Input>::IterIndices
fn slice_index(&self, count: usize) -> Result<usize, Needed>
fn split_at_position<P, E>( &self, predicate: P, ) -> Result<(&'a str, &'a str), Err<E>>
fn split_at_position1<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(&'a str, &'a str), Err<E>>
fn split_at_position_complete<P, E>( &self, predicate: P, ) -> Result<(&'a str, &'a str), Err<E>>
fn split_at_position1_complete<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(&'a str, &'a str), Err<E>>
Source§impl<'a> Input for &'a [u8]
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>>>
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>>>
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>>>
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>>>
mode version of split_at_position