pub trait Tool<'a> {
type Error;
type Data;
// Required method
fn parse(
&self,
st: View<'a>,
) -> Result<(Self::Data, usize, View<'a>), Self::Error>;
}Expand description
Parsing tool trait.
An object implementing this trait represents a parsing rule that are applied to string prefixes. If any prefix of a string satisfy this rule then the match is successful and additional data parsed from the matching prefix is returned. If instead no prefix satisfies the rule then an error is returned.
Required Associated Types§
Required Methods§
Sourcefn parse(
&self,
st: View<'a>,
) -> Result<(Self::Data, usize, View<'a>), Self::Error>
fn parse( &self, st: View<'a>, ) -> Result<(Self::Data, usize, View<'a>), Self::Error>
The main parsing algorithm.
On a successful match, it additionally returns the parsed data and the length of the match in bytes.
§Errors
If no prefix of st satisfies this parsing strategy then Error is returned.
Implementations on Foreign Types§
Source§impl<'a, T> Tool<'a> for [T]where
T: Tool<'a>,
Matches any tool in the given slice.
impl<'a, T> Tool<'a> for [T]where
T: Tool<'a>,
Matches any tool in the given slice.
Tools are evaluated with increasing index ordering, so a later tool would not be tested is a previous tool has already matched.
Source§type Error = Option<<T as Tool<'a>>::Error>
type Error = Option<<T as Tool<'a>>::Error>
Only the last error is returned.
If you want to keep track of every returned error, use instead multiple nested instances of
Or tool.
type Data = (usize, <T as Tool<'a>>::Data)
fn parse( &self, st: View<'a>, ) -> Result<(Self::Data, usize, View<'a>), Self::Error>
Source§impl<'a, T, const N: usize> Tool<'a> for [T; N]where
T: Tool<'a>,
Matches any tool in the given array.
impl<'a, T, const N: usize> Tool<'a> for [T; N]where
T: Tool<'a>,
Matches any tool in the given array.
Tools are evaluated with increasing index ordering, so a later tool would not be tested is a previous tool has already matched.
Source§type Error = Option<<T as Tool<'a>>::Error>
type Error = Option<<T as Tool<'a>>::Error>
Only the last error is returned.
If you want to keep track of every returned error, use instead multiple nested instances of
Or tool.