From 8ecab378debdfd1f65d964dd26fd40ffd9945ba5 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 1 Aug 2023 16:45:25 -0500 Subject: [PATCH] feat(error): Impl AddContext for ErrMode --- src/combinator/parser.rs | 2 +- src/error.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/combinator/parser.rs b/src/combinator/parser.rs index bf848494..c6241f91 100644 --- a/src/combinator/parser.rs +++ b/src/combinator/parser.rs @@ -838,7 +838,7 @@ where trace(name, move |i: &mut I| { (self.parser) .parse_next(i) - .map_err(|err| err.map(|err| err.add_context(i, self.context.clone()))) + .map_err(|err| err.add_context(i, self.context.clone())) }) .parse_next(i) } diff --git a/src/error.rs b/src/error.rs index 765a2cb3..93ad2e09 100644 --- a/src/error.rs +++ b/src/error.rs @@ -210,6 +210,13 @@ where } } +impl> AddContext for ErrMode { + #[inline] + fn add_context(self, input: &I, ctx: C) -> Self { + self.map(|err| err.add_context(input, ctx)) + } +} + impl ErrMode> { /// Maps `ErrMode>` to `ErrMode>` with the given `F: T -> U` pub fn map_input(self, f: F) -> ErrMode>