Skip to content

Commit

Permalink
Clarify description of take_until
Browse files Browse the repository at this point in the history
It consumes input until the first occurrence of the tag, not the
longest possible input until the last occurrence of the tag.
  • Loading branch information
fanf2 authored and Geal committed Oct 11, 2020
1 parent 24f4b27 commit 8717d52
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/bytes/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ where
}
}

/// Returns the longest input slice till it matches the pattern.
/// Returns the input slice up to the first occurrence of the pattern.
///
/// It doesn't consume the pattern. It will return `Err(Err::Error((_, ErrorKind::TakeUntil)))`
/// if the pattern wasn't met.
Expand All @@ -431,6 +431,7 @@ where
/// assert_eq!(until_eof("hello, worldeof"), Ok(("eof", "hello, world")));
/// assert_eq!(until_eof("hello, world"), Err(Err::Error(Error::new("hello, world", ErrorKind::TakeUntil))));
/// assert_eq!(until_eof(""), Err(Err::Error(Error::new("", ErrorKind::TakeUntil))));
/// assert_eq!(until_eof("1eof2eof"), Ok(("eof2eof", "1")));
/// ```
pub fn take_until<T, Input, Error: ParseError<Input>>(
tag: T,
Expand Down
3 changes: 2 additions & 1 deletion src/bytes/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ where
}
}

/// Returns the longest input slice till it matches the pattern.
/// Returns the input slice up to the first occurrence of the pattern.
///
/// It doesn't consume the pattern.
///
Expand All @@ -451,6 +451,7 @@ where
/// assert_eq!(until_eof("hello, worldeof"), Ok(("eof", "hello, world")));
/// assert_eq!(until_eof("hello, world"), Err(Err::Incomplete(Needed::Unknown)));
/// assert_eq!(until_eof("hello, worldeo"), Err(Err::Incomplete(Needed::Unknown)));
/// assert_eq!(until_eof("1eof2eof"), Ok(("eof2eof", "1")));
/// ```
pub fn take_until<T, Input, Error: ParseError<Input>>(
tag: T,
Expand Down

0 comments on commit 8717d52

Please sign in to comment.