Skip to content

Commit

Permalink
feat(error): Add impl ErrorConvert for ContextError
Browse files Browse the repository at this point in the history
I added `InputError`->`ContextError` because that's easy enough to do,
but I couldn't implement the other way round because `ContextError`
discards its input.
  • Loading branch information
Lexicality committed Apr 7, 2024
1 parent 8512ab7 commit fc65414
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,20 @@ impl crate::lib::std::fmt::Display for ContextError<StrContext> {
}
}

impl<C> ErrorConvert<ContextError<C>> for ContextError<C> {
#[inline]
fn convert(self) -> ContextError<C> {
self
}
}

impl<I: Clone + Stream, C> ErrorConvert<ContextError<C>> for InputError<I> {
#[inline]
fn convert(self) -> ContextError<C> {
ContextError::from_error_kind(&self.input, self.kind)
}
}

/// Additional parse context for [`ContextError`] added via [`Parser::context`]
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
Expand Down

0 comments on commit fc65414

Please sign in to comment.