Repository: Geal/nom
Pull request #1243 (2020-11-12 21:06:49)

Fix feature documentation for count
Documentation for `multi::count` did not have the marker indicating its dependence on the `alloc` feature. This PR adds it.


Patch:
diff --git a/.travis.yml b/.travis.yml
index 9aac1c1..3c19181 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,6 +20,15 @@ before_script:
 
 matrix:
   include:
+    - rust: stable
+      env: FEATURES='--features "std lexical regexp"'
+      before_script:
+        - export PATH=$HOME/.cargo/bin:$PATH
+        - cargo install cargo-update || echo "cargo-update already installed"
+        - cargo install cargo-tarpaulin || echo "cargo tarpaulin already installed"
+        - cargo install-update -a
+      script:
+        cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID
     - rust: stable
       env: FEATURES=''
     - rust: stable
@@ -41,15 +50,6 @@ matrix:
         - export PATH=$HOME/.cargo/bin:$PATH
       script:
         - eval cargo doc --verbose $DOC_FEATURES
-    - rust: stable
-      env: FEATURES='--features "std lexical regexp"'
-      before_script:
-        - export PATH=$HOME/.cargo/bin:$PATH
-        - cargo install cargo-update || echo "cargo-update already installed"
-        - cargo install cargo-tarpaulin || echo "cargo tarpaulin already installed"
-        - cargo install-update -a
-      script:
-        cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID
 
   allow_failures:
     - rust: stable
diff --git a/README.md b/README.md
index dd54d96..3bcac8f 100644
--- a/README.md
+++ b/README.md
@@ -275,6 +275,7 @@ Here is a (non exhaustive) list of known projects using nom:
 [X.509](https://github.com/rusticata/x509-parser)
 - Network protocol formats:
 [Bencode](https://github.com/jbaum98/bencode.rs),
+[D-Bus](https://github.com/toshokan/misato),
 [DHCP](https://github.com/rusticata/dhcp-parser),
 [HTTP](https://github.com/sozu-proxy/sozu/tree/master/lib/src/protocol/http),
 [URI](https://github.com/santifa/rrp/blob/master/src/uri.rs),
@@ -291,7 +292,8 @@ Here is a (non exhaustive) list of known projects using nom:
 [TLS](https://github.com/rusticata/tls-parser),
 [IPFIX / Netflow v10](https://github.com/dominotree/rs-ipfix),
 [GTP](https://github.com/fuerstenau/gorrosion-gtp),
-[SIP](https://github.com/armatusmiles/sipcore/tree/master/crates/sipmsg)
+[SIP](https://github.com/armatusmiles/sipcore/tree/master/crates/sipmsg),
+[Prometheus](https://github.com/timberio/vector/blob/master/lib/prometheus-parser/src/line.rs)
 - Language specifications:
 [BNF](https://github.com/snewt/bnf)
 - Misc formats:
diff --git a/doc/choosing_a_combinator.md b/doc/choosing_a_combinator.md
index db46568..02c8d64 100644
--- a/doc/choosing_a_combinator.md
+++ b/doc/choosing_a_combinator.md
@@ -117,13 +117,6 @@ Parsing integers from binary formats can be done in two ways: With parser functi
 - `tag_bits!`: Matches an integer pattern to a bitstream. The number of bits of the input to compare must be specified
 - `take_bits!`: Generates a parser consuming the specified number of bits
 
-## Whitespace delimited formats parsing
-
-- `eat_separator!`: Helper macro to build a separator parser
-- `sep!`: Parser rewriting macro for whitespace separated formats
-- `wrap_sep!`: 
-- `ws!`: Consumes whitespace characters, i.e. the `\s` regex pattern
-
 ## Remaining combinators
 
 - `apply!`: Emulate function currying: `apply!(my_function, arg1, arg2, ...)` becomes `my_function(input, arg1, arg2, ...)`
diff --git a/doc/nom_recipes.md b/doc/nom_recipes.md
index 06622dc..6a8ab6f 100644
--- a/doc/nom_recipes.md
+++ b/doc/nom_recipes.md
@@ -27,7 +27,7 @@ These are short recipes for accomplishing common tasks with nom.
 ```rust
 /// A combinator that takes a parser `inner` and produces a parser that also consumes both leading and 
 /// trailing whitespace, returning the output of `inner`.
-fn ws<'a, F: 'a, O, E: ParseError<&'a str>>(inner: F) -> impl Fn(&'a str) -> IResult<&'a str, O, E>
+fn ws<'a, F: 'a, O, E: ParseError<&'a str>>(inner: F) -> impl FnMut(&'a str) -> IResult<&'a str, O, E>
   where
   F: Fn(&'a str) -> IResult<&'a str, O, E>,
 {
@@ -35,7 +35,7 @@ fn ws<'a, F: 'a, O, E: ParseError<&'a str>>(inner: F) -> impl Fn(&'a str) -> IRe
     multispace0,
     inner,
     multispace0
-  )(i)
+  )
 }
 ```
 
@@ -83,7 +83,7 @@ pub fn pinline_comment<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a st
 
 ### `Rust-Style Identifiers`
 
-Parsing identifiers that may start with a letter (or underscore) and may c∏ontain underscores,
+Parsing identifiers that may start with a letter (or underscore) and may contain underscores,
 letters and numbers may be parsed like this:
 
 ```rust
diff --git a/src/bits/mod.rs b/src/bits/mod.rs
index 5b2be01..8f68734 100644
--- a/src/bits/mod.rs
+++ b/src/bits/mod.rs
@@ -23,9 +23,10 @@ use crate::traits::{ErrorConvert, Slice};
 /// # use nom::IResult;
 /// use nom::bits::bits;
 /// use nom::bits::complete::take;
+/// use nom::error::Error;
 ///
 /// fn take_4_bits(input: &[u8]) -> IResult<&[u8], u64> {
-///   bits(take::<_, _, _, (_, _)>(4usize))(input)
+///   bits(take::<_, _, _, Error<_>>(4usize))(input)
 /// }
 ///
 /// let input = vec![0xAB, 0xCD, 0xEF, 0x12];
@@ -34,11 +35,11 @@ use crate::traits::{ErrorConvert, Slice};
 /// assert_eq!(take_4_bits( sl ), Ok( (&sl[1..], 0xA) ));
 /// ```
 pub fn bits<I, O, E1: ParseError<(I, usize)> + ErrorConvert<E2>, E2: ParseError<I>, P>(
-  parser: P,
-) -> impl Fn(I) -> IResult<I, O, E2>
+  mut parser: P,
+) -> impl FnMut(I) -> IResult<I, O, E2>
 where
   I: Slice<RangeFrom<usize>>,
-  P: Fn((I, usize)) -> IResult<(I, usize), O, E1>,
+  P: FnMut((I, usize)) -> IResult<(I, usize), O, E1>,
 {
   move |input: I| match parser((input, 0)) {
     Ok(((rest, offset), res)) => {
@@ -58,7 +59,7 @@ pub fn bitsc<I, O, E1: ParseError<(I, usize)> + ErrorConvert<E2>, E2: ParseError
 ) -> IResult<I, O, E2>
 where
   I: Slice<RangeFrom<usize>>,
-  P: Fn((I, usize)) -> IResult<(I, usize), O, E1>,
+  P: FnMut((I, usize)) -> IResult<(I, usize), O, E1>,
 {
   bits(parser)(input)
 }
@@ -89,11 +90,11 @@ where
 /// assert_eq!(parse( input ), Ok(( &[][..], (0xd, 0xea, &[0xbe, 0xaf][..]) )));
 /// ```
 pub fn bytes<I, O, E1: ParseError<I> + ErrorConvert<E2>, E2: ParseError<(I, usize)>, P>(
-  parser: P,
-) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E2>
+  mut parser: P,
+) -> impl FnMut((I, usize)) -> IResult<(I, usize), O, E2>
 where
   I: Slice<RangeFrom<usize>> + Clone,
-  P: Fn(I) -> IResult<I, O, E1>,
+  P: FnMut(I) -> IResult<I, O, E1>,
 {
   move |(input, offset): (I, usize)| {
     let inner = if offset % 8 != 0 {
@@ -122,7 +123,7 @@ pub fn bytesc<I, O, E1: ParseError<I> + ErrorConvert<E2>, E2: ParseError<(I, usi
 ) -> IResult<(I, usize), O, E2>
 where
   I: Slice<RangeFrom<usize>> + Clone,
-  P: Fn(I) -> IResult<I, O, E1>,
+  P: FnMut(I) -> IResult<I, O, E1>,
 {
   bytes(parser)(input)
 }
diff --git a/src/multi/mod.rs b/src/multi/mod.rs
index 58b76dc..837252b 100644
--- a/src/multi/mod.rs
+++ b/src/multi/mod.rs
@@ -614,6 +614,7 @@ where
 /// assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));
 /// ```
 #[cfg(feature = "alloc")]
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
 pub fn count<I, O, E, F>(mut f: F, count: usize) -> impl FnMut(I) -> IResult<I, Vec<O>, E>
 where
   I: Clone + PartialEq,
diff --git a/src/sequence/mod.rs b/src/sequence/mod.rs
index c534d23..4df7ae7 100644
--- a/src/sequence/mod.rs
+++ b/src/sequence/mod.rs
@@ -321,7 +321,7 @@ macro_rules! tuple_trait_inner(
 tuple_trait!(FnA A, FnB B, FnC C, FnD D, FnE E, FnF F, FnG G, FnH H, FnI I, FnJ J, FnK K, FnL L,
   FnM M, FnN N, FnO O, FnP P, FnQ Q, FnR R, FnS S, FnT T, FnU U);
 
-///Aapplies a tuple of parsers one by one and returns their results as a tuple.
+///Applies a tuple of parsers one by one and returns their results as a tuple.
 ///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind};
diff --git a/src/traits.rs b/src/traits.rs
index 14b6090..2710bdd 100644
--- a/src/traits.rs
+++ b/src/traits.rs
@@ -38,7 +38,6 @@ impl<'a> InputLength for &'a str {
   }
 }
 
-#[deprecated(since = "6.0.0", note = "Use `BitSlice`")]
 impl<'a> InputLength for (&'a [u8], usize) {
   #[inline]
   fn input_len(&self) -> usize {


Test patch:
diff --git a/tests/issues.rs b/tests/issues.rs
index 1f473b4..6788f72 100644
--- a/tests/issues.rs
+++ b/tests/issues.rs
@@ -347,3 +347,19 @@ named!(issue_962<&[u8], Vec<&[u8]>>,
         }
     )
 );
+
+#[test]
+fn issue_1231_bits_expect_fn_closure() {
+    use nom::bits::{bits, complete::take};
+    use nom::error::Error;
+    use nom::sequence::tuple;
+    pub fn example(input: &[u8]) -> IResult<&[u8], (u8, u8)> {
+        bits::<_, _, Error<_>, _, _>(tuple((
+                    take(1usize), take(1usize)
+        )))(input)
+    }
+    assert_eq!(
+        example(&[0xff]),
+        Ok((&b""[..], (1, 1)))
+    );
+}