Skip to content

Commit 18f20ee

Browse files
authored
Merge pull request #796 from epage/docs
docs(ref): Clarify distinction between parse and parse_next
2 parents 1b57161 + fa51dd4 commit 18f20ee

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/parser.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ use crate::stream::{Recover, Recoverable};
4747
/// - `&[u8]` and `&str`, see [`winnow::token::literal`][crate::token::literal]
4848
pub trait Parser<I, O, E> {
4949
/// Parse all of `input`, generating `O` from it
50+
///
51+
/// This is intended for integrating your parser into the rest of your application.
52+
///
53+
/// For one [`Parser`] to drive another [`Parser`] forward or for
54+
/// [incremental parsing][StreamIsPartial], see instead [`Parser::parse_next`].
55+
///
56+
/// This assumes the [`Parser`] intends to read all of `input` and will return an
57+
/// [`eof`][crate::combinator::eof] error if it does not
58+
/// To ignore trailing `input`, combine your parser with a [`rest`][crate::token::rest]
59+
/// (e.g. `(parser, rest).parse(input)`).
60+
///
61+
/// See also the [tutorial][crate::_tutorial::chapter_6].
5062
#[inline]
5163
fn parse(&mut self, mut input: I) -> Result<O, ParseError<I, <E as ParserError<I>>::Inner>>
5264
where
@@ -76,9 +88,12 @@ pub trait Parser<I, O, E> {
7688

7789
/// Take tokens from the [`Stream`], turning it into the output
7890
///
79-
/// This includes advancing the [`Stream`] to the next location.
91+
/// This includes advancing the input [`Stream`] to the next location.
8092
///
8193
/// On error, `input` will be left pointing at the error location.
94+
///
95+
/// This is intended for a [`Parser`] to drive another [`Parser`] forward or for
96+
/// [incremental parsing][StreamIsPartial]
8297
fn parse_next(&mut self, input: &mut I) -> Result<O, E>;
8398

8499
/// Take tokens from the [`Stream`], turning it into the output

0 commit comments

Comments
 (0)