pub trait ContextExt<'i, O>: Parser<Input<'i>, O, ErrMode<ParseStack<'i>>> + Sized {
// Provided methods
fn label(self, label: impl Into<String>) -> ContextParser<Self> { ... }
fn expected_char(self, expected: char) -> ContextParser<Self> { ... }
fn expected_chars(
self,
expected: impl IntoIterator<Item = char>,
) -> ContextParser<Self> { ... }
fn expected_string(self, expected: &'static str) -> ContextParser<Self> { ... }
fn expected_strings<I>(self, expected: I) -> ContextParser<Self>
where I: IntoIterator,
I::Item: Borrow<&'static str> { ... }
fn expected_text(self, expected: impl Into<String>) -> ContextParser<Self> { ... }
fn description(self, description: impl Into<String>) -> ContextParser<Self> { ... }
}Expand description
The trait that adds context functions to all parsers over Input.
These functions are the String-capable counterparts to Parser::context.
§Note
Just like Parser::context calls, any attached context becomes part of the current layer,
which is closed by the next LayerExt::layer.
§Example
use alpm_parsers::prelude::*;
use winnow::ascii::digit1;
// Context messages may be built at runtime.
let expected = format!("Hoped for exactly {} decimal digit", 1);
let mut parser = digit1
.label("version number")
.description(expected)
.layer("version");
parser.parse(Input::new("42"))?;Provided Methods§
Sourcefn label(self, label: impl Into<String>) -> ContextParser<Self>
fn label(self, label: impl Into<String>) -> ContextParser<Self>
Set a label that describes what is currently being parsed.
Sourcefn expected_char(self, expected: char) -> ContextParser<Self>
fn expected_char(self, expected: char) -> ContextParser<Self>
Add a char literal to describe what is expected at the failing position.
Sourcefn expected_chars(
self,
expected: impl IntoIterator<Item = char>,
) -> ContextParser<Self>
fn expected_chars( self, expected: impl IntoIterator<Item = char>, ) -> ContextParser<Self>
Helper function to add multiple chars like Self::expected_char.
Sourcefn expected_string(self, expected: &'static str) -> ContextParser<Self>
fn expected_string(self, expected: &'static str) -> ContextParser<Self>
Add a string literal that is expected at the failing position.
Sourcefn expected_strings<I>(self, expected: I) -> ContextParser<Self>
fn expected_strings<I>(self, expected: I) -> ContextParser<Self>
Helper function to add multiple strings literals like Self::expected_string.
Sourcefn expected_text(self, expected: impl Into<String>) -> ContextParser<Self>
fn expected_text(self, expected: impl Into<String>) -> ContextParser<Self>
Add a free-form text that describes what is expected at the failing position.
Sourcefn description(self, description: impl Into<String>) -> ContextParser<Self>
fn description(self, description: impl Into<String>) -> ContextParser<Self>
Add a free-form description of what went wrong at the failing position.
Multiple description entries are joined without any spacing or characters.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".