pub trait ParserUntilInclusive: Sized {
// Required method
fn parser_until_inclusive<'a, P>(
delimiter: P,
) -> impl Parser<&'a str, Self, ErrMode<ContextError>>
where P: Parser<&'a str, &'a str, ErrMode<ContextError>>;
// Provided method
fn parser_until_line_ending_inclusive(input: &mut &str) -> ModalResult<Self> { ... }
}Expand description
A trait for types that can be parsed until a given delimiter parser matches, while consuming that delimiter.
Allows creating non-delimiter-aware type parsers, that can be used inline in file parsers.
Automatically implemented for all types implementing ParserUntil and thereby transitively
AlpmParser.
§Examples
use alpm_parsers::traits::{AlpmParser, ParserUntil, ParserUntilInclusive};
use winnow::{
ModalResult,
Parser,
error::{ContextError, ErrMode},
token::take_while,
};
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
struct Alphanumeric(String);
// Implementing `AlpmParser` automatically implements `ParserUntilInclusive`:
// `ParserUntil` is auto-implemented over `AlpmParser` and `ParserUntilInclusive` is auto-implemented over `ParserUntil`.
impl AlpmParser for Alphanumeric {
fn parser(input: &mut &str) -> ModalResult<Self> {
take_while(1.., |c: char| c.is_alphanumeric())
.map(|s: &str| Alphanumeric(s.to_string()))
.parse_next(input)
}
}
assert_eq!(
Alphanumeric::parser_until_line_ending_inclusive.parse_peek("abc123\nnext"),
Ok(("next", Alphanumeric("abc123".to_string())))
);
Required Methods§
Sourcefn parser_until_inclusive<'a, P>(
delimiter: P,
) -> impl Parser<&'a str, Self, ErrMode<ContextError>>
fn parser_until_inclusive<'a, P>( delimiter: P, ) -> impl Parser<&'a str, Self, ErrMode<ContextError>>
Returns a [Parser] that parses the whole input and consumes the given delimiter parser.
Provided Methods§
Sourcefn parser_until_line_ending_inclusive(input: &mut &str) -> ModalResult<Self>
fn parser_until_line_ending_inclusive(input: &mut &str) -> ModalResult<Self>
Returns a [Parser] that parses until the end of line and fully consumes it.
Delegates to Self::parser_until_inclusive with the [line_ending] and [eof]
delimiter.
A line ending is \n, \r\n or [eof] and consumed as well.
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.