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

docs: Clarify peek's behavior with Input #624

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion src/combinator/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ where
})
}

/// Tries to apply its parser without consuming the input.
/// Apply the parser without advancing the input.
///
/// To lookahead and only advance on success, see [`opt`].
///
/// # Example
///
Expand Down
13 changes: 12 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,18 @@ pub trait Parser<I, O, E> {

/// Take tokens from the [`Stream`], turning it into the output
///
/// This includes advancing the [`Stream`] to the next location.
/// This returns a copy of the [`Stream`] advanced to the next location.
///
/// <div class="warning">
///
/// Generally, prefer [`Parser::parse_next`].
/// This is primarily intended for:
/// - Migrating from older versions / `nom`
/// - Testing [`Parser`]s
///
/// For look-ahead parsing, see instead [`peek`].
///
/// </div>
#[inline(always)]
fn parse_peek(&mut self, mut input: I) -> IResult<I, O, E> {
match self.parse_next(&mut input) {
Expand Down
Loading