From 6580debbfe1e183213d4afee3bc2fc36fc95afeb Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 4 Dec 2021 14:14:16 +0100 Subject: [PATCH] Doc example for take --- src/bytes/complete.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bytes/complete.rs b/src/bytes/complete.rs index 9375b1f..a5442b5 100644 --- a/src/bytes/complete.rs +++ b/src/bytes/complete.rs @@ -388,6 +388,18 @@ where /// assert_eq!(take6("short"), Err(Err::Error(Error::new("short", ErrorKind::Eof)))); /// assert_eq!(take6(""), Err(Err::Error(Error::new("", ErrorKind::Eof)))); /// ``` +/// +/// The units that are taken will depend on the input type. For example, for a +/// `&str` it will take a number of `char`'s, whereas for a `&[u8]` it will +/// take that many `u8`'s: +/// +/// ```rust +/// use nom::error::Error; +/// use nom::bytes::complete::take; +/// +/// assert_eq!(take::<_, _, Error<_>>(1usize)("💙"), Ok(("", "💙"))); +/// assert_eq!(take::<_, _, Error<_>>(1usize)("💙".as_bytes()), Ok((b"\x9F\x92\x99".as_ref(), b"\xF0".as_ref()))); +/// ``` pub fn take>( count: C, ) -> impl Fn(Input) -> IResult