diff --git a/src/error.rs b/src/error.rs index e7380f87..058916f4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1164,7 +1164,8 @@ pub struct ParseError { } impl> ParseError { - pub(crate) fn new(mut input: I, start: I::Checkpoint, inner: E) -> Self { + /// Construct a new [`ParseError`] wrapping the given error and input. + pub fn new(mut input: I, start: I::Checkpoint, inner: E) -> Self { let offset = input.offset_from(&start); input.reset(&start); Self { @@ -1176,6 +1177,21 @@ impl> ParseError { } impl ParseError { + /// Replace the [`input`][`ParseError::input`] in this [`ParseError`], returning a new + /// [`ParseError`]. + /// + /// **Note:** To replace the [`input`][`ParseError::input`] and + /// [`offset`][`ParseError::offset`], use [`ParseError::new`] and + /// [`ParseError::into_inner`]. + #[inline] + pub fn with_input(self, input: I2) -> ParseError { + ParseError { + input, + offset: self.offset, + inner: self.inner, + } + } + /// The [`Stream`] at the initial location when parsing started #[inline] pub fn input(&self) -> &I {