Skip to main content

ExtractContext

Trait ExtractContext 

Source
pub trait ExtractContext<I, T> {
    // Required method
    fn extract_context(self, original_input: I) -> T;
}
Expand description

Trait for recombining error information with the original input.

This trait is used to take the context information attached to nom errors- specifically, the tail of the input indicating the location of the input- and recombine it with the original input to produce an error with something more useful for error reporting.

Typically, it looks like ExtractContext<I, E<T>> for E<I>. This indicates that some error type E, which is generic over the input type, can be converted into another variant of that error, using T instead of I to hold the result context. Often this context conversion can happen with RecreateContext.

Required Methods§

Source

fn extract_context(self, original_input: I) -> T

Given the context attached to a nom error, and given the original input to the nom parser, extract more the useful context information.

For example, for a string, 1 possible context extraction would be the Location (line and column number) in the original input where the error indicated by self occurred.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<I, T> ExtractContext<I, (T, ErrorKind)> for (I, ErrorKind)
where T: RecreateContext<I>,

Source§

fn extract_context(self, original_input: I) -> (T, ErrorKind)

Source§

impl<I, T> ExtractContext<I, Error<T>> for Error<I>
where T: RecreateContext<I>,

Source§

fn extract_context(self, original_input: I) -> Error<T>

Source§

impl<I, T> ExtractContext<I, VerboseError<T>> for VerboseError<I>
where T: RecreateContext<I>, I: Clone,

Source§

fn extract_context(self, original_input: I) -> VerboseError<T>

Source§

impl<T, E1, E2, I> ExtractContext<I, Result<T, E2>> for Result<T, E1>
where E1: ExtractContext<I, E2>,

extract_context can be used directly on Result values that have an error with ExtractContext

Source§

fn extract_context(self, original_input: I) -> Result<T, E2>

Implementors§

Source§

impl<I, I2, T, C, E> ExtractContext<I, GenericErrorTree<I2, T, C, E>> for GenericErrorTree<I, T, C, E>
where I: Clone, I2: RecreateContext<I>,

Source§

impl<I, T> ExtractContext<I, ()> for T