Skip to content

Commit e392b17

Browse files
committed
Change take_while doc example to use nom::bytes::take_while
1 parent a44b52e commit e392b17

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/bytes/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,19 +276,23 @@ where
276276
/// takes the input and returns a bool)*.
277277
/// # Example
278278
/// ```rust
279-
/// # use nom::{Err, error::ErrorKind, Needed, IResult};
280-
/// use nom::bytes::complete::take_while;
279+
/// # use nom::{Err, error::ErrorKind, Needed, Parser, IResult};
280+
/// use nom::bytes::take_while;
281281
/// use nom::AsChar;
282282
///
283283
/// fn alpha(s: &[u8]) -> IResult<&[u8], &[u8]> {
284-
/// take_while(AsChar::is_alpha)(s)
284+
/// take_while(AsChar::is_alpha).parse(s)
285285
/// }
286286
///
287287
/// assert_eq!(alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
288288
/// assert_eq!(alpha(b"12345"), Ok((&b"12345"[..], &b""[..])));
289-
/// assert_eq!(alpha(b"latin"), Ok((&b""[..], &b"latin"[..])));
290-
/// assert_eq!(alpha(b""), Ok((&b""[..], &b""[..])));
289+
/// assert_eq!(alpha(b"latin"), Err(Err::Incomplete(Needed::new(1))));
290+
/// assert_eq!(alpha(b""), Err(Err::Incomplete(Needed::new(1))));
291291
/// ```
292+
///
293+
/// See also:
294+
/// - [`bytes::streaming::take_while`](crate::bytes::streaming::take_while)
295+
/// - [`bytes::complete::take_while`](crate::bytes::complete::take_while)
292296
pub fn take_while<F, I, Error: ParseError<I>>(cond: F) -> impl Parser<I, Output = I, Error = Error>
293297
where
294298
I: Input,

0 commit comments

Comments
 (0)