Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ParseError::with_input #604

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,8 @@ pub struct ParseError<I, E> {
}

impl<I: Stream, E: ParserError<I>> ParseError<I, E> {
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 {
Expand All @@ -1176,6 +1177,21 @@ impl<I: Stream, E: ParserError<I>> ParseError<I, E> {
}

impl<I, E> ParseError<I, E> {
/// 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<I2>(self, input: I2) -> ParseError<I2, E> {
ParseError {
input,
offset: self.offset,
inner: self.inner,
}
}

/// The [`Stream`] at the initial location when parsing started
#[inline]
pub fn input(&self) -> &I {
Expand Down
Loading