use nom::error::{Error, ErrorKind, VerboseError, VerboseErrorKind};
pub trait ContextError<I, C>: Sized {
fn add_context(location: I, ctx: C, other: Self) -> Self;
}
impl<I, C> ContextError<I, C> for () {
fn add_context(_location: I, _ctx: C, _other: Self) -> Self {}
}
impl<I, C> ContextError<I, C> for (I, ErrorKind) {
fn add_context(_location: I, _ctx: C, other: Self) -> Self {
other
}
}
impl<I, C> ContextError<I, C> for Error<I> {
fn add_context(_location: I, _ctx: C, other: Self) -> Self {
other
}
}
impl<I> ContextError<I, &'static str> for VerboseError<I> {
fn add_context(location: I, ctx: &'static str, mut other: Self) -> Self {
other
.errors
.push((location, VerboseErrorKind::Context(ctx)));
other
}
}