1use nom::error::{Error, ErrorKind, VerboseError, VerboseErrorKind};
8
9pub trait ContextError<I, C>: Sized {
12 fn add_context(location: I, ctx: C, other: Self) -> Self;
17}
18
19impl<I, C> ContextError<I, C> for () {
20 fn add_context(_location: I, _ctx: C, _other: Self) -> Self {}
21}
22
23impl<I, C> ContextError<I, C> for (I, ErrorKind) {
24 fn add_context(_location: I, _ctx: C, other: Self) -> Self {
25 other
26 }
27}
28
29impl<I, C> ContextError<I, C> for Error<I> {
30 fn add_context(_location: I, _ctx: C, other: Self) -> Self {
31 other
32 }
33}
34
35impl<I> ContextError<I, &'static str> for VerboseError<I> {
36 fn add_context(location: I, ctx: &'static str, mut other: Self) -> Self {
37 other
38 .errors
39 .push((location, VerboseErrorKind::Context(ctx)));
40
41 other
42 }
43}