Snap for 8570526 from cf329c0891d9be50679a3240cdf758e8e3eea104 to mainline-mediaprovider-release

Change-Id: I766ed922afd694bc6ed131c62f6ec958e5720e14
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 11eb80a..d603d8a 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
 {
   "git": {
-    "sha1": "7e16897f3862dc4187a794c58e54909458ff044a"
+    "sha1": "b6f79c4d375ae55e1fd1a35032ebb47a52ea3389"
   }
-}
+}
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index e18b140..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,101 +0,0 @@
-language: rust
-# sudo is required to enable kcov to use the personality syscall
-sudo: required
-dist: trusty
-cache: cargo
-
-rust:
-  - nightly
-  - beta
-  - stable
-  - 1.31.0
-
-env:
-  matrix:
-    - FEATURES='--features "regexp regexp_macros"'
-
-before_script:
-  - eval git pull --rebase https://github.com/Geal/nom master
-  - eval git log --pretty=oneline HEAD~5..HEAD
-
-matrix:
-  include:
-    - rust: nightly
-      env: FEATURES='--no-default-features'
-    - rust: nightly
-      env: FEATURES='--no-default-features --features "alloc"'
-    - rust: stable
-      env: FEATURES=''
-    - rust: nightly
-      env: DOC_FEATURES='--features "std lexical regexp regexp_macros" --no-default-features'
-      before_script:
-        - export PATH=$HOME/.cargo/bin:$PATH
-      script:
-        - eval cargo doc --verbose $DOC_FEATURES
-    - rust: nightly
-      env: FEATURES=''
-      before_script:
-        - export PATH=$HOME/.cargo/bin:$PATH
-        - cargo install cargo-update   || echo "cargo-update already installed"
-        - cargo install cargo-travis   || echo "cargo-travis already installed"
-        - cargo install-update -a
-        - mkdir -p target/kcov-master
-      script:
-        cargo coveralls --verbose --all-features
-  allow_failures:
-    - rust: stable
-      env: FEATURES=''
-      before_script:
-        - export PATH=$HOME/.cargo/bin:$PATH
-        - rustup component add rustfmt-preview
-      script:
-        - eval cargo fmt -- --write-mode=diff
-
-notifications:
-  webhooks:
-    urls:
-      - https://webhooks.gitter.im/e/9c035a194ac4fd4cc061
-    on_success: change
-    on_failure: always
-    on_start: false
-
-
-addons:
-  apt:
-    packages:
-      - libcurl4-openssl-dev
-      - libelf-dev
-      - libdw-dev
-      - binutils-dev
-      - cmake
-    sources:
-      - kalakris-cmake
-
-cache:
-  directories:
-    - /home/travis/.cargo
-
-before_cache:
-  - rm -rf /home/travis/.cargo/registry
-
-script:
-  - eval cargo build --verbose $FEATURES
-  - eval cargo test --verbose $FEATURES
-
-after_success: |
-  case "$TRAVIS_RUST_VERSION" in
-    nightly)
-      if [ "${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}" != "master" ]; then
-        git fetch &&
-        git checkout master &&
-        cargo bench --verbose
-      fi
-
-      if [ "$FEATURES" == '--features "regexp regexp_macros"' ]; then
-        cargo bench --verbose
-      fi
-      ;;
-
-    *)
-      ;;
-  esac
diff --git a/Android.bp b/Android.bp
index 0c5acc3..6fd9d6f 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,4 +1,5 @@
-// This file is generated by cargo2android.py --run --dependencies --device --features=alloc,std.
+// This file is generated by cargo2android.py --config cargo2android.json.
+// Do not modify this file as changes will be overridden on upgrade.
 
 package {
     default_applicable_licenses: ["external_rust_crates_nom_license"],
@@ -21,20 +22,17 @@
     name: "libnom",
     host_supported: true,
     crate_name: "nom",
+    cargo_env_compat: true,
+    cargo_pkg_version: "7.1.0",
     srcs: ["src/lib.rs"],
     edition: "2018",
     features: [
         "alloc",
         "std",
     ],
-    flags: [
-        "--cfg stable_i128",
-    ],
+    cfgs: ["stable_i128"],
     rustlibs: [
         "libmemchr",
+        "libminimal_lexical",
     ],
 }
-
-// dependent_library ["feature_list"]
-//   memchr-2.3.3 "std,use_std"
-//   version_check-0.9.2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 33d2a78..a1bff5c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,10 +4,314 @@
 
 ### Thanks
 
+### Changed
+
+## 7.1.0 - 2021-11-04
+
+### Thanks
+
+- @nickelc
+- @Stargateur
+- @NilsIrl
+- @clonejo
+- @Strytyp
+- @schubart
+- @jihchi
+- @nipunn1313
+- @Gungy2
+- @Drumato
+- @Alexhuszagh
+- @Aehmlo
+- @homersimpsons
+- @dne
+- @epage
+- @saiintbrisson
+- @pymongo
+
+### Changed
+
+- documentation fixes
+- Ci fixes
+- the move to minimal-lexical for float parsing introduced bugs that cannot be resolved right now, so this version moves back to using the standard lib' parser. *This is a performance regression**. If you have specific requirements around float parsing, you are strongly encouraged to use [recognize_float](https://docs.rs/nom/latest/nom/number/complete/fn.recognize_float.html) and another library to convert to a f32 or f64
+
 ### Added
 
+- alt now works with 1 elment tuples
+
+## 7.0.0 - 2021-08-21
+
+This release fixes dependency compilation issues and strengthen the minimum supported Rust version (MSRV) policy. This is also the first release without the macros that were used since nom's beginning.
+
+### Thanks
+
+- @djc
+- @homersimpsons
+- @lo48576
+- @myrrlyn
+- @RalXYZ
+- @nickelc
+- @cenodis
+
+### Added
+
+- `take_until1` combinator
+- more `to_owned` implementations
+- `fail`: a parser that always fail, useful as default condition in other combinators
+- text to number parsers: in the `character::streaming` and `character::complete` modules, there are parsers named `i8, u16, u32, u64, u128` and `u8 ,u16, u32, u64, u128` that recognize decimal digits and directly convert to a number in the target size (checking for max int size)
+
+### Removed
+
+- now that function combinators are the main way to write parsers, the old macro combinators are confusing newcomers. THey have been removed
+- the `BitSlice` input type from bitvec has been moved into the [nom-bitvec](https://crates.io/crates/nom-bitvec) crate. nom does not depend on bitvec now
+- regex parsers have been moved into the [nom-regex](https://crates.io/crates/nom-regex) crate. nom does not depend on regex now
+- `ErrorKind::PArseTo` was not needed anymore
+
+### Changed
+
+- relax trait bounds
+- some performance fixes
+- `split_at_position*` functions should now be guaranteed panic free
+- the `lexical-core` crate used for float parsing has now been replaced with `minimal-lexical`: the new crate is faster to compile, faster to parse, and has no dependencies
+
 ### Fixed
 
+- infinite loop in `escaped` combinator
+- `many_m_n` now fails if min > max
+
+
+## 6.2.1 - 2021-06-23
+
+### Thanks
+
+This release was done thanks to the hard work of (by order of appearance in the commit list):
+
+- @homersimpsons
+
+### Fixed
+
+- fix documentation building
+
+## 6.2.0 - 2021-02-15
+
+### Thanks
+
+This release was done thanks to the hard work of (by order of appearance in the commit list):
+
+- @DavidKorczynski
+- @homersimpsons
+- @kornelski
+- @lf-
+- @lewisbelcher
+- @ronan-d
+- @weirane
+- @heymind
+- @marcianx
+- @Nukesor
+
+### Added
+
+- nom is now regularly fuzzed through the OSSFuzz project
+
+### Changed
+
+- lots of documentation fixes
+- relax trait bounds
+- workarounds for dependency issues with bitvec and memchr
+
+## 6.1.2 - 2021-02-15
+
+### Changed
+
+- Fix cargo feature usage in previous release
+
+## 6.1.1 - 2021-02-15
+
+### Thanks
+
+This release was done thanks to the hard work of (by order of appearance in the commit list):
+
+- @nickelc
+
+### Changed
+
+- Fix dependenciy incompatibilities: Restrict the bitvec->funty dependency to <=1.1
+
+## 6.1.0 - 2021-01-23
+
+### Thanks
+
+This release was done thanks to the hard work of (by order of appearance in the commit list):
+
+- @sachaarbonel
+- @vallentin
+- @Lucretiel
+- @meiomorphism
+- @jufajardini
+- @neithernut
+- @drwilco
+
+### Changed
+
+- readme and documentation fixes
+- rewrite of fold_many_m_n
+- relax trait bounds on some parsers
+- implement `std::error::Error` on `VerboseError`
+
+
+## 6.0.1 - 2020-11-24
+
+### Thanks
+
+This release was done thanks to the hard work of (by order of appearance in the commit list):
+
+- @Leonqn
+- @nickelc
+- @toshokan
+- @juchiast
+- @shssoichiro
+- @jlkiri
+- @chifflier
+- @fkloiber
+- @Kaoet
+- @Matthew Plant
+
+### Added
+
+- `ErrorConvert` implementation for `VerboseError`
+
+### Changed
+
+- CI fixes
+- `fold_many*` now accept `FnMut` for the accumulation function
+- relaxed input bounds on `length_count`
+
+# Fixed
+
+- documentation fixes
+- the `#[deprecated]` attribute was removed from traits because it does not compile anymore on nightly
+- bits and bytes combinators from the bits modules are now converted to use `FnMut`
+
+## 6.0.0 - 2020-10-31
+
+### Thanks
+
+This release was done thanks to the hard work of (by order of appearance in the commit list):
+- @chifflier
+- @shepmaster
+- @amerelo
+- @razican
+- @Palladinium
+- @0ndorio
+- Sebastian Zivota
+- @keruspe
+- @devonhollowood
+- @parasyte
+- @nnt0
+- @AntoineCezar
+- @GuillaumeGomez
+- @eijebong
+- @stadelmanma
+- @sphynx
+- @snawaz
+- @fosskers
+- @JamesHarrison
+- @calebsander
+- @jthornber
+- @ahmedcharles
+- @rljacobson
+- @benkay86
+- @georgeclaghorn
+- @TianyiShi2001
+- @shnewto
+- @alfriadox
+- @resistor
+- @myrrlyn
+- @chipsenkbeil
+- @ruza-net
+- @fanf2
+- @jameysharp
+- @FallenWarrior2k
+- @jmg-duarte
+- @ericseppanen
+- @hbina
+- Andreas Molzer
+- @nickelc
+- @bgourlie
+
+## Notable changes
+
+This release is a more polished version of nom 5, that came with a focus on
+function parsers, by relaxing the requirements: combinators will return a
+`impl FnMut` instead of `impl Fn`, allowing closures that change their context,
+and parsers can be any type now, as long as they implement the new `Parser` trait.
+That parser trait also comes with a few helper methods.
+
+Error management was often a pain point, so a lot of work went into making it easier.
+Now it integrates with `std:error::Error`, the `IResult::finish()` method allows you
+to convert to a more usable type, the `into` combinator can convert the error type
+if there's a `From` implementation, and there are more specific error traits like
+`ContextError` for the `context` combinator, and `FromExternalError` for `map_res`.
+While the `VerboseError` type and its `convert_error` function saw some changes,
+not many features ill be added to it, instead you are encouraged to build the error
+type that corresponds to your needs if you are building a language parser.
+
+This version also integrates with the excellent [bitvec](https://crates.io/crates/bitvec)
+crate for better bit level parsing. This part of nom was not great and a bit of a hack,
+so this will give better options for those parsers.
+
+At last, documentation! There are now more code examples, functions and macros that require
+specific cargo features are now clearly indicated, and there's a new `recipes` module
+containing example patterns.
+
+### Breaking changes
+
+- the minimal Rust version is now 1.44 (1.37 if building without the `alloc` or `std` features)
+- streaming parsers return the number of additional bytes they need, not the total. This was supposed to be the case everywhere, but some parsers were forgotten
+- removed the `regexp_macros` cargo feature
+- the `context` combinator is not linked to `ParseError` anymore, instead it come with its own `ContextError` trait
+- `Needed::Size` now contains a `NonZeroUsize`, so we can reduce the structure's size by 8 bytes. When upgrading, `Needed::Size(number)` can be replaced with `Needed::new(number)`
+- there is now a more general `Parser` trait, so parsers can be something else than a function. This trait also comes with combinator methods like `map`, `flat_map`, `or`. Since it is implemented on `Fn*` traits, it should not affect existing code too much
+- combinators that returned a `impl Fn` now return a `impl FnMut` to allow parser closures that capture some mutable value from the context
+- `separated_list` is now `separated_list0`
+- removed the deprecated `methods` module
+- removed the deprecated `whitespace` module
+- the default error type is now a struct (`nom::error::Error`) instead of a tuple
+- the `FromExternalError` allows wrapping the error returned by the function in the `map_res` combinator
+- renamed the `dbg!` macro to avoid conflicts with `std::dbg!`
+- `separated_list` now allows empty elements
+
+
+### Added
+
+- function version of regex parsers
+- `fill`: attempts to fill the output slice passed as argument
+- `success`: returns a value without consuming the input
+- `satisfy`: checks a predicate over the next character
+- `eof` function combinator
+- `consumed`: returns the produced value and the consumed input
+- `length_count` function combinator
+- `into`: converts a parser's output and error values if `From` implementations are available
+- `IResult::finish()`: converts a parser's result to `Result<(I, O), E>` by removing the distinction between `Error` and `Failure` and panicking on `Incomplete`
+- non macro versions of `u16`, `i32`, etc, with configurable endianness
+- `is_newline` function
+- `std::error::Error` implementation for nom's error types
+- recipes section of the documentation, outlining common patterns in nom
+- custom errors example
+- bitstream parsing with the `BitSlice` type from the bitvec crate
+- native endianness parsers
+- github actions for CI
+
+### Changed
+
+- allows lexical-core 0.7
+- number parsers are now generic over the input type
+- stabilized the `alloc` feature
+- `convert_error` accepts a type that derefs to `&str`
+- the JSON example now follows the spec better
+
+### Fixed
+- use `fold_many0c` in the `fold_many0` macro
+
 ## 5.1.1 - 2020-02-24
 
 ### Thanks
@@ -57,7 +361,7 @@
 - `convert_error` optimization
 - `alt` optimization
 
-## 5.0.1 - 2020-08-22
+## 5.0.1 - 2019-08-22
 
 ### Thanks
 
@@ -852,7 +1156,7 @@
 ## 0.3.11 - 2015-08-04
 
 ### Thanks
-- @bluss for remarking that the crate included random junk lying non commited in my local repository
+- @bluss for remarking that the crate included random junk lying non committed in my local repository
 
 ### Fixed
 - cleanup of my local repository will ship less files in the crates, resulting in a smaller download
@@ -915,7 +1219,7 @@
 ### Added
 - documentation for a few functions
 - the consumer trait now requires the `failed(&self, error_code)` method in case of parsing error
-- `named!` now handles thge alternative `named!(pub fun_name<OutputType>, ...)`
+- `named!` now handles the alternative `named!(pub fun_name<OutputType>, ...)`
 
 ### Fixed
 - `filter!` now returns the whole input if the filter function never returned false
@@ -1116,7 +1420,15 @@
 
 ## Compare code
 
-* [unreleased](https://github.com/Geal/nom/compare/5.1.1...HEAD)
+* [unreleased](https://github.com/Geal/nom/compare/7.0.0...HEAD)
+* [7.0.0](https://github.com/Geal/nom/compare/6.2.1...7.0.0)
+* [6.2.1](https://github.com/Geal/nom/compare/6.2.0...6.2.1)
+* [6.2.0](https://github.com/Geal/nom/compare/6.1.2...6.2.0)
+* [6.1.2](https://github.com/Geal/nom/compare/6.1.1...6.1.2)
+* [6.1.1](https://github.com/Geal/nom/compare/6.1.0...6.1.1)
+* [6.1.0](https://github.com/Geal/nom/compare/6.0.1...6.1.0)
+* [6.0.1](https://github.com/Geal/nom/compare/6.0.0...6.0.1)
+* [6.0.0](https://github.com/Geal/nom/compare/5.1.1...6.0.0)
 * [5.1.1](https://github.com/Geal/nom/compare/5.1.0...5.1.1)
 * [5.1.0](https://github.com/Geal/nom/compare/5.0.1...5.1.0)
 * [5.0.1](https://github.com/Geal/nom/compare/5.0.0...5.0.1)
diff --git a/Cargo.toml b/Cargo.toml
index 56bacd7..6e38fa0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,19 +3,18 @@
 # When uploading crates to the registry Cargo will automatically
 # "normalize" Cargo.toml files for maximal compatibility
 # with all versions of Cargo and also rewrite `path` dependencies
-# to registry (e.g., crates.io) dependencies
+# to registry (e.g., crates.io) dependencies.
 #
-# If you believe there's an error in this file please file an
-# issue against the rust-lang/cargo repository. If you're
-# editing this file be aware that the upstream Cargo.toml
-# will likely look very different (and much more reasonable)
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
 
 [package]
 edition = "2018"
 name = "nom"
-version = "5.1.2"
+version = "7.1.0"
 authors = ["contact@geoffroycouprie.com"]
-include = ["CHANGELOG.md", "LICENSE", "README.md", ".gitignore", ".travis.yml", "Cargo.toml", "src/*.rs", "src/*/*.rs", "tests/*.rs", "build.rs"]
+include = ["CHANGELOG.md", "LICENSE", "README.md", ".gitignore", "Cargo.toml", "src/*.rs", "src/*/*.rs", "tests/*.rs", "doc/nom_recipes.md", "build.rs"]
 autoexamples = false
 description = "A byte-oriented, zero-copy, parser combinators library"
 documentation = "https://docs.rs/nom"
@@ -26,21 +25,22 @@
 repository = "https://github.com/Geal/nom"
 [package.metadata.docs.rs]
 all-features = true
-features = ["alloc", "std", "regexp", "regexp_macros", "lexical"]
+features = ["alloc", "std", "docsrs"]
 [profile.bench]
 lto = true
 codegen-units = 1
 debug = true
 
-[lib]
-bench = false
-
 [[example]]
 name = "json"
 path = "examples/json.rs"
 required-features = ["alloc"]
 
 [[example]]
+name = "iterator"
+path = "examples/iterator.rs"
+
+[[example]]
 name = "s_expression"
 path = "examples/s_expression.rs"
 required-features = ["alloc"]
@@ -58,9 +58,6 @@
 required-features = ["alloc"]
 
 [[test]]
-name = "blockbuf-arithmetic"
-
-[[test]]
 name = "css"
 
 [[test]]
@@ -70,9 +67,6 @@
 name = "float"
 
 [[test]]
-name = "inference"
-
-[[test]]
 name = "ini"
 required-features = ["alloc"]
 
@@ -82,7 +76,7 @@
 
 [[test]]
 name = "issues"
-required-features = ["alloc", "regexp_macros"]
+required-features = ["alloc"]
 
 [[test]]
 name = "json"
@@ -96,79 +90,34 @@
 required-features = ["alloc"]
 
 [[test]]
-name = "named_args"
-
-[[test]]
 name = "overflow"
 
 [[test]]
 name = "reborrow_fold"
 
 [[test]]
-name = "test1"
-
-[[bench]]
-name = "arithmetic"
-path = "benches/arithmetic.rs"
-harness = false
-
-[[bench]]
-name = "http"
-path = "benches/http.rs"
-harness = false
-
-[[bench]]
-name = "ini"
-path = "benches/ini.rs"
-harness = false
-
-[[bench]]
-name = "ini_complete"
-path = "benches/ini_complete.rs"
-harness = false
-
-[[bench]]
-name = "ini_str"
-path = "benches/ini_str.rs"
-harness = false
-
-[[bench]]
-name = "json"
-path = "benches/json.rs"
-harness = false
-[dependencies.lazy_static]
-version = "^1.0"
-optional = true
-
-[dependencies.lexical-core]
-version = ">= 0.6, < 0.8"
-optional = true
-
+name = "fnmut"
+required-features = ["alloc"]
 [dependencies.memchr]
-version = "^2.0"
+version = "2.3"
 default-features = false
 
-[dependencies.regex]
-version = "^1.0"
-optional = true
-[dev-dependencies.criterion]
-version = "0.2"
-
+[dependencies.minimal-lexical]
+version = "0.2.0"
+default-features = false
 [dev-dependencies.doc-comment]
 version = "0.3"
 
-[dev-dependencies.jemallocator]
-version = "^0.1"
+[dev-dependencies.proptest]
+version = "1.0.0"
 [build-dependencies.version_check]
 version = "0.9"
 
 [features]
 alloc = []
-default = ["std", "lexical"]
-lexical = ["lexical-core"]
-regexp = ["regex"]
-regexp_macros = ["regexp", "lazy_static"]
-std = ["alloc", "memchr/use_std"]
+default = ["std"]
+docsrs = []
+std = ["alloc", "memchr/std", "minimal-lexical/std"]
 [badges.coveralls]
 branch = "master"
 repository = "Geal/nom"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index fafc6b3..4e5b011 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,7 +1,7 @@
 [package]
 
 name = "nom"
-version = "5.1.2"
+version = "7.1.0"
 authors = [ "contact@geoffroycouprie.com" ]
 description = "A byte-oriented, zero-copy, parser combinators library"
 license = "MIT"
@@ -18,48 +18,37 @@
   "LICENSE",
   "README.md",
   ".gitignore",
-  ".travis.yml",
   "Cargo.toml",
   "src/*.rs",
   "src/*/*.rs",
   "tests/*.rs",
+  "doc/nom_recipes.md",
   "build.rs"
 ]
 
 [features]
 alloc = []
-std = ["alloc", "memchr/use_std"]
-default = ["std", "lexical"]
-regexp = ["regex"]
-regexp_macros = ["regexp", "lazy_static"]
-lexical = ["lexical-core"]
+std = ["alloc", "memchr/std", "minimal-lexical/std"]
+default = ["std"]
+docsrs = []
 
-[dependencies.regex]
-version = "^1.0"
-optional = true
-
-[dependencies.lazy_static]
-version = "^1.0"
-optional = true
-
-[dependencies.memchr]
-version = "^2.0"
+[dependencies.minimal-lexical]
+version = "0.2.0"
 default-features = false
 
-[dependencies.lexical-core]
-version = ">= 0.6, < 0.8"
-optional = true
+[dependencies.memchr]
+version = "2.3"
+default-features = false
 
 [dev-dependencies]
-criterion = "0.2"
-jemallocator = "^0.1"
 doc-comment = "0.3"
+proptest = "1.0.0"
 
 [build-dependencies]
 version_check = "0.9"
 
 [package.metadata.docs.rs]
-features = [ "alloc", "std", "regexp", "regexp_macros", "lexical"]
+features = ["alloc", "std", "docsrs"]
 all-features = true
 
 [profile.bench]
@@ -67,9 +56,6 @@
 lto = true
 codegen-units = 1
 
-[lib]
-bench = false
-
 [[test]]
 name = "arithmetic"
 
@@ -78,9 +64,6 @@
 required-features = ["alloc"]
 
 [[test]]
-name = "blockbuf-arithmetic"
-
-[[test]]
 name = "css"
 
 [[test]]
@@ -90,9 +73,6 @@
 name = "float"
 
 [[test]]
-name = "inference"
-
-[[test]]
 name = "ini"
 required-features = ["alloc"]
 
@@ -102,7 +82,7 @@
 
 [[test]]
 name = "issues"
-required-features = ["alloc", "regexp_macros"]
+required-features = ["alloc"]
 
 [[test]]
 name = "json"
@@ -116,54 +96,23 @@
 required-features = ["alloc"]
 
 [[test]]
-name = "named_args"
-
-[[test]]
 name = "overflow"
 
 [[test]]
 name = "reborrow_fold"
 
 [[test]]
-name = "test1"
-
-[[bench]]
-name = "arithmetic"
-path = "benches/arithmetic.rs"
-harness = false
-
-[[bench]]
-name = "http"
-path = "benches/http.rs"
-harness = false
-
-[[bench]]
-name = "ini"
-path = "benches/ini.rs"
-harness = false
-
-[[bench]]
-name = "ini_complete"
-path = "benches/ini_complete.rs"
-harness = false
-
-[[bench]]
-name = "ini_str"
-path = "benches/ini_str.rs"
-harness = false
-
-[[bench]]
-name = "json"
-path = "benches/json.rs"
-harness = false
+name = "fnmut"
+required-features = ["alloc"]
 
 [[example]]
 name = "json"
 required-features = ["alloc"]
 path = "examples/json.rs"
 
-#[[example]]
-#name = "iterator"
+[[example]]
+name = "iterator"
+path = "examples/iterator.rs"
 
 [[example]]
 name = "s_expression"
@@ -179,3 +128,6 @@
 travis-ci = { repository = "Geal/nom" }
 coveralls = { repository = "Geal/nom", branch = "master", service = "github" }
 maintenance = { status = "actively-developed" }
+
+[workspace]
+members = [".", "benchmarks/"]
diff --git a/METADATA b/METADATA
index 7a8bf59..504894c 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/nom/nom-5.1.2.crate"
+    value: "https://static.crates.io/crates/nom/nom-7.1.0.crate"
   }
-  version: "5.1.2"
+  version: "7.1.0"
   license_type: NOTICE
   last_upgrade_date {
-    year: 2020
-    month: 10
-    day: 26
+    year: 2022
+    month: 3
+    day: 1
   }
 }
diff --git a/README.md b/README.md
index a398317..1a95f96 100644
--- a/README.md
+++ b/README.md
@@ -2,10 +2,10 @@
 
 [![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
 [![Join the chat at https://gitter.im/Geal/nom](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Geal/nom?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
-[![Build Status](https://travis-ci.org/Geal/nom.svg?branch=master)](https://travis-ci.org/Geal/nom)
-[![Coverage Status](https://coveralls.io/repos/Geal/nom/badge.svg?branch=master)](https://coveralls.io/r/Geal/nom?branch=master)
+[![Build Status](https://github.com/Geal/nom/actions/workflows/ci.yml/badge.svg)](https://github.com/Geal/nom/actions/workflows/ci.yml)
+[![Coverage Status](https://coveralls.io/repos/github/Geal/nom/badge.svg?branch=master)](https://coveralls.io/github/Geal/nom?branch=master)
 [![Crates.io Version](https://img.shields.io/crates/v/nom.svg)](https://crates.io/crates/nom)
-[![Minimum rustc version](https://img.shields.io/badge/rustc-1.31.0+-lightgray.svg)](#rust-version-requirements)
+[![Minimum rustc version](https://img.shields.io/badge/rustc-1.48.0+-lightgray.svg)](#rust-version-requirements)
 
 nom is a parser combinators library written in Rust. Its goal is to provide tools
 to build safe parsers without compromising the speed or memory consumption. To
@@ -75,24 +75,24 @@
 
 - [Reference documentation](https://docs.rs/nom)
 - [Various design documents and tutorials](https://github.com/Geal/nom/tree/master/doc)
-- [list of combinators and their behaviour](https://github.com/Geal/nom/blob/master/doc/choosing_a_combinator.md)
+- [List of combinators and their behaviour](https://github.com/Geal/nom/blob/master/doc/choosing_a_combinator.md)
 
-If you need any help developing your parsers, please ping `geal` on IRC (freenode, geeknode, oftc), go to `#nom-parsers` on Freenode IRC, or on the [Gitter chat room](https://gitter.im/Geal/nom).
+If you need any help developing your parsers, please ping `geal` on IRC (libera, geeknode, oftc), go to `#nom-parsers` on Libera IRC, or on the [Gitter chat room](https://gitter.im/Geal/nom).
 
 ## Why use nom
 
 If you want to write:
 
-### binary format parsers
+### Binary format parsers
 
 nom was designed to properly parse binary formats from the beginning. Compared
 to the usual handwritten C parsers, nom parsers are just as fast, free from
 buffer overflow vulnerabilities, and handle common patterns for you:
 
 - [TLV](https://en.wikipedia.org/wiki/Type-length-value)
-- bit level parsing
-- hexadecimal viewer in the debugging macros for easy data analysis
-- streaming parsers for network formats and huge files
+- Bit level parsing
+- Hexadecimal viewer in the debugging macros for easy data analysis
+- Streaming parsers for network formats and huge files
 
 Example projects:
 
@@ -106,10 +106,10 @@
 well with text formats. From line based formats like CSV, to more complex, nested
 formats such as JSON, nom can manage it, and provides you with useful tools:
 
-- fast case insensitive comparison
-- recognizers for escaped strings
-- regular expressions can be embedded in nom parsers to represent complex character patterns succinctly
-- special care has been given to managing non ASCII characters properly
+- Fast case insensitive comparison
+- Recognizers for escaped strings
+- Regular expressions can be embedded in nom parsers to represent complex character patterns succinctly
+- Special care has been given to managing non ASCII characters properly
 
 Example projects:
 
@@ -139,7 +139,7 @@
 While a lot of formats (and the code handling them) assume that they can fit
 the complete data in memory, there are formats for which we only get a part
 of the data at once, like network formats, or huge files.
-nom has been designed for a correct behaviour with partial data: if there is
+nom has been designed for a correct behaviour with partial data: If there is
 not enough data to decide, nom will tell you it needs more instead of silently
 returning a wrong result. Whether your data comes entirely or in chunks, the
 result should be the same.
@@ -149,7 +149,7 @@
 Example projects:
 
 - [HTTP proxy](https://github.com/sozu-proxy/sozu/blob/master/lib/src/protocol/http/parser.rs)
-- [using nom with generators](https://github.com/Geal/generator_nom)
+- [Using nom with generators](https://github.com/Geal/generator_nom)
 
 ## Parser combinators
 
@@ -158,39 +158,38 @@
 [yacc](https://en.wikipedia.org/wiki/Yacc). Instead of writing the grammar
 in a separate file and generating the corresponding code, you use very
 small functions with very specific purpose, like "take 5 bytes", or
-"recognize the word 'HTTP'", and assemble then in meaningful patterns
+"recognize the word 'HTTP'", and assemble them in meaningful patterns
 like "recognize 'HTTP', then a space, then a version".
 The resulting code is small, and looks like the grammar you would have
 written with other parser approaches.
 
 This has a few advantages:
 
-- the parsers are small and easy to write
-- the parsers components are easy to reuse (if they're general enough, please add them to nom!)
-- the parsers components are easy to test separately (unit tests and property-based tests)
-- the parser combination code looks close to the grammar you would have written
-- you can build partial parsers, specific to the data you need at the moment, and ignore the rest
+- The parsers are small and easy to write
+- The parsers components are easy to reuse (if they're general enough, please add them to nom!)
+- The parsers components are easy to test separately (unit tests and property-based tests)
+- The parser combination code looks close to the grammar you would have written
+- You can build partial parsers, specific to the data you need at the moment, and ignore the rest
 
 ## Technical features
 
 nom parsers are for:
-- [x] **byte-oriented**: the basic type is `&[u8]` and parsers will work as much as possible on byte array slices (but are not limited to them)
+- [x] **byte-oriented**: The basic type is `&[u8]` and parsers will work as much as possible on byte array slices (but are not limited to them)
 - [x] **bit-oriented**: nom can address a byte slice as a bit stream
-- [x] **string-oriented**: the same kind of combinators can apply on UTF-8 strings as well
-- [x] **zero-copy**: if a parser returns a subset of its input data, it will return a slice of that input, without copying
+- [x] **string-oriented**: The same kind of combinators can apply on UTF-8 strings as well
+- [x] **zero-copy**: If a parser returns a subset of its input data, it will return a slice of that input, without copying
 - [x] **streaming**: nom can work on partial data and detect when it needs more data to produce a correct result
-- [x] **descriptive errors**: the parsers can aggregate a list of error codes with pointers to the incriminated input slice. Those error lists can be pattern matched to provide useful messages.
-- [x] **custom error types**: you can provide a specific type to improve errors returned by parsers
+- [x] **descriptive errors**: The parsers can aggregate a list of error codes with pointers to the incriminated input slice. Those error lists can be pattern matched to provide useful messages.
+- [x] **custom error types**: You can provide a specific type to improve errors returned by parsers
 - [x] **safe parsing**: nom leverages Rust's safe memory handling and powerful types, and parsers are routinely fuzzed and tested with real world data. So far, the only flaws found by fuzzing were in code written outside of nom
-- [x] **speed**: benchmarks have shown that nom parsers often outperform many parser combinators library like Parsec and attoparsec, some regular expression engines and even handwritten C parsers
+- [x] **speed**: Benchmarks have shown that nom parsers often outperform many parser combinators library like Parsec and attoparsec, some regular expression engines and even handwritten C parsers
 
 Some benchmarks are available on [Github](https://github.com/Geal/nom_benchmarks).
 
 ## Rust version requirements
 
-The 5.0 series of nom requires **Rustc version 1.31 or greater**.
+The 7.0 series of nom supports **Rustc version 1.48 or greater**. It is known to work properly on Rust 1.41.1 but there is no guarantee it will stay the case through this major release.
 
-Travis CI always has a build with a pinned version of Rustc matching the oldest supported Rust release.
 The current policy is that this will only be updated in the next major nom release.
 
 ## Installation
@@ -199,102 +198,112 @@
 
 ```toml
 [dependencies]
-nom = "5"
+nom = "7"
 ```
 
-Then include it in your code like this:
-
-```rust,ignore
-#[macro_use]
-extern crate nom;
-```
-
-**NOTE: if you have existing code using nom below the 5.0 version, please take a look
-at the [upgrade documentation](https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_5.md)
-to handle the breaking changes.**
-
 There are a few compilation features:
 
-* `std`: (activated by default) if disabled, nom can work in `no_std` builds
-* `regexp`: enables regular expression parsers with the `regex` crate
-* `regexp_macros`: enables regular expression parsers with the `regex` and `regex_macros` crates. Regular expressions can be defined at compile time, but it requires a nightly version of rustc
+* `alloc`: (activated by default) if disabled, nom can work in `no_std` builds without memory allocators. If enabled, combinators that allocate (like `many0`) will be available
+* `std`: (activated by default, activates `alloc` too) if disabled, nom can work in `no_std` builds
 
-You can activate those features like this:
+You can configure those features like this:
 
 ```toml
 [dependencies.nom]
-version = "^5"
-features = ["regexp"]
+version = "7"
+default-features = false
+features = ["alloc"]
 ```
 
 # Related projects
 
-- [get line and column info in nom's input type](https://github.com/fflorent/nom_locate)
-- [using nom as lexer and parser](https://github.com/Rydgel/monkey-rust)
+- [Get line and column info in nom's input type](https://github.com/fflorent/nom_locate)
+- [Using nom as lexer and parser](https://github.com/Rydgel/monkey-rust)
 
 # Parsers written with nom
 
 Here is a (non exhaustive) list of known projects using nom:
 
-- Text file formats:
-  * [Ceph Crush](https://github.com/cholcombe973/crushtool)
-  * [Cronenberg](https://github.com/ayrat555/cronenberg)
-  * [XFS Runtime Stats](https://github.com/ChrisMacNaughton/xfs-rs)
-  * [CSV](https://github.com/GuillaumeGomez/csv-parser)
-  * [FASTQ](https://github.com/elij/fastq.rs)
-  * [INI](https://github.com/Geal/nom/blob/master/tests/ini.rs)
-  * [ISO 8601 dates](https://github.com/badboy/iso8601)
-  * [libconfig-like configuration file format](https://github.com/filipegoncalves/rust-config)
-  * [Web archive](https://github.com/sbeckeriv/warc_nom_parser)
-  * [proto files](https://github.com/tafia/protobuf-parser)
-  * [Fountain screenplay markup](https://github.com/adamchalmers/fountain-rs)
+- Text file formats: [Ceph Crush](https://github.com/cholcombe973/crushtool),
+[Cronenberg](https://github.com/ayrat555/cronenberg),
+[XFS Runtime Stats](https://github.com/ChrisMacNaughton/xfs-rs),
+[CSV](https://github.com/GuillaumeGomez/csv-parser),
+[FASTA](https://github.com/TianyiShi2001/nom-fasta),
+[FASTQ](https://github.com/elij/fastq.rs),
+[INI](https://github.com/Geal/nom/blob/master/tests/ini.rs),
+[ISO 8601 dates](https://github.com/badboy/iso8601),
+[libconfig-like configuration file format](https://github.com/filipegoncalves/rust-config),
+[Web archive](https://github.com/sbeckeriv/warc_nom_parser),
+[PDB](https://github.com/TianyiShi2001/nom-pdb),
+[proto files](https://github.com/tafia/protobuf-parser),
+[Fountain screenplay markup](https://github.com/adamchalmers/fountain-rs),
+[vimwiki](https://github.com/chipsenkbeil/vimwiki-server/tree/master/vimwiki) & [vimwiki_macros](https://github.com/chipsenkbeil/vimwiki-server/tree/master/vimwiki_macros)
 - Programming languages:
-  * [PHP](https://github.com/tagua-vm/parser)
-  * [Basic Calculator](https://github.com/balajisivaraman/basic_calculator_rs)
-  * [GLSL](https://github.com/phaazon/glsl)
-  * [Lua](https://github.com/doomrobo/nom-lua53)
-  * [Python](https://github.com/ProgVal/rust-python-parser)
-  * [SQL](https://github.com/ms705/nom-sql)
-  * [Elm](https://github.com/cout970/Elm-interpreter)
-  * [SystemVerilog](https://github.com/dalance/sv-parser)
-  * [Turtle](https://github.com/vandenoever/rome/tree/master/src/io/turtle)
-  * [CSML](https://github.com/CSML-by-Clevy/csml-interpreter)
-- Interface definition formats:
-  * [Thrift](https://github.com/thehydroimpulse/thrust)
+[PHP](https://github.com/tagua-vm/parser),
+[Basic Calculator](https://github.com/balajisivaraman/basic_calculator_rs),
+[GLSL](https://github.com/phaazon/glsl),
+[Lua](https://github.com/doomrobo/nom-lua53),
+[Python](https://github.com/ProgVal/rust-python-parser),
+[SQL](https://github.com/ms705/nom-sql),
+[Elm](https://github.com/cout970/Elm-interpreter),
+[SystemVerilog](https://github.com/dalance/sv-parser),
+[Turtle](https://github.com/vandenoever/rome/tree/master/src/io/turtle),
+[CSML](https://github.com/CSML-by-Clevy/csml-interpreter),
+[Wasm](https://github.com/Strytyp/wasm-nom),
+[Pseudocode](https://github.com/Gungy2/pseudocode)
+- Interface definition formats: [Thrift](https://github.com/thehydroimpulse/thrust)
 - Audio, video and image formats:
-  * [GIF](https://github.com/Geal/gif.rs)
-  * [MagicaVoxel .vox](https://github.com/davidedmonds/dot_vox)
-  * [midi](https://github.com/derekdreery/nom-midi-rs)
-  * [SWF](https://github.com/open-flash/swf-parser)
-  * [WAVE](http://github.com/noise-Labs/wave)
+[GIF](https://github.com/Geal/gif.rs),
+[MagicaVoxel .vox](https://github.com/davidedmonds/dot_vox),
+[midi](https://github.com/derekdreery/nom-midi-rs),
+[SWF](https://github.com/open-flash/swf-parser),
+[WAVE](http://github.com/noise-Labs/wave),
+[Matroska (MKV)](https://github.com/rust-av/matroska)
 - Document formats:
-  * [TAR](https://github.com/Keruspe/tar-parser.rs)
-  * [GZ](https://github.com/nharward/nom-gzip)
+[TAR](https://github.com/Keruspe/tar-parser.rs),
+[GZ](https://github.com/nharward/nom-gzip)
 - Cryptographic formats:
-  * [X.509](https://github.com/rusticata/x509-parser)
+[X.509](https://github.com/rusticata/x509-parser)
 - Network protocol formats:
-  * [Bencode](https://github.com/jbaum98/bencode.rs)
-  * [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)
-  * [IMAP](https://github.com/djc/tokio-imap)
-  * [IRC](https://github.com/Detegr/RBot-parser)
-  * [Pcap-NG](https://github.com/richo/pcapng-rs)
-  * [Pcap](https://github.com/ithinuel/pcap-rs)
-  * [Pcap + PcapNG](https://github.com/rusticata/pcap-parser)
-  * [IKEv2](https://github.com/rusticata/ipsec-parser)
-  * [NTP](https://github.com/rusticata/ntp-parser)
-  * [SNMP](https://github.com/rusticata/snmp-parser)
-  * [Kerberos v5](https://github.com/rusticata/kerberos-parser)
-  * [DER](https://github.com/rusticata/der-parser)
-  * [TLS](https://github.com/rusticata/tls-parser)
-  * [IPFIX / Netflow v10](https://github.com/dominotree/rs-ipfix)
-  * [GTP](https://github.com/fuerstenau/gorrosion-gtp)
+[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),
+[IMAP](https://github.com/djc/tokio-imap),
+[IRC](https://github.com/Detegr/RBot-parser),
+[Pcap-NG](https://github.com/richo/pcapng-rs),
+[Pcap](https://github.com/ithinuel/pcap-rs),
+[Pcap + PcapNG](https://github.com/rusticata/pcap-parser),
+[IKEv2](https://github.com/rusticata/ipsec-parser),
+[NTP](https://github.com/rusticata/ntp-parser),
+[SNMP](https://github.com/rusticata/snmp-parser),
+[Kerberos v5](https://github.com/rusticata/kerberos-parser),
+[DER](https://github.com/rusticata/der-parser),
+[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),
+[Prometheus](https://github.com/timberio/vector/blob/master/lib/prometheus-parser/src/line.rs)
 - Language specifications:
-  * [BNF](https://github.com/snewt/bnf)
+[BNF](https://github.com/snewt/bnf)
 - Misc formats:
-  * [Gameboy ROM](https://github.com/MarkMcCaskey/gameboy-rom-parser)
+[Gameboy ROM](https://github.com/MarkMcCaskey/gameboy-rom-parser),
+[ANT FIT](https://github.com/stadelmanma/fitparse-rs),
+[Version Numbers](https://github.com/fosskers/rs-versions),
+[Telcordia/Bellcore SR-4731 SOR OTDR files](https://github.com/JamesHarrison/otdrs),
+[MySQL binary log](https://github.com/PrivateRookie/boxercrab),
+[URI](https://github.com/Skasselbard/nom-uri),
+[Furigana](https://github.com/sachaarbonel/furigana.rs)
 
 Want to create a new parser using `nom`? A list of not yet implemented formats is available [here](https://github.com/Geal/nom/issues/14).
 
 Want to add your parser here? Create a pull request for it!
+
+# Contributors
+
+nom is the fruit of the work of many contributors over the years, many thanks for your help!
+
+<a href="https://github.com/geal/nom/graphs/contributors">
+  <img src="https://contributors-img.web.app/image?repo=geal/nom" />
+</a>
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 6716814..0b9e785 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -1,8 +1,48 @@
-// Generated by cargo2android.py for tests in Android.bp
+// Generated by update_crate_tests.py for tests that depend on this crate.
 {
+  "imports": [
+    {
+      "path": "external/rust/crates/libsqlite3-sys"
+    },
+    {
+      "path": "external/rust/crates/oid-registry"
+    },
+    {
+      "path": "external/rust/crates/rusticata-macros"
+    }
+  ],
   "presubmit": [
     {
-      "name": "libsqlite3-sys_device_test_src_lib"
+      "name": "keystore2_test"
+    },
+    {
+      "name": "legacykeystore_test"
+    },
+    {
+      "name": "libapkverify.integration_test"
+    },
+    {
+      "name": "libapkverify.test"
+    },
+    {
+      "name": "microdroid_manager_test"
+    }
+  ],
+  "presubmit-rust": [
+    {
+      "name": "keystore2_test"
+    },
+    {
+      "name": "legacykeystore_test"
+    },
+    {
+      "name": "libapkverify.integration_test"
+    },
+    {
+      "name": "libapkverify.test"
+    },
+    {
+      "name": "microdroid_manager_test"
     }
   ]
 }
diff --git a/build.rs b/build.rs
index 9743c90..0fb5784 100644
--- a/build.rs
+++ b/build.rs
@@ -1,7 +1,7 @@
 extern crate version_check;
 
 fn main() {
-  if version_check::is_min_version("1.28.0").unwrap_or(true) {
+  if version_check::is_min_version("1.44.0").unwrap_or(true) {
     println!("cargo:rustc-cfg=stable_i128");
   }
 }
diff --git a/cargo2android.json b/cargo2android.json
new file mode 100644
index 0000000..5fb7e33
--- /dev/null
+++ b/cargo2android.json
@@ -0,0 +1,5 @@
+{
+  "device": true,
+  "features": "alloc,std",
+  "run": true
+}
\ No newline at end of file
diff --git a/doc/nom_recipes.md b/doc/nom_recipes.md
new file mode 100644
index 0000000..8899485
--- /dev/null
+++ b/doc/nom_recipes.md
@@ -0,0 +1,395 @@
+# Nom Recipes
+
+These are short recipes for accomplishing common tasks with nom.
+
+* [Whitespace](#whitespace)
+  + [Wrapper combinators that eat whitespace before and after a parser](#wrapper-combinators-that-eat-whitespace-before-and-after-a-parser)
+* [Comments](#comments)
+  + [`// C++/EOL-style comments`](#-ceol-style-comments)
+  + [`/* C-style comments */`](#-c-style-comments-)
+* [Identifiers](#identifiers)
+  + [`Rust-Style Identifiers`](#rust-style-identifiers)
+* [Literal Values](#literal-values)
+  + [Escaped Strings](#escaped-strings)
+  + [Integers](#integers)
+    - [Hexadecimal](#hexadecimal)
+    - [Octal](#octal)
+    - [Binary](#binary)
+    - [Decimal](#decimal)
+  + [Floating Point Numbers](#floating-point-numbers)
+
+## Whitespace
+
+
+
+### Wrapper combinators that eat whitespace before and after a parser
+
+```rust
+use nom::{
+  IResult,
+  error::ParseError,
+  combinator::value,
+  sequence::delimited,
+  character::complete::multispace0,
+};
+
+/// 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 FnMut(&'a str) -> IResult<&'a str, O, E>
+  where
+  F: Fn(&'a str) -> IResult<&'a str, O, E>,
+{
+  delimited(
+    multispace0,
+    inner,
+    multispace0
+  )
+}
+```
+
+To eat only trailing whitespace, replace `delimited(...)` with `terminated(&inner, multispace0)`.
+Likewise, the eat only leading whitespace, replace `delimited(...)` with `preceded(multispace0,
+&inner)`. You can use your own parser instead of `multispace0` if you want to skip a different set
+of lexemes.
+
+## Comments
+
+### `// C++/EOL-style comments`
+
+This version uses `%` to start a comment, does not consume the newline character, and returns an
+output of `()`.
+
+```rust
+use nom::{
+  IResult,
+  error::ParseError,
+  combinator::value,
+  sequence::pair,
+  bytes::complete::is_not,
+  character::complete::char,
+};
+
+pub fn peol_comment<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, (), E>
+{
+  value(
+    (), // Output is thrown away.
+    pair(char('%'), is_not("\n\r"))
+  )(i)
+}
+```
+
+### `/* C-style comments */`
+
+Inline comments surrounded with sentinel tags `(*` and `*)`. This version returns an output of `()`
+and does not handle nested comments.
+
+```rust
+use nom::{
+  IResult,
+  error::ParseError,
+  combinator::value,
+  sequence::tuple,
+  bytes::complete::{tag, take_until},
+};
+
+pub fn pinline_comment<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, (), E> {
+  value(
+    (), // Output is thrown away.
+    tuple((
+      tag("(*"),
+      take_until("*)"),
+      tag("*)")
+    ))
+  )(i)
+}
+```
+
+## Identifiers
+
+### `Rust-Style Identifiers`
+
+Parsing identifiers that may start with a letter (or underscore) and may contain underscores,
+letters and numbers may be parsed like this:
+
+```rust
+use nom::{
+  IResult,
+  branch::alt,
+  multi::many0,
+  combinator::recognize,
+  sequence::pair,
+  character::complete::{alpha1, alphanumeric1},
+  bytes::complete::tag,
+};
+
+pub fn identifier(input: &str) -> IResult<&str, &str> {
+  recognize(
+    pair(
+      alt((alpha1, tag("_"))),
+      many0(alt((alphanumeric1, tag("_"))))
+    )
+  )(input)
+}
+```
+
+Let's say we apply this to the identifier `hello_world123abc`. The first `alt` parser would
+recognize `h`. The `pair` combinator ensures that `ello_world123abc` will be piped to the next
+`alphanumeric0` parser, which recognizes every remaining character. However, the `pair` combinator
+returns a tuple of the results of its sub-parsers. The `recognize` parser produces a `&str` of the
+input text that was parsed, which in this case is the entire `&str` `hello_world123abc`.
+
+## Literal Values
+
+### Escaped Strings
+
+This is [one of the examples](https://github.com/Geal/nom/blob/master/examples/string.rs) in the
+examples directory.
+
+### Integers
+
+The following recipes all return string slices rather than integer values. How to obtain an
+integer value instead is demonstrated for hexadecimal integers. The others are similar.
+
+The parsers allow the grouping character `_`, which allows one to group the digits by byte, for
+example: `0xA4_3F_11_28`. If you prefer to exclude the `_` character, the lambda to convert from a
+string slice to an integer value is slightly simpler. You can also strip the `_` from the string
+slice that is returned, which is demonstrated in the second hexdecimal number parser.
+
+If you wish to limit the number of digits in a valid integer literal, replace `many1` with
+`many_m_n` in the recipes.
+
+#### Hexadecimal
+
+The parser outputs the string slice of the digits without the leading `0x`/`0X`.
+
+```rust
+use nom::{
+  IResult,
+  branch::alt,
+  multi::{many0, many1},
+  combinator::recognize,
+  sequence::{preceded, terminated},
+  character::complete::{char, one_of},
+  bytes::complete::tag,
+};
+
+fn hexadecimal(input: &str) -> IResult<&str, &str> { // <'a, E: ParseError<&'a str>>
+  preceded(
+    alt((tag("0x"), tag("0X"))),
+    recognize(
+      many1(
+        terminated(one_of("0123456789abcdefABCDEF"), many0(char('_')))
+      )
+    )
+  )(input)
+}
+```
+
+If you want it to return the integer value instead, use map:
+
+```rust
+use nom::{
+  IResult,
+  branch::alt,
+  multi::{many0, many1},
+  combinator::{map_res, recognize},
+  sequence::{preceded, terminated},
+  character::complete::{char, one_of},
+  bytes::complete::tag,
+};
+
+fn hexadecimal_value(input: &str) -> IResult<&str, i64> {
+  map_res(
+    preceded(
+      alt((tag("0x"), tag("0X"))),
+      recognize(
+        many1(
+          terminated(one_of("0123456789abcdefABCDEF"), many0(char('_')))
+        )
+      )
+    ),
+    |out: &str| i64::from_str_radix(&str::replace(&out, "_", ""), 16)
+  )(input)
+}
+```
+
+#### Octal
+
+```rust
+use nom::{
+  IResult,
+  branch::alt,
+  multi::{many0, many1},
+  combinator::recognize,
+  sequence::{preceded, terminated},
+  character::complete::{char, one_of},
+  bytes::complete::tag,
+};
+
+fn octal(input: &str) -> IResult<&str, &str> {
+  preceded(
+    alt((tag("0o"), tag("0O"))),
+    recognize(
+      many1(
+        terminated(one_of("01234567"), many0(char('_')))
+      )
+    )
+  )(input)
+}
+```
+
+#### Binary
+
+```rust
+use nom::{
+  IResult,
+  branch::alt,
+  multi::{many0, many1},
+  combinator::recognize,
+  sequence::{preceded, terminated},
+  character::complete::{char, one_of},
+  bytes::complete::tag,
+};
+
+fn binary(input: &str) -> IResult<&str, &str> {
+  preceded(
+    alt((tag("0b"), tag("0B"))),
+    recognize(
+      many1(
+        terminated(one_of("01"), many0(char('_')))
+      )
+    )
+  )(input)
+}
+```
+
+#### Decimal
+
+```rust
+use nom::{
+  IResult,
+  multi::{many0, many1},
+  combinator::recognize,
+  sequence::terminated,
+  character::complete::{char, one_of},
+};
+
+fn decimal(input: &str) -> IResult<&str, &str> {
+  recognize(
+    many1(
+      terminated(one_of("0123456789"), many0(char('_')))
+    )
+  )(input)
+}
+```
+
+### Floating Point Numbers
+
+The following is adapted from [the Python parser by Valentin Lorentz (ProgVal)](https://github.com/ProgVal/rust-python-parser/blob/master/src/numbers.rs).
+
+```rust
+use nom::{
+  IResult,
+  branch::alt,
+  multi::{many0, many1},
+  combinator::{opt, recognize},
+  sequence::{preceded, terminated, tuple},
+  character::complete::{char, one_of},
+};
+
+fn float(input: &str) -> IResult<&str, &str> {
+  alt((
+    // Case one: .42
+    recognize(
+      tuple((
+        char('.'),
+        decimal,
+        opt(tuple((
+          one_of("eE"),
+          opt(one_of("+-")),
+          decimal
+        )))
+      ))
+    )
+    , // Case two: 42e42 and 42.42e42
+    recognize(
+      tuple((
+        decimal,
+        opt(preceded(
+          char('.'),
+          decimal,
+        )),
+        one_of("eE"),
+        opt(one_of("+-")),
+        decimal
+      ))
+    )
+    , // Case three: 42. and 42.42
+    recognize(
+      tuple((
+        decimal,
+        char('.'),
+        opt(decimal)
+      ))
+    )
+  ))(input)
+}
+
+fn decimal(input: &str) -> IResult<&str, &str> {
+  recognize(
+    many1(
+      terminated(one_of("0123456789"), many0(char('_')))
+    )
+  )(input)
+}
+```
+
+# implementing FromStr
+
+The [FromStr trait](https://doc.rust-lang.org/std/str/trait.FromStr.html) provides
+a common interface to parse from a string.
+
+```rust
+use nom::{
+  IResult, Finish, error::Error,
+  bytes::complete::{tag, take_while},
+};
+use std::str::FromStr;
+
+// will recognize the name in "Hello, name!"
+fn parse_name(input: &str) -> IResult<&str, &str> {
+  let (i, _) = tag("Hello, ")(input)?;
+  let (i, name) = take_while(|c:char| c.is_alphabetic())(i)?;
+  let (i, _) = tag("!")(i)?;
+
+  Ok((i, name))
+}
+
+// with FromStr, the result cannot be a reference to the input, it must be owned
+#[derive(Debug)]
+pub struct Name(pub String);
+
+impl FromStr for Name {
+  // the error must be owned as well
+  type Err = Error<String>;
+
+  fn from_str(s: &str) -> Result<Self, Self::Err> {
+      match parse_name(s).finish() {
+          Ok((_remaining, name)) => Ok(Name(name.to_string())),
+          Err(Error { input, code }) => Err(Error {
+              input: input.to_string(),
+              code,
+          })
+      }
+  }
+}
+
+fn main() {
+  // parsed: Ok(Name("nom"))
+  println!("parsed: {:?}", "Hello, nom!".parse::<Name>());
+
+  // parsed: Err(Error { input: "123!", code: Tag })
+  println!("parsed: {:?}", "Hello, 123!".parse::<Name>());
+}
+```
+
diff --git a/src/bits/complete.rs b/src/bits/complete.rs
index f868ec2..b46bc7a 100644
--- a/src/bits/complete.rs
+++ b/src/bits/complete.rs
@@ -1,13 +1,38 @@
-//! bit level parsers
+//! Bit level parsers
 //!
 
 use crate::error::{ErrorKind, ParseError};
 use crate::internal::{Err, IResult};
-use crate::lib::std::ops::{AddAssign, RangeFrom, Shl, Shr, Div};
+use crate::lib::std::ops::{AddAssign, Div, RangeFrom, Shl, Shr};
 use crate::traits::{InputIter, InputLength, Slice, ToUsize};
 
-/// generates a parser taking `count` bits
-pub fn take<I, O, C, E: ParseError<(I, usize)>>(count: C) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
+/// Generates a parser taking `count` bits
+///
+/// # Example
+/// ```rust
+/// # use nom::bits::complete::take;
+/// # use nom::IResult;
+/// # use nom::error::{Error, ErrorKind};
+/// // Input is a tuple of (input: I, bit_offset: usize)
+/// fn parser(input: (&[u8], usize), count: usize)-> IResult<(&[u8], usize), u8> {
+///  take(count)(input)
+/// }
+///
+/// // Consumes 0 bits, returns 0
+/// assert_eq!(parser(([0b00010010].as_ref(), 0), 0), Ok((([0b00010010].as_ref(), 0), 0)));
+///
+/// // Consumes 4 bits, returns their values and increase offset to 4
+/// assert_eq!(parser(([0b00010010].as_ref(), 0), 4), Ok((([0b00010010].as_ref(), 4), 0b00000001)));
+///
+/// // Consumes 4 bits, offset is 4, returns their values and increase offset to 0 of next byte
+/// assert_eq!(parser(([0b00010010].as_ref(), 4), 4), Ok((([].as_ref(), 0), 0b00000010)));
+///
+/// // Tries to consume 12 bits but only 8 are available
+/// assert_eq!(parser(([0b00010010].as_ref(), 0), 12), Err(nom::Err::Error(Error{input: ([0b00010010].as_ref(), 0), code: ErrorKind::Eof })));
+/// ```
+pub fn take<I, O, C, E: ParseError<(I, usize)>>(
+  count: C,
+) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
 where
   I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
   C: ToUsize,
@@ -20,11 +45,14 @@
     } else {
       let cnt = (count + bit_offset).div(8);
       if input.input_len() * 8 < count + bit_offset {
-        Err(Err::Error(E::from_error_kind((input, bit_offset), ErrorKind::Eof)))
+        Err(Err::Error(E::from_error_kind(
+          (input, bit_offset),
+          ErrorKind::Eof,
+        )))
       } else {
-        let mut acc:O             = (0 as u8).into();
-        let mut offset: usize     = bit_offset;
-        let mut remaining: usize  = count;
+        let mut acc: O = 0_u8.into();
+        let mut offset: usize = bit_offset;
+        let mut remaining: usize = count;
         let mut end_offset: usize = 0;
 
         for byte in input.iter_elements().take(cnt + 1) {
@@ -47,14 +75,17 @@
             offset = 0;
           }
         }
-        Ok(( (input.slice(cnt..), end_offset) , acc))
+        Ok(((input.slice(cnt..), end_offset), acc))
       }
     }
   }
 }
 
-/// generates a parser taking `count` bits and comparing them to `pattern`
-pub fn tag<I, O, C, E: ParseError<(I, usize)>>(pattern: O, count: C) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
+/// Generates a parser taking `count` bits and comparing them to `pattern`
+pub fn tag<I, O, C, E: ParseError<(I, usize)>>(
+  pattern: O,
+  count: C,
+) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
 where
   I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength + Clone,
   C: ToUsize,
@@ -73,3 +104,47 @@
     })
   }
 }
+
+#[cfg(test)]
+mod test {
+  use super::*;
+
+  #[test]
+  fn test_take_0() {
+    let input = [0b00010010].as_ref();
+    let count = 0usize;
+    assert_eq!(count, 0usize);
+    let offset = 0usize;
+
+    let result: crate::IResult<(&[u8], usize), usize> = take(count)((input, offset));
+
+    assert_eq!(result, Ok(((input, offset), 0)));
+  }
+
+  #[test]
+  fn test_take_eof() {
+    let input = [0b00010010].as_ref();
+
+    let result: crate::IResult<(&[u8], usize), usize> = take(1usize)((input, 8));
+
+    assert_eq!(
+      result,
+      Err(crate::Err::Error(crate::error::Error {
+        input: (input, 8),
+        code: ErrorKind::Eof
+      }))
+    )
+  }
+
+  #[test]
+  fn test_take_span_over_multiple_bytes() {
+    let input = [0b00010010, 0b00110100, 0b11111111, 0b11111111].as_ref();
+
+    let result: crate::IResult<(&[u8], usize), usize> = take(24usize)((input, 4));
+
+    assert_eq!(
+      result,
+      Ok((([0b11111111].as_ref(), 4), 0b1000110100111111111111))
+    );
+  }
+}
diff --git a/src/bits/macros.rs b/src/bits/macros.rs
deleted file mode 100644
index b056503..0000000
--- a/src/bits/macros.rs
+++ /dev/null
@@ -1,263 +0,0 @@
-//! Bit level parsers and combinators
-//!
-//! Bit parsing is handled by tweaking the input in most macros.
-//! In byte level parsing, the input is generally a `&[u8]` passed from combinator
-//! to combinator as the slices are manipulated.
-//!
-//! Bit parsers take a `(&[u8], usize)` as input. The first part of the tuple is a byte slice,
-//! the second part is a bit offset in the first byte of the slice.
-//!
-//! By passing a pair like this, we can leverage most of the existing combinators, and avoid
-//! transforming the whole slice to a vector of booleans. This should make it easy
-//! to see a byte slice as a bit stream, and parse code points of arbitrary bit length.
-//!
-
-/// Transforms its byte slice input into a bit stream for the underlying parser. This allows the
-/// given bit stream parser to work on a byte slice input.
-///
-/// Signature:
-/// `bits!( parser ) => ( &[u8], (&[u8], usize) -> IResult<(&[u8], usize), T> ) -> IResult<&[u8], T>`
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, Needed};
-/// # fn main() {
-///  named!( take_4_bits<u8>, bits!( take_bits!( 4u8 ) ) );
-///
-///  let input = vec![0xAB, 0xCD, 0xEF, 0x12];
-///  let sl    = &input[..];
-///
-///  assert_eq!(take_4_bits( sl ), Ok( (&sl[1..], 0xA) ));
-///  assert_eq!(take_4_bits( &b""[..] ), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
-#[macro_export(local_inner_macros)]
-macro_rules! bits (
-  ($i:expr, $submac:ident!( $($args:tt)* )) => ({
-    $crate::bits::bitsc($i, move |i| { $submac!(i, $($args)*) })
-  });
-  ($i:expr, $f:expr) => (
-    bits!($i, call!($f))
-  );
-);
-
-/// Counterpart to bits, bytes! transforms its bit stream input into a byte slice for the underlying
-/// parser, allowing byte-slice parsers to work on bit streams.
-///
-/// Signature:
-/// `bytes!( parser ) => ( (&[u8], usize), &[u8] -> IResult<&[u8], T> ) -> IResult<(&[u8], usize), T>`,
-///
-/// A partial byte remaining in the input will be ignored and the given parser will start parsing
-/// at the next full byte.
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::combinator::rest;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-///
-/// named!( parse<(u8, u8, &[u8])>,  bits!( tuple!(
-///    take_bits!(4u8),
-///    take_bits!(8u8),
-///    bytes!(rest::<_, (_, ErrorKind)>)
-/// )));
-///
-///  let input = &[0xde, 0xad, 0xbe, 0xaf];
-///
-///  assert_eq!(parse( input ), Ok(( &[][..], (0xd, 0xea, &[0xbe, 0xaf][..]) )));
-/// # }
-#[macro_export(local_inner_macros)]
-macro_rules! bytes (
-  ($i:expr, $submac:ident!( $($args:tt)* )) => ({
-    $crate::bits::bytesc($i, move |i| { $submac!(i, $($args)*) })
-  });
-  ($i:expr, $f:expr) => (
-    bytes!($i, call!($f))
-  );
-);
-
-/// Consumes the specified number of bits and returns them as the specified type.
-///
-/// Signature:
-/// `take_bits!(type, count) => ( (&[T], usize), U, usize) -> IResult<(&[T], usize), U>`
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-/// named!(bits_pair<(&[u8], usize), (u8, u8)>, pair!( take_bits!(4u8), take_bits!(4u8) ) );
-/// named!( take_pair<(u8, u8)>, bits!( bits_pair ) );
-///
-/// let input = vec![0xAB, 0xCD, 0xEF];
-/// let sl    = &input[..];
-///
-/// assert_eq!(take_pair( sl ),       Ok((&sl[1..], (0xA, 0xB))) );
-/// assert_eq!(take_pair( &sl[1..] ), Ok((&sl[2..], (0xC, 0xD))) );
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! take_bits (
-  ($i:expr, $count:expr) => (
-    {
-      let res: $crate::IResult<_, _> = $crate::bits::streaming::take($count)($i);
-      res
-    }
-  );
-);
-
-/// Matches the given bit pattern.
-///
-/// Signature:
-/// `tag_bits!(type, count, pattern) => ( (&[T], usize), U, usize, U) -> IResult<(&[T], usize), U>`
-///
-/// The caller must specify the number of bits to consume. The matched value is included in the
-/// result on success.
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!( take_a<u8>, bits!( tag_bits!(4usize, 0xA) ) );
-///
-///  let input = vec![0xAB, 0xCD, 0xEF];
-///  let sl    = &input[..];
-///
-///  assert_eq!(take_a( sl ),       Ok((&sl[1..], 0xA)) );
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! tag_bits (
-  ($i:expr, $count:expr, $p: expr) => (
-    {
-      let res: $crate::IResult<_, _> = $crate::bits::streaming::tag($p, $count)($i);
-      res
-    }
-  )
-);
-
-#[cfg(test)]
-mod tests {
-  use crate::lib::std::ops::{AddAssign, Shl, Shr};
-  use crate::internal::{Err, Needed, IResult};
-  use crate::error::ErrorKind;
-
-  #[test]
-  fn take_bits() {
-    let input = [0b10_10_10_10, 0b11_11_00_00, 0b00_11_00_11];
-    let sl = &input[..];
-
-    assert_eq!(take_bits!((sl, 0), 0u8), Ok(((sl, 0), 0)));
-    assert_eq!(take_bits!((sl, 0), 8u8), Ok(((&sl[1..], 0), 170)));
-    assert_eq!(take_bits!((sl, 0), 3u8), Ok(((&sl[0..], 3), 5)));
-    assert_eq!(take_bits!((sl, 0), 6u8), Ok(((&sl[0..], 6), 42)));
-    assert_eq!(take_bits!((sl, 1), 1u8), Ok(((&sl[0..], 2), 0)));
-    assert_eq!(take_bits!((sl, 1), 2u8), Ok(((&sl[0..], 3), 1)));
-    assert_eq!(take_bits!((sl, 1), 3u8), Ok(((&sl[0..], 4), 2)));
-    assert_eq!(take_bits!((sl, 6), 3u8), Ok(((&sl[1..], 1), 5)));
-    assert_eq!(take_bits!((sl, 0), 10u8), Ok(((&sl[1..], 2), 683)));
-    assert_eq!(take_bits!((sl, 0), 8u8), Ok(((&sl[1..], 0), 170)));
-    assert_eq!(take_bits!((sl, 6), 10u8), Ok(((&sl[2..], 0), 752)));
-    assert_eq!(take_bits!((sl, 6), 11u8), Ok(((&sl[2..], 1), 1504)));
-    assert_eq!(take_bits!((sl, 0), 20u8), Ok(((&sl[2..], 4), 700_163)));
-    assert_eq!(take_bits!((sl, 4), 20u8), Ok(((&sl[3..], 0), 716_851)));
-    let r: IResult<_,u32> = take_bits!((sl, 4), 22u8);
-    assert_eq!(
-      r,
-      Err(Err::Incomplete(Needed::Size(22)))
-    );
-  }
-
-  #[test]
-  fn tag_bits() {
-    let input = [0b10_10_10_10, 0b11_11_00_00, 0b00_11_00_11];
-    let sl = &input[..];
-
-    assert_eq!(tag_bits!((sl, 0), 3u8, 0b101), Ok(((&sl[0..], 3), 5)));
-    assert_eq!(tag_bits!((sl, 0), 4u8, 0b1010), Ok(((&sl[0..], 4), 10)));
-  }
-
-  named!(ch<(&[u8],usize),(u8,u8)>,
-    do_parse!(
-      tag_bits!(3u8, 0b101) >>
-      x: take_bits!(4u8)    >>
-      y: take_bits!(5u8)    >>
-      (x,y)
-    )
-  );
-
-  #[test]
-  fn chain_bits() {
-    let input = [0b10_10_10_10, 0b11_11_00_00, 0b00_11_00_11];
-    let sl = &input[..];
-    assert_eq!(ch((&input[..], 0)), Ok(((&sl[1..], 4), (5, 15))));
-    assert_eq!(ch((&input[..], 4)), Ok(((&sl[2..], 0), (7, 16))));
-    assert_eq!(ch((&input[..1], 0)), Err(Err::Incomplete(Needed::Size(5))));
-  }
-
-  named!(ch_bytes<(u8, u8)>, bits!(ch));
-  #[test]
-  fn bits_to_bytes() {
-    let input = [0b10_10_10_10, 0b11_11_00_00, 0b00_11_00_11];
-    assert_eq!(ch_bytes(&input[..]), Ok((&input[2..], (5, 15))));
-    assert_eq!(ch_bytes(&input[..1]), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(
-      ch_bytes(&input[1..]),
-      Err(Err::Error(error_position!(&input[1..], ErrorKind::TagBits)))
-    );
-  }
-
-  named!(bits_bytes_bs, bits!(bytes!(crate::combinator::rest::<_, (&[u8], ErrorKind)>)));
-  #[test]
-  fn bits_bytes() {
-    let input = [0b10_10_10_10];
-    assert_eq!(bits_bytes_bs(&input[..]), Ok((&[][..], &[0b10_10_10_10][..])));
-  }
-
-  #[derive(PartialEq, Debug)]
-  struct FakeUint(u32);
-
-  impl AddAssign for FakeUint {
-    fn add_assign(&mut self, other: FakeUint) {
-      *self = FakeUint(self.0 + other.0);
-    }
-  }
-
-  impl Shr<usize> for FakeUint {
-    type Output = FakeUint;
-
-    fn shr(self, shift: usize) -> FakeUint {
-      FakeUint(self.0 >> shift)
-    }
-  }
-
-  impl Shl<usize> for FakeUint {
-    type Output = FakeUint;
-
-    fn shl(self, shift: usize) -> FakeUint {
-      FakeUint(self.0 << shift)
-    }
-  }
-
-  impl From<u8> for FakeUint {
-    fn from(i: u8) -> FakeUint {
-      FakeUint(u32::from(i))
-    }
-  }
-
-  #[test]
-  fn non_privitive_type() {
-    let input = [0b10_10_10_10, 0b11_11_00_00, 0b00_11_00_11];
-    let sl = &input[..];
-
-    assert_eq!(
-      take_bits!((sl, 0), 20u8),
-      Ok(((&sl[2..], 4), FakeUint(700_163)))
-    );
-    assert_eq!(
-      take_bits!((sl, 4), 20u8),
-      Ok(((&sl[3..], 0), FakeUint(716_851)))
-    );
-    let r3: IResult<_, FakeUint> = take_bits!((sl, 4), 22u8);
-    assert_eq!(
-      r3,
-      Err(Err::Incomplete(Needed::Size(22)))
-    );
-  }
-}
diff --git a/src/bits/mod.rs b/src/bits/mod.rs
index a6b12f1..235b797 100644
--- a/src/bits/mod.rs
+++ b/src/bits/mod.rs
@@ -1,17 +1,13 @@
-//! bit level parsers
+//! Bit level parsers
 //!
 
-#[macro_use]
-mod macros;
-
-pub mod streaming;
 pub mod complete;
+pub mod streaming;
 
-use crate::error::{ParseError, ErrorKind};
+use crate::error::{ErrorKind, ParseError};
 use crate::internal::{Err, IResult, Needed};
 use crate::lib::std::ops::RangeFrom;
-use crate::traits::{Slice, ErrorConvert};
-
+use crate::traits::{ErrorConvert, Slice};
 
 /// Converts a byte-level input to a bit-level input, for consumption by a parser that uses bits.
 ///
@@ -19,75 +15,80 @@
 /// away.
 ///
 /// # Example
-/// ```ignore
-/// # #[macro_use] extern crate nom;
-/// # use nom::IResult;
-/// use nom::bits::bits;
-/// use nom::bits::complete::take;
+/// ```
+/// use nom::bits::{bits, streaming::take};
+/// use nom::error::Error;
+/// use nom::sequence::tuple;
+/// use nom::IResult;
 ///
-/// fn take_4_bits(input: &[u8]) -> IResult<&[u8], u64> {
-///   bits(take::<_, _, _, (_, _)>(4usize))(input)
+/// fn parse(input: &[u8]) -> IResult<&[u8], (u8, u8)> {
+///     bits::<_, _, Error<(&[u8], usize)>, _, _>(tuple((take(4usize), take(8usize))))(input)
 /// }
 ///
-/// let input = vec![0xAB, 0xCD, 0xEF, 0x12];
-/// let sl    = &input[..];
+/// let input = &[0x12, 0x34, 0xff, 0xff];
 ///
-/// assert_eq!(take_4_bits( sl ), Ok( (&sl[1..], 0xA) ));
+/// let output = parse(input).expect("We take 1.5 bytes and the input is longer than 2 bytes");
+///
+/// // The first byte is consumed, the second byte is partially consumed and dropped.
+/// let remaining = output.0;
+/// assert_eq!(remaining, [0xff, 0xff]);
+///
+/// let parsed = output.1;
+/// assert_eq!(parsed.0, 0x01);
+/// assert_eq!(parsed.1, 0x23);
 /// ```
-pub fn bits<I, O, E1: ParseError<(I, usize)>+ErrorConvert<E2>, E2: ParseError<I>, P>(parser: P) -> impl Fn(I) -> IResult<I, O, E2>
+pub fn bits<I, O, E1, E2, P>(mut parser: P) -> impl FnMut(I) -> IResult<I, O, E2>
 where
+  E1: ParseError<(I, usize)> + ErrorConvert<E2>,
+  E2: ParseError<I>,
   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)) => {
-      let byte_index = offset / 8 + if offset % 8 == 0 { 0 } else { 1 };
-      Ok((rest.slice(byte_index..), res))
+    Ok(((rest, offset), result)) => {
+      // If the next byte has been partially read, it will be sliced away as well.
+      // The parser functions might already slice away all fully read bytes.
+      // That's why `offset / 8` isn't necessarily needed at all times.
+      let remaining_bytes_index = offset / 8 + if offset % 8 == 0 { 0 } else { 1 };
+      Ok((rest.slice(remaining_bytes_index..), result))
     }
-    Err(Err::Incomplete(n)) => Err(Err::Incomplete(n.map(|u| u / 8 + 1))),
+    Err(Err::Incomplete(n)) => Err(Err::Incomplete(n.map(|u| u.get() / 8 + 1))),
     Err(Err::Error(e)) => Err(Err::Error(e.convert())),
     Err(Err::Failure(e)) => Err(Err::Failure(e.convert())),
   }
 }
 
-#[doc(hidden)]
-pub fn bitsc<I, O, E1: ParseError<(I, usize)>+ErrorConvert<E2>, E2: ParseError<I>, P>(input: I, parser: P) -> IResult<I, O, E2>
-where
-  I: Slice<RangeFrom<usize>>,
-  P: Fn((I, usize)) -> IResult<(I, usize), O, E1>,
-{
-  bits(parser)(input)
-}
-
-/// Counterpart to bits, bytes transforms its bit stream input into a byte slice for the underlying
+/// Counterpart to `bits`, `bytes` transforms its bit stream input into a byte slice for the underlying
 /// parser, allowing byte-slice parsers to work on bit streams.
 ///
 /// A partial byte remaining in the input will be ignored and the given parser will start parsing
 /// at the next full byte.
 ///
-/// ```ignore
-/// # #[macro_use] extern crate nom;
-/// # use nom::IResult;
-/// # use nom::combinator::rest;
-/// # use nom::sequence::tuple;
-/// use nom::bits::{bits, bytes, streaming::take_bits};
+/// ```
+/// use nom::bits::{bits, bytes, streaming::take};
+/// use nom::combinator::rest;
+/// use nom::error::Error;
+/// use nom::sequence::tuple;
+/// use nom::IResult;
 ///
 /// fn parse(input: &[u8]) -> IResult<&[u8], (u8, u8, &[u8])> {
-///   bits(tuple((
-///     take_bits(4usize),
-///     take_bits(8usize),
-///     bytes(rest)
+///   bits::<_, _, Error<(&[u8], usize)>, _, _>(tuple((
+///     take(4usize),
+///     take(8usize),
+///     bytes::<_, _, Error<&[u8]>, _, _>(rest)
 ///   )))(input)
 /// }
 ///
-/// let input = &[0xde, 0xad, 0xbe, 0xaf];
+/// let input = &[0x12, 0x34, 0xff, 0xff];
 ///
-/// assert_eq!(parse( input ), Ok(( &[][..], (0xd, 0xea, &[0xbe, 0xaf][..]) )));
+/// assert_eq!(parse( input ), Ok(( &[][..], (0x01, 0x23, &[0xff, 0xff][..]) )));
 /// ```
-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>
+pub fn bytes<I, O, E1, E2, P>(mut parser: P) -> impl FnMut((I, usize)) -> IResult<(I, usize), O, E2>
 where
+  E1: ParseError<I> + ErrorConvert<E2>,
+  E2: ParseError<(I, usize)>,
   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 {
@@ -95,12 +96,12 @@
     } else {
       input.slice((offset / 8)..)
     };
-    let i = (input.clone(), offset);
+    let i = (input, offset);
     match parser(inner) {
       Ok((rest, res)) => Ok(((rest, 0), res)),
       Err(Err::Incomplete(Needed::Unknown)) => Err(Err::Incomplete(Needed::Unknown)),
-      Err(Err::Incomplete(Needed::Size(sz))) => Err(match sz.checked_mul(8) {
-        Some(v) => Err::Incomplete(Needed::Size(v)),
+      Err(Err::Incomplete(Needed::Size(sz))) => Err(match sz.get().checked_mul(8) {
+        Some(v) => Err::Incomplete(Needed::new(v)),
         None => Err::Failure(E2::from_error_kind(i, ErrorKind::TooLarge)),
       }),
       Err(Err::Error(e)) => Err(Err::Error(e.convert())),
@@ -109,11 +110,70 @@
   }
 }
 
-#[doc(hidden)]
-pub fn bytesc<I, O, E1: ParseError<I>+ErrorConvert<E2>, E2: ParseError<(I, usize)>, P>(input: (I, usize), parser: P) -> IResult<(I, usize), O, E2>
-where
-  I: Slice<RangeFrom<usize>> + Clone,
-  P: Fn(I) -> IResult<I, O, E1>,
-{
-  bytes(parser)(input)
+#[cfg(test)]
+mod test {
+  use super::*;
+  use crate::bits::streaming::take;
+  use crate::error::Error;
+  use crate::sequence::tuple;
+
+  #[test]
+  /// Take the `bits` function and assert that remaining bytes are correctly returned, if the
+  /// previous bytes are fully consumed
+  fn test_complete_byte_consumption_bits() {
+    let input = &[0x12, 0x34, 0x56, 0x78];
+
+    // Take 3 bit slices with sizes [4, 8, 4].
+    let result: IResult<&[u8], (u8, u8, u8)> =
+      bits::<_, _, Error<(&[u8], usize)>, _, _>(tuple((take(4usize), take(8usize), take(4usize))))(
+        input,
+      );
+
+    let output = result.expect("We take 2 bytes and the input is longer than 2 bytes");
+
+    let remaining = output.0;
+    assert_eq!(remaining, [0x56, 0x78]);
+
+    let parsed = output.1;
+    assert_eq!(parsed.0, 0x01);
+    assert_eq!(parsed.1, 0x23);
+    assert_eq!(parsed.2, 0x04);
+  }
+
+  #[test]
+  /// Take the `bits` function and assert that remaining bytes are correctly returned, if the
+  /// previous bytes are NOT fully consumed. Partially consumed bytes are supposed to be dropped.
+  /// I.e. if we consume 1.5 bytes of 4 bytes, 2 bytes will be returned, bits 13-16 will be
+  /// dropped.
+  fn test_partial_byte_consumption_bits() {
+    let input = &[0x12, 0x34, 0x56, 0x78];
+
+    // Take bit slices with sizes [4, 8].
+    let result: IResult<&[u8], (u8, u8)> =
+      bits::<_, _, Error<(&[u8], usize)>, _, _>(tuple((take(4usize), take(8usize))))(input);
+
+    let output = result.expect("We take 1.5 bytes and the input is longer than 2 bytes");
+
+    let remaining = output.0;
+    assert_eq!(remaining, [0x56, 0x78]);
+
+    let parsed = output.1;
+    assert_eq!(parsed.0, 0x01);
+    assert_eq!(parsed.1, 0x23);
+  }
+
+  #[test]
+  #[cfg(feature = "std")]
+  /// Ensure that in Incomplete error is thrown, if too few bytes are passed for a given parser.
+  fn test_incomplete_bits() {
+    let input = &[0x12];
+
+    // Take bit slices with sizes [4, 8].
+    let result: IResult<&[u8], (u8, u8)> =
+      bits::<_, _, Error<(&[u8], usize)>, _, _>(tuple((take(4usize), take(8usize))))(input);
+
+    assert!(result.is_err());
+    let error = result.err().unwrap();
+    assert_eq!("Parsing requires 2 bytes/chars", error.to_string());
+  }
 }
diff --git a/src/bits/streaming.rs b/src/bits/streaming.rs
index 5ab7596..e8adc1c 100644
--- a/src/bits/streaming.rs
+++ b/src/bits/streaming.rs
@@ -1,13 +1,15 @@
-//! bit level parsers
+//! Bit level parsers
 //!
 
 use crate::error::{ErrorKind, ParseError};
 use crate::internal::{Err, IResult, Needed};
-use crate::lib::std::ops::{AddAssign, RangeFrom, Shl, Shr, Div};
+use crate::lib::std::ops::{AddAssign, Div, RangeFrom, Shl, Shr};
 use crate::traits::{InputIter, InputLength, Slice, ToUsize};
 
-/// generates a parser taking `count` bits
-pub fn take<I, O, C, E: ParseError<(I, usize)>>(count: C) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
+/// Generates a parser taking `count` bits
+pub fn take<I, O, C, E: ParseError<(I, usize)>>(
+  count: C,
+) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
 where
   I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
   C: ToUsize,
@@ -20,11 +22,11 @@
     } else {
       let cnt = (count + bit_offset).div(8);
       if input.input_len() * 8 < count + bit_offset {
-        Err(Err::Incomplete(Needed::Size(count as usize)))
+        Err(Err::Incomplete(Needed::new(count as usize)))
       } else {
-        let mut acc:O             = (0 as u8).into();
-        let mut offset: usize     = bit_offset;
-        let mut remaining: usize  = count;
+        let mut acc: O = 0_u8.into();
+        let mut offset: usize = bit_offset;
+        let mut remaining: usize = count;
         let mut end_offset: usize = 0;
 
         for byte in input.iter_elements().take(cnt + 1) {
@@ -47,14 +49,17 @@
             offset = 0;
           }
         }
-        Ok(( (input.slice(cnt..), end_offset) , acc))
+        Ok(((input.slice(cnt..), end_offset), acc))
       }
     }
   }
 }
 
-/// generates a parser taking `count` bits and comparing them to `pattern`
-pub fn tag<I, O, C, E: ParseError<(I, usize)>>(pattern: O, count: C) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
+/// Generates a parser taking `count` bits and comparing them to `pattern`
+pub fn tag<I, O, C, E: ParseError<(I, usize)>>(
+  pattern: O,
+  count: C,
+) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E>
 where
   I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength + Clone,
   C: ToUsize,
@@ -73,3 +78,52 @@
     })
   }
 }
+
+#[cfg(test)]
+mod test {
+  use super::*;
+
+  #[test]
+  fn test_take_0() {
+    let input = [].as_ref();
+    let count = 0usize;
+    assert_eq!(count, 0usize);
+    let offset = 0usize;
+
+    let result: crate::IResult<(&[u8], usize), usize> = take(count)((input, offset));
+
+    assert_eq!(result, Ok(((input, offset), 0)));
+  }
+
+  #[test]
+  fn test_tag_ok() {
+    let input = [0b00011111].as_ref();
+    let offset = 0usize;
+    let bits_to_take = 4usize;
+    let value_to_tag = 0b0001;
+
+    let result: crate::IResult<(&[u8], usize), usize> =
+      tag(value_to_tag, bits_to_take)((input, offset));
+
+    assert_eq!(result, Ok(((input, bits_to_take), value_to_tag)));
+  }
+
+  #[test]
+  fn test_tag_err() {
+    let input = [0b00011111].as_ref();
+    let offset = 0usize;
+    let bits_to_take = 4usize;
+    let value_to_tag = 0b1111;
+
+    let result: crate::IResult<(&[u8], usize), usize> =
+      tag(value_to_tag, bits_to_take)((input, offset));
+
+    assert_eq!(
+      result,
+      Err(crate::Err::Error(crate::error::Error {
+        input: (input, offset),
+        code: ErrorKind::TagBits
+      }))
+    );
+  }
+}
diff --git a/src/branch/macros.rs b/src/branch/macros.rs
deleted file mode 100644
index 4c02461..0000000
--- a/src/branch/macros.rs
+++ /dev/null
@@ -1,940 +0,0 @@
-/// Try a list of parsers and return the result of the first successful one
-///
-/// ```rust,ignore
-/// alt!(I -> IResult<I,O> | I -> IResult<I,O> | ... | I -> IResult<I,O> ) => I -> IResult<I, O>
-/// ```
-/// All the parsers must have the same return type.
-///
-/// If one of the parsers returns `Incomplete`, `alt!` will return `Incomplete`, to retry
-/// once you get more input. Note that it is better for performance to know the
-/// minimum size of data you need before you get into `alt!`.
-///
-/// The `alt!` combinator is used in the following way:
-///
-/// ```rust,ignore
-/// alt!(parser_1 | parser_2 | ... | parser_n)
-/// ```
-///
-/// # Basic example
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  // Create a parser that will match either "dragon" or "beast"
-///  named!( dragon_or_beast, alt!( tag!( "dragon" ) | tag!( "beast" ) ) );
-///
-///  // Given the input "dragon slayer", the parser will match "dragon"
-///  // and the rest will be " slayer"
-///  let (rest, result) = dragon_or_beast(b"dragon slayer").unwrap();
-///  assert_eq!(result, b"dragon");
-///  assert_eq!(rest, b" slayer");
-///
-///  // Given the input "beast of Gevaudan", the parser will match "beast"
-///  // and the rest will be " of Gevaudan"
-///  let (rest, result) = dragon_or_beast(&b"beast of Gevaudan"[..]).unwrap();
-///  assert_eq!(result, b"beast");
-///  assert_eq!(rest, b" of Gevaudan");
-///  # }
-/// ```
-///
-/// # Manipulate results
-///
-/// There exists another syntax for `alt!` that gives you the ability to
-/// manipulate the result from each parser:
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-/// #
-/// // We create an enum to represent our creatures
-/// #[derive(Debug,PartialEq,Eq)]
-/// enum Creature {
-///     Dragon,
-///     Beast,
-///     Unknown(usize)
-/// }
-///
-/// // Let's make a helper function that returns true when not a space
-/// // we are required to do this because the `take_while!` macro is limited
-/// // to idents, so we can't negate `ìs_space` at the call site
-/// fn is_not_space(c: u8) -> bool { ! nom::character::is_space(c) }
-///
-/// // Our parser will return the `Dragon` variant when matching "dragon",
-/// // the `Beast` variant when matching "beast" and otherwise it will consume
-/// // the input until a space is found and return an `Unknown` creature with
-/// // the size of it's name.
-/// named!(creature<Creature>, alt!(
-///     tag!("dragon")            => { |_| Creature::Dragon } |
-///     tag!("beast")             => { |_| Creature::Beast }  |
-///     take_while!(is_not_space) => { |r: &[u8]| Creature::Unknown(r.len()) }
-///     // the closure takes the result as argument if the parser is successful
-/// ));
-///
-/// // Given the input "dragon slayer" the parser will return `Creature::Dragon`
-/// // and the rest will be " slayer"
-/// let (rest, result) = creature(b"dragon slayer").unwrap();
-/// assert_eq!(result, Creature::Dragon);
-/// assert_eq!(rest, b" slayer");
-///
-/// // Given the input "beast of Gevaudan" the parser will return `Creature::Beast`
-/// // and the rest will be " of Gevaudan"
-/// let (rest, result) = creature(b"beast of Gevaudan").unwrap();
-/// assert_eq!(result, Creature::Beast);
-/// assert_eq!(rest, b" of Gevaudan");
-///
-/// // Given the input "demon hunter" the parser will return `Creature::Unknown(5)`
-/// // and the rest will be " hunter"
-/// let (rest, result) = creature(b"demon hunter").unwrap();
-/// assert_eq!(result, Creature::Unknown(5));
-/// assert_eq!(rest, b" hunter");
-/// # }
-/// ```
-///
-/// # Behaviour of `alt!`
-///
-/// **BE CAREFUL** there is a case where the behaviour of `alt!` can be confusing:
-///
-/// when the alternatives have different lengths, like this case:
-///
-/// ```ignore
-///  named!( test, alt!( tag!( "abcd" ) | tag!( "ef" ) | tag!( "ghi" ) | tag!( "kl" ) ) );
-/// ```
-///
-/// With this parser, if you pass `"abcd"` as input, the first alternative parses it correctly,
-/// but if you pass `"efg"`, the first alternative will return `Incomplete`, since it needs an input
-/// of 4 bytes. This behaviour of `alt!` is expected: if you get a partial input that isn't matched
-/// by the first alternative, but would match if the input was complete, you want `alt!` to indicate
-/// that it cannot decide with limited information.
-///
-/// There are two ways to fix this behaviour. The first one consists in ordering the alternatives
-/// by size, like this:
-///
-/// ```ignore
-///  named!( test, alt!( tag!( "ef" ) | tag!( "kl") | tag!( "ghi" ) | tag!( "abcd" ) ) );
-/// ```
-///
-/// With this solution, the largest alternative will be tested last.
-///
-/// The other solution uses the `complete!` combinator, which transforms an `Incomplete` in an
-/// `Error`. If one of the alternatives returns `Incomplete` but is wrapped by `complete!`,
-/// `alt!` will try the next alternative. This is useful when you know that
-/// you will not get partial input:
-///
-/// ```ignore
-///  named!( test,
-///    alt!(
-///      complete!( tag!( "abcd" ) ) |
-///      complete!( tag!( "ef"   ) ) |
-///      complete!( tag!( "ghi"  ) ) |
-///      complete!( tag!( "kl"   ) )
-///    )
-///  );
-/// ```
-///
-/// This behaviour of `alt!` can get especially confusing if multiple alternatives have different
-/// sizes but a common prefix, like this:
-///
-/// ```ignore
-///  named!( test, alt!( tag!( "abcd" ) | tag!( "ab" ) | tag!( "ef" ) ) );
-/// ```
-///
-/// in that case, if you order by size, passing `"abcd"` as input will always be matched by the
-/// smallest parser, so the solution using `complete!` is better suited.
-///
-/// You can also nest multiple `alt!`, like this:
-///
-/// ```ignore
-///  named!( test,
-///    alt!(
-///      preceded!(
-///        tag!("ab"),
-///        alt!(
-///          tag!( "cd" ) |
-///          eof!()
-///        )
-///      )
-///    | tag!( "ef" )
-///    )
-///  );
-/// ```
-///
-///  `preceded!` will first parse `"ab"` then, if successful, try the alternatives "cd",
-///  or empty input (End Of File). If none of them work, `preceded!` will fail and
-///  "ef" will be tested.
-///
-#[macro_export(local_inner_macros)]
-macro_rules! alt (
-  (__impl $i:expr, $submac:ident!( $($args:tt)* ), $($rest:tt)* ) => (
-    nom_compile_error!("alt uses '|' as separator, not ',':
-
-      alt!(
-        tag!(\"abcd\") |
-        tag!(\"efgh\") |
-        tag!(\"ijkl\")
-      )
-    ");
-  );
-  (__impl $i:expr, $e:path, $($rest:tt)* ) => (
-    alt!(__impl $i, call!($e) , $($rest)*);
-  );
-  (__impl $i:expr, $e:path | $($rest:tt)*) => (
-    alt!(__impl $i, call!($e) | $($rest)*);
-  );
-
-  (__impl $i:expr, $subrule:ident!( $($args:tt)*) | $($rest:tt)*) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::Err;
-
-      let i_ = $i.clone();
-      let res = $subrule!(i_, $($args)*);
-      match res {
-        Ok(o) => Ok(o),
-        Err(Err::Error(e))      => {
-          let out = alt!(__impl $i, $($rest)*);
-
-          // Compile-time hack to ensure that res's E type is not under-specified.
-          // This all has no effect at runtime.
-          #[allow(dead_code)]
-          fn unify_types<T>(_: &T, _: &T) {}
-          if let Err(Err::Error(ref e2)) = out {
-            unify_types(&e, e2);
-          }
-
-          out
-        },
-        Err(e) => Err(e),
-      }
-    }
-  );
-
-  (__impl $i:expr, $subrule:ident!( $($args:tt)* ) => { $gen:expr } | $($rest:tt)*) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::Err;
-
-      let i_ = $i.clone();
-      match $subrule!(i_, $($args)* ) {
-        Ok((i,o))         => Ok((i,$gen(o))),
-        Err(Err::Error(e)) => {
-          let out = alt!(__impl $i, $($rest)*);
-
-          // Compile-time hack to ensure that res's E type is not under-specified.
-          // This all has no effect at runtime.
-          fn unify_types<T>(_: &T, _: &T) {}
-          if let Err(Err::Error(ref e2)) = out {
-            unify_types(&e, e2);
-          }
-
-          out
-        },
-        Err(e) => Err(e),
-      }
-    }
-  );
-
-  (__impl $i:expr, $e:path => { $gen:expr } | $($rest:tt)*) => (
-    alt!(__impl $i, call!($e) => { $gen } | $($rest)*);
-  );
-
-  (__impl $i:expr, __end) => (
-    {
-      use $crate::{Err,error::ErrorKind};
-      let e2 = ErrorKind::Alt;
-      let err = Err::Error(error_position!($i, e2));
-
-      Err(err)
-    }
-  );
-
-  ($i:expr, $($rest:tt)*) => (
-    {
-      alt!(__impl $i, $($rest)* | __end)
-    }
-  );
-);
-
-/// `switch!(I -> IResult<I,P>, P => I -> IResult<I,O> | ... | P => I -> IResult<I,O> ) => I -> IResult<I, O>`
-/// choose the next parser depending on the result of the first one, if successful,
-/// and returns the result of the second parser
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-///  named!(sw,
-///    switch!(take!(4),
-///      b"abcd" => tag!("XYZ") |
-///      b"efgh" => tag!("123")
-///    )
-///  );
-///
-///  let a = b"abcdXYZ123";
-///  let b = b"abcdef";
-///  let c = b"efgh123";
-///  let d = b"blah";
-///
-///  assert_eq!(sw(&a[..]), Ok((&b"123"[..], &b"XYZ"[..])));
-///  assert_eq!(sw(&b[..]), Err(Err::Error(error_node_position!(&b"abcdef"[..], ErrorKind::Switch,
-///    error_position!(&b"ef"[..], ErrorKind::Tag)))));
-///  assert_eq!(sw(&c[..]), Ok((&b""[..], &b"123"[..])));
-///  assert_eq!(sw(&d[..]), Err(Err::Error(error_position!(&b"blah"[..], ErrorKind::Switch))));
-///  # }
-/// ```
-///
-/// You can specify a default case like with a normal match, using `_`
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(sw,
-///    switch!(take!(4),
-///      b"abcd" => tag!("XYZ") |
-///      _       => value!(&b"default"[..])
-///    )
-///  );
-///
-///  let a = b"abcdXYZ123";
-///  let b = b"blah";
-///
-///  assert_eq!(sw(&a[..]), Ok((&b"123"[..], &b"XYZ"[..])));
-///  assert_eq!(sw(&b[..]), Ok((&b""[..], &b"default"[..])));
-///  # }
-/// ```
-///
-/// Due to limitations in Rust macros, it is not possible to have simple functions on the right hand
-/// side of pattern, like this:
-///
-/// ```ignore
-///  named!(xyz, tag!("XYZ"));
-///  named!(num, tag!("123"));
-///  named!(sw,
-///    switch!(take!(4),
-///      b"abcd" => xyz |
-///      b"efgh" => 123
-///    )
-///  );
-/// ```
-///
-/// If you want to pass your own functions instead, you can use the `call!` combinator as follows:
-///
-/// ```ignore
-///  named!(xyz, tag!("XYZ"));
-///  named!(num, tag!("123"));
-///  named!(sw,
-///    switch!(take!(4),
-///      b"abcd" => call!(xyz) |
-///      b"efgh" => call!(num)
-///    )
-///  );
-/// ```
-///
-#[macro_export(local_inner_macros)]
-macro_rules! switch (
-  (__impl $i:expr, $submac:ident!( $($args:tt)* ), $( $($p:pat)|+ => $subrule:ident!( $($args2:tt)* ))|* ) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::lib::std::option::Option::*;
-      use $crate::{Err,error::ErrorKind};
-
-      let i_ = $i.clone();
-      match map!(i_, $submac!($($args)*), Some) {
-        Err(Err::Error(err))      => {
-          fn unify_types<T>(_: &T, _: &T) {}
-          let e1 = ErrorKind::Switch;
-          let e2 = error_position!($i, e1.clone());
-          unify_types(&err, &e2);
-
-          Err(Err::Error(error_node_position!($i, e1, err)))
-        },
-        Err(e) => Err(e),
-        Ok((i, o))    => {
-
-          match o {
-            $($(Some($p) )|+ => match $subrule!(i, $($args2)*) {
-              Err(Err::Error(err)) => {
-                fn unify_types<T>(_: &T, _: &T) {}
-                let e1 = ErrorKind::Switch;
-                let e2 = error_position!($i, e1.clone());
-                unify_types(&err, &e2);
-
-                Err(Err::Error(error_node_position!($i, e1, err)))
-              },
-              Ok(o) => Ok(o),
-              Err(e) => Err(e),
-            }),*,
-            _    => Err(Err::convert(Err::Error(error_position!($i, ErrorKind::Switch))))
-          }
-        }
-      }
-    }
-  );
-  ($i:expr, $submac:ident!( $($args:tt)*), $($rest:tt)*) => (
-    {
-      switch!(__impl $i, $submac!($($args)*), $($rest)*)
-    }
-  );
-  ($i:expr, $e:path, $($rest:tt)*) => (
-    {
-      switch!(__impl $i, call!($e), $($rest)*)
-    }
-  );
-);
-
-///
-///
-/// `permutation!(I -> IResult<I,A>, I -> IResult<I,B>, ... I -> IResult<I,X> ) => I -> IResult<I, (A,B,...X)>`
-/// applies its sub parsers in a sequence, but independent from their order
-/// this parser will only succeed if all of its sub parsers succeed
-///
-/// the tuple of results is in the same order as the parsers are declared
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,error::ErrorKind,Needed};
-/// # fn main() {
-/// named!(perm<(&[u8], &[u8], &[u8])>,
-///   permutation!(tag!("abcd"), tag!("efg"), tag!("hi"))
-/// );
-///
-/// // whatever the order, if the parser succeeds, each
-/// // tag should have matched correctly
-/// let expected = (&b"abcd"[..], &b"efg"[..], &b"hi"[..]);
-///
-/// let a = &b"abcdefghijk"[..];
-/// assert_eq!(perm(a), Ok((&b"jk"[..], expected)));
-/// let b = &b"efgabcdhijkl"[..];
-/// assert_eq!(perm(b), Ok((&b"jkl"[..], expected)));
-/// let c = &b"hiefgabcdjklm"[..];
-/// assert_eq!(perm(c), Ok((&b"jklm"[..], expected)));
-///
-/// let d = &b"efgxyzabcdefghi"[..];
-/// assert_eq!(perm(d), Err(Err::Error(error_node_position!(&b"efgxyzabcdefghi"[..], ErrorKind::Permutation,
-///   error_position!(&b"xyzabcdefghi"[..], ErrorKind::Permutation)))));
-///
-/// let e = &b"efgabc"[..];
-/// assert_eq!(perm(e), Err(Err::Incomplete(Needed::Size(4))));
-/// # }
-/// ```
-///
-/// If one of the child parsers is followed by a `?`, that parser is now
-/// optional:
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,error::ErrorKind,Needed};
-/// # fn main() {
-/// named!(perm<&str, (Option<&str>, &str, &str)>,
-///   permutation!(tag!("abcd")?, tag!("efg"), tag!("hi"))
-/// );
-///
-/// // whatever the order, if the parser succeeds, each
-/// // tag should have matched correctly
-/// let expected = (Some("abcd"), "efg", "hi");
-///
-/// let a = "abcdefghijk";
-/// assert_eq!(perm(a), Ok(("jk", expected)));
-/// let b = "efgabcdhijkl";
-/// assert_eq!(perm(b), Ok(("jkl", expected)));
-/// let c = "hiefgabcdjklm";
-/// assert_eq!(perm(c), Ok(("jklm", expected)));
-///
-/// // if `abcd` is missing:
-/// let expected = (None, "efg", "hi");
-///
-/// let a = "efghijk";
-/// assert_eq!(perm(a), Ok(("jk", expected)));
-/// let b = "efghijkl";
-/// assert_eq!(perm(b), Ok(("jkl", expected)));
-/// let c = "hiefgjklm";
-/// assert_eq!(perm(c), Ok(("jklm", expected)));
-///
-/// let e = "efgabc";
-/// assert_eq!(perm(e), Err(Err::Incomplete(Needed::Size(4))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! permutation (
-  ($i:expr, $($rest:tt)*) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::lib::std::option::Option::*;
-      use $crate::{Err,error::ErrorKind};
-
-      let mut res    = permutation_init!((), $($rest)*);
-      let mut input  = $i;
-      let mut error  = None;
-      let mut needed = None;
-
-      loop {
-        let mut all_done = true;
-        permutation_iterator!(0, input, all_done, needed, res, $($rest)*);
-
-        //if we reach that part, it means none of the parsers were able to read anything
-        if !all_done {
-          //FIXME: should wrap the error returned by the child parser
-          error = Some(error_position!(input, ErrorKind::Permutation));
-        }
-        break;
-      }
-
-      if let Some(need) = needed {
-        Err(Err::convert(need))
-      } else {
-        if let Some(unwrapped_res) = { permutation_unwrap!(0, (), res, $($rest)*) } {
-          Ok((input, unwrapped_res))
-        } else {
-          if let Some(e) = error {
-            Err(Err::Error(error_node_position!($i, ErrorKind::Permutation, e)))
-          } else {
-            Err(Err::Error(error_position!($i, ErrorKind::Permutation)))
-          }
-        }
-      }
-    }
-  );
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! permutation_init (
-  ((), $e:ident?, $($rest:tt)*) => (
-    permutation_init!(($crate::lib::std::option::Option::None), $($rest)*)
-  );
-  ((), $e:ident, $($rest:tt)*) => (
-    permutation_init!(($crate::lib::std::option::Option::None), $($rest)*)
-  );
-
-  ((), $submac:ident!( $($args:tt)* )?, $($rest:tt)*) => (
-    permutation_init!(($crate::lib::std::option::Option::None), $($rest)*)
-  );
-  ((), $submac:ident!( $($args:tt)* ), $($rest:tt)*) => (
-    permutation_init!(($crate::lib::std::option::Option::None), $($rest)*)
-  );
-
-  (($($parsed:expr),*), $e:ident?, $($rest:tt)*) => (
-    permutation_init!(($($parsed),* , $crate::lib::std::option::Option::None), $($rest)*);
-  );
-  (($($parsed:expr),*), $e:ident, $($rest:tt)*) => (
-    permutation_init!(($($parsed),* , $crate::lib::std::option::Option::None), $($rest)*);
-  );
-
-  (($($parsed:expr),*), $submac:ident!( $($args:tt)* )?, $($rest:tt)*) => (
-    permutation_init!(($($parsed),* , $crate::lib::std::option::Option::None), $($rest)*);
-  );
-  (($($parsed:expr),*), $submac:ident!( $($args:tt)* ), $($rest:tt)*) => (
-    permutation_init!(($($parsed),* , $crate::lib::std::option::Option::None), $($rest)*);
-  );
-
-  (($($parsed:expr),*), $e:ident) => (
-    ($($parsed),* , $crate::lib::std::option::Option::None)
-  );
-  (($($parsed:expr),*), $e:ident?) => (
-    ($($parsed),* , $crate::lib::std::option::Option::None)
-  );
-
-  (($($parsed:expr),*), $submac:ident!( $($args:tt)* )?) => (
-    ($($parsed),* , $crate::lib::std::option::Option::None)
-  );
-  (($($parsed:expr),*), $submac:ident!( $($args:tt)* )) => (
-    ($($parsed),* , $crate::lib::std::option::Option::None)
-  );
-  (($($parsed:expr),*),) => (
-    ($($parsed),*)
-  );
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! succ (
-  (0, $submac:ident ! ($($rest:tt)*)) => ($submac!(1, $($rest)*));
-  (1, $submac:ident ! ($($rest:tt)*)) => ($submac!(2, $($rest)*));
-  (2, $submac:ident ! ($($rest:tt)*)) => ($submac!(3, $($rest)*));
-  (3, $submac:ident ! ($($rest:tt)*)) => ($submac!(4, $($rest)*));
-  (4, $submac:ident ! ($($rest:tt)*)) => ($submac!(5, $($rest)*));
-  (5, $submac:ident ! ($($rest:tt)*)) => ($submac!(6, $($rest)*));
-  (6, $submac:ident ! ($($rest:tt)*)) => ($submac!(7, $($rest)*));
-  (7, $submac:ident ! ($($rest:tt)*)) => ($submac!(8, $($rest)*));
-  (8, $submac:ident ! ($($rest:tt)*)) => ($submac!(9, $($rest)*));
-  (9, $submac:ident ! ($($rest:tt)*)) => ($submac!(10, $($rest)*));
-  (10, $submac:ident ! ($($rest:tt)*)) => ($submac!(11, $($rest)*));
-  (11, $submac:ident ! ($($rest:tt)*)) => ($submac!(12, $($rest)*));
-  (12, $submac:ident ! ($($rest:tt)*)) => ($submac!(13, $($rest)*));
-  (13, $submac:ident ! ($($rest:tt)*)) => ($submac!(14, $($rest)*));
-  (14, $submac:ident ! ($($rest:tt)*)) => ($submac!(15, $($rest)*));
-  (15, $submac:ident ! ($($rest:tt)*)) => ($submac!(16, $($rest)*));
-  (16, $submac:ident ! ($($rest:tt)*)) => ($submac!(17, $($rest)*));
-  (17, $submac:ident ! ($($rest:tt)*)) => ($submac!(18, $($rest)*));
-  (18, $submac:ident ! ($($rest:tt)*)) => ($submac!(19, $($rest)*));
-  (19, $submac:ident ! ($($rest:tt)*)) => ($submac!(20, $($rest)*));
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! permutation_unwrap (
-  ($it:tt,  (), $res:ident, $e:ident?, $($rest:tt)*) => (
-    succ!($it, permutation_unwrap!(($res.$it), $res, $($rest)*));
-  );
-  ($it:tt,  (), $res:ident, $e:ident, $($rest:tt)*) => ({
-    let res = $res.$it;
-    if res.is_some() {
-      succ!($it, permutation_unwrap!((res.unwrap()), $res, $($rest)*))
-    } else {
-      $crate::lib::std::option::Option::None
-    }
-  });
-
-  ($it:tt,  (), $res:ident, $submac:ident!( $($args:tt)* )?, $($rest:tt)*) => (
-    succ!($it, permutation_unwrap!(($res.$it), $res, $($rest)*));
-  );
-  ($it:tt,  (), $res:ident, $submac:ident!( $($args:tt)* ), $($rest:tt)*) => ({
-    let res = $res.$it;
-    if res.is_some() {
-      succ!($it, permutation_unwrap!((res.unwrap()), $res, $($rest)*))
-    } else {
-      $crate::lib::std::option::Option::None
-    }
-  });
-
-  ($it:tt, ($($parsed:expr),*), $res:ident, $e:ident?, $($rest:tt)*) => (
-    succ!($it, permutation_unwrap!(($($parsed),* , $res.$it), $res, $($rest)*));
-  );
-  ($it:tt, ($($parsed:expr),*), $res:ident, $e:ident, $($rest:tt)*) => ({
-    let res = $res.$it;
-    if res.is_some() {
-      succ!($it, permutation_unwrap!(($($parsed),* , res.unwrap()), $res, $($rest)*))
-    } else {
-      $crate::lib::std::option::Option::None
-    }
-  });
-
-  ($it:tt, ($($parsed:expr),*), $res:ident, $submac:ident!( $($args:tt)* )?, $($rest:tt)*) => (
-    succ!($it, permutation_unwrap!(($($parsed),* , $res.$it), $res, $($rest)*));
-  );
-  ($it:tt, ($($parsed:expr),*), $res:ident, $submac:ident!( $($args:tt)* ), $($rest:tt)*) => ({
-    let res = $res.$it;
-    if res.is_some() {
-      succ!($it, permutation_unwrap!(($($parsed),* , res.unwrap()), $res, $($rest)*))
-    } else {
-      $crate::lib::std::option::Option::None
-    }
-  });
-
-  ($it:tt, ($($parsed:expr),*), $res:ident?, $e:ident) => (
-    $crate::lib::std::option::Option::Some(($($parsed),* , { $res.$it }))
-  );
-  ($it:tt, ($($parsed:expr),*), $res:ident, $e:ident) => ({
-    let res = $res.$it;
-    if res.is_some() {
-      $crate::lib::std::option::Option::Some(($($parsed),* , res.unwrap() ))
-    } else {
-      $crate::lib::std::option::Option::None
-    }
-  });
-
-  ($it:tt, ($($parsed:expr),*), $res:ident, $submac:ident!( $($args:tt)* )?) => (
-    $crate::lib::std::option::Option::Some(($($parsed),* , { $res.$it }))
-  );
-  ($it:tt, ($($parsed:expr),*), $res:ident, $submac:ident!( $($args:tt)* )) => ({
-    let res = $res.$it;
-    if res.is_some() {
-      $crate::lib::std::option::Option::Some(($($parsed),* , res.unwrap() ))
-    } else {
-      $crate::lib::std::option::Option::None
-    }
-  });
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! permutation_iterator (
-  ($it:tt,$i:expr, $all_done:expr, $needed:expr, $res:expr, $e:ident?, $($rest:tt)*) => (
-    permutation_iterator!($it, $i, $all_done, $needed, $res, call!($e), $($rest)*);
-  );
-  ($it:tt,$i:expr, $all_done:expr, $needed:expr, $res:expr, $e:ident, $($rest:tt)*) => (
-    permutation_iterator!($it, $i, $all_done, $needed, $res, call!($e), $($rest)*);
-  );
-
-  ($it:tt, $i:expr, $all_done:expr, $needed:expr, $res:expr, $submac:ident!( $($args:tt)* )?, $($rest:tt)*) => {
-    permutation_iterator!($it, $i, $all_done, $needed, $res, $submac!($($args)*) , $($rest)*);
-  };
-  ($it:tt, $i:expr, $all_done:expr, $needed:expr, $res:expr, $submac:ident!( $($args:tt)* ), $($rest:tt)*) => ({
-    use $crate::lib::std::result::Result::*;
-    use $crate::lib::std::option::Option::*;
-    use $crate::Err;
-
-    if $res.$it.is_none() {
-      match $submac!($i, $($args)*) {
-        Ok((i,o))     => {
-          $i = i;
-          $res.$it = Some(o);
-          continue;
-        },
-        Err(Err::Error(_)) => {
-          $all_done = false;
-        },
-        Err(e) => {
-          $needed = Some(e);
-          break;
-        }
-      };
-    }
-    succ!($it, permutation_iterator!($i, $all_done, $needed, $res, $($rest)*));
-  });
-
-  ($it:tt,$i:expr, $all_done:expr, $needed:expr, $res:expr, $e:ident?) => (
-    permutation_iterator!($it, $i, $all_done, $needed, $res, call!($e));
-  );
-  ($it:tt,$i:expr, $all_done:expr, $needed:expr, $res:expr, $e:ident) => (
-    permutation_iterator!($it, $i, $all_done, $needed, $res, call!($e));
-  );
-
-  ($it:tt, $i:expr, $all_done:expr, $needed:expr, $res:expr, $submac:ident!( $($args:tt)* )?) => {
-    permutation_iterator!($it, $i, $all_done, $needed, $res, $submac!($($args)*));
-  };
-  ($it:tt, $i:expr, $all_done:expr, $needed:expr, $res:expr, $submac:ident!( $($args:tt)* )) => ({
-    use $crate::lib::std::result::Result::*;
-    use $crate::lib::std::option::Option::*;
-    use $crate::Err;
-
-    if $res.$it.is_none() {
-      match $submac!($i, $($args)*) {
-        Ok((i,o))     => {
-          $i = i;
-          $res.$it = Some(o);
-          continue;
-        },
-        Err(Err::Error(_)) => {
-          $all_done = false;
-        },
-        Err(e) => {
-          $needed = Some(e);
-          break;
-        }
-      };
-    }
-  });
-);
-
-#[cfg(test)]
-mod tests {
-  use crate::error::ErrorKind;
-  #[cfg(feature = "alloc")]
-  use crate::{
-    error::ParseError,
-    lib::std::{
-      fmt::Debug,
-      string::{String, ToString}
-    }
-  };
-  use crate::internal::{Err, IResult, Needed};
-
-  // reproduce the tag and take macros, because of module import order
-  macro_rules! tag (
-    ($i:expr, $inp: expr) => (
-      {
-        #[inline(always)]
-        fn as_bytes<T: $crate::AsBytes>(b: &T) -> &[u8] {
-          b.as_bytes()
-        }
-
-        let expected = $inp;
-        let bytes    = as_bytes(&expected);
-
-        tag_bytes!($i,bytes)
-      }
-    );
-  );
-
-  macro_rules! tag_bytes (
-    ($i:expr, $bytes: expr) => (
-      {
-        use $crate::lib::std::cmp::min;
-
-        let len = $i.len();
-        let blen = $bytes.len();
-        let m   = min(len, blen);
-        let reduced = &$i[..m];
-        let b       = &$bytes[..m];
-
-        let res: IResult<_,_,_> = if reduced != b {
-          let e: ErrorKind = ErrorKind::Tag;
-          Err(Err::Error(error_position!($i, e)))
-        } else if m < blen {
-          Err(Err::Incomplete(Needed::Size(blen)))
-        } else {
-          Ok((&$i[blen..], reduced))
-        };
-        res
-      }
-    );
-  );
-
-  macro_rules! take(
-    ($i:expr, $count:expr) => (
-      {
-        let cnt = $count as usize;
-        let res:IResult<&[u8],&[u8],_> = if $i.len() < cnt {
-          Err(Err::Incomplete(Needed::Size(cnt)))
-        } else {
-          Ok((&$i[cnt..],&$i[0..cnt]))
-        };
-        res
-      }
-    );
-  );
-
-  #[cfg(feature = "alloc")]
-  #[derive(Debug, Clone, PartialEq)]
-  pub struct ErrorStr(String);
-
-  #[cfg(feature = "alloc")]
-  impl From<u32> for ErrorStr {
-    fn from(i: u32) -> Self {
-      ErrorStr(format!("custom error code: {}", i))
-    }
-  }
-
-  #[cfg(feature = "alloc")]
-  impl<'a> From<&'a str> for ErrorStr {
-    fn from(i: &'a str) -> Self {
-      ErrorStr(format!("custom error message: {}", i))
-    }
-  }
-
-  #[cfg(feature = "alloc")]
-  impl<I: Debug> ParseError<I> for ErrorStr {
-    fn from_error_kind(input: I, kind: ErrorKind) -> Self {
-      ErrorStr(format!("custom error message: ({:?}, {:?})", input, kind))
-    }
-
-    fn append(input: I, kind: ErrorKind, other: Self) -> Self {
-      ErrorStr(format!("custom error message: ({:?}, {:?}) - {:?}", input, kind, other))
-    }
-  }
-
-  #[cfg(feature = "alloc")]
-  #[test]
-  fn alt() {
-    fn work(input: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
-      Ok((&b""[..], input))
-    }
-
-    #[allow(unused_variables)]
-    fn dont_work(input: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
-      Err(Err::Error(ErrorStr("abcd".to_string())))
-    }
-
-    fn work2(input: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
-      Ok((input, &b""[..]))
-    }
-
-    fn alt1(i: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
-      alt!(i, dont_work | dont_work)
-    }
-    fn alt2(i: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
-      alt!(i, dont_work | work)
-    }
-    fn alt3(i: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
-      alt!(i, dont_work | dont_work | work2 | dont_work)
-    }
-    //named!(alt1, alt!(dont_work | dont_work));
-    //named!(alt2, alt!(dont_work | work));
-    //named!(alt3, alt!(dont_work | dont_work | work2 | dont_work));
-
-    let a = &b"abcd"[..];
-    assert_eq!(alt1(a), Err(Err::Error(error_position!(a, ErrorKind::Alt))));
-    assert_eq!(alt2(a), Ok((&b""[..], a)));
-    assert_eq!(alt3(a), Ok((a, &b""[..])));
-
-    named!(alt4, alt!(tag!("abcd") | tag!("efgh")));
-    let b = &b"efgh"[..];
-    assert_eq!(alt4(a), Ok((&b""[..], a)));
-    assert_eq!(alt4(b), Ok((&b""[..], b)));
-
-    // test the alternative syntax
-    named!(alt5<bool>, alt!(tag!("abcd") => { |_| false } | tag!("efgh") => { |_| true }));
-    assert_eq!(alt5(a), Ok((&b""[..], false)));
-    assert_eq!(alt5(b), Ok((&b""[..], true)));
-
-    // compile-time test guarding against an underspecified E generic type (#474)
-    named!(alt_eof1, alt!(eof!() | eof!()));
-    named!(alt_eof2, alt!(eof!() => {|x| x} | eof!() => {|x| x}));
-    let _ = (alt_eof1, alt_eof2);
-  }
-
-  #[test]
-  fn alt_incomplete() {
-    named!(alt1, alt!(tag!("a") | tag!("bc") | tag!("def")));
-
-    let a = &b""[..];
-    assert_eq!(alt1(a), Err(Err::Incomplete(Needed::Size(1))));
-    let a = &b"b"[..];
-    assert_eq!(alt1(a), Err(Err::Incomplete(Needed::Size(2))));
-    let a = &b"bcd"[..];
-    assert_eq!(alt1(a), Ok((&b"d"[..], &b"bc"[..])));
-    let a = &b"cde"[..];
-    assert_eq!(alt1(a), Err(Err::Error(error_position!(a, ErrorKind::Alt))));
-    let a = &b"de"[..];
-    assert_eq!(alt1(a), Err(Err::Incomplete(Needed::Size(3))));
-    let a = &b"defg"[..];
-    assert_eq!(alt1(a), Ok((&b"g"[..], &b"def"[..])));
-  }
-
-  #[allow(unused_variables)]
-  #[test]
-  fn switch() {
-    named!(
-      sw,
-      switch!(take!(4),
-        b"abcd" | b"xxxx" => take!(2) |
-        b"efgh" => take!(4)
-      )
-    );
-
-    let a = &b"abcdefgh"[..];
-    assert_eq!(sw(a), Ok((&b"gh"[..], &b"ef"[..])));
-
-    let b = &b"efghijkl"[..];
-    assert_eq!(sw(b), Ok((&b""[..], &b"ijkl"[..])));
-    let c = &b"afghijkl"[..];
-    assert_eq!(sw(c), Err(Err::Error(error_position!(&b"afghijkl"[..], ErrorKind::Switch))));
-
-    let a = &b"xxxxefgh"[..];
-    assert_eq!(sw(a), Ok((&b"gh"[..], &b"ef"[..])));
-  }
-
-  #[test]
-  fn permutation() {
-    named!(perm<(&[u8], &[u8], &[u8])>, permutation!(tag!("abcd"), tag!("efg"), tag!("hi")));
-
-    let expected = (&b"abcd"[..], &b"efg"[..], &b"hi"[..]);
-
-    let a = &b"abcdefghijk"[..];
-    assert_eq!(perm(a), Ok((&b"jk"[..], expected)));
-    let b = &b"efgabcdhijk"[..];
-    assert_eq!(perm(b), Ok((&b"jk"[..], expected)));
-    let c = &b"hiefgabcdjk"[..];
-    assert_eq!(perm(c), Ok((&b"jk"[..], expected)));
-
-    let d = &b"efgxyzabcdefghi"[..];
-    assert_eq!(
-      perm(d),
-      Err(Err::Error(error_node_position!(
-        &b"efgxyzabcdefghi"[..],
-        ErrorKind::Permutation,
-        error_position!(&b"xyzabcdefghi"[..], ErrorKind::Permutation)
-      )))
-    );
-
-    let e = &b"efgabc"[..];
-    assert_eq!(perm(e), Err(Err::Incomplete(Needed::Size(4))));
-  }
-
-  /*
-  named!(does_not_compile,
-    alt!(tag!("abcd"), tag!("efgh"))
-  );
-  */
-}
diff --git a/src/branch/mod.rs b/src/branch/mod.rs
index 55d3633..9df5a29 100644
--- a/src/branch/mod.rs
+++ b/src/branch/mod.rs
@@ -1,26 +1,52 @@
-//! choice combinators
+//! Choice combinators
 
-#[macro_use]
-mod macros;
+macro_rules! succ (
+  (0, $submac:ident ! ($($rest:tt)*)) => ($submac!(1, $($rest)*));
+  (1, $submac:ident ! ($($rest:tt)*)) => ($submac!(2, $($rest)*));
+  (2, $submac:ident ! ($($rest:tt)*)) => ($submac!(3, $($rest)*));
+  (3, $submac:ident ! ($($rest:tt)*)) => ($submac!(4, $($rest)*));
+  (4, $submac:ident ! ($($rest:tt)*)) => ($submac!(5, $($rest)*));
+  (5, $submac:ident ! ($($rest:tt)*)) => ($submac!(6, $($rest)*));
+  (6, $submac:ident ! ($($rest:tt)*)) => ($submac!(7, $($rest)*));
+  (7, $submac:ident ! ($($rest:tt)*)) => ($submac!(8, $($rest)*));
+  (8, $submac:ident ! ($($rest:tt)*)) => ($submac!(9, $($rest)*));
+  (9, $submac:ident ! ($($rest:tt)*)) => ($submac!(10, $($rest)*));
+  (10, $submac:ident ! ($($rest:tt)*)) => ($submac!(11, $($rest)*));
+  (11, $submac:ident ! ($($rest:tt)*)) => ($submac!(12, $($rest)*));
+  (12, $submac:ident ! ($($rest:tt)*)) => ($submac!(13, $($rest)*));
+  (13, $submac:ident ! ($($rest:tt)*)) => ($submac!(14, $($rest)*));
+  (14, $submac:ident ! ($($rest:tt)*)) => ($submac!(15, $($rest)*));
+  (15, $submac:ident ! ($($rest:tt)*)) => ($submac!(16, $($rest)*));
+  (16, $submac:ident ! ($($rest:tt)*)) => ($submac!(17, $($rest)*));
+  (17, $submac:ident ! ($($rest:tt)*)) => ($submac!(18, $($rest)*));
+  (18, $submac:ident ! ($($rest:tt)*)) => ($submac!(19, $($rest)*));
+  (19, $submac:ident ! ($($rest:tt)*)) => ($submac!(20, $($rest)*));
+  (20, $submac:ident ! ($($rest:tt)*)) => ($submac!(21, $($rest)*));
+);
+
+#[cfg(test)]
+mod tests;
 
 use crate::error::ErrorKind;
 use crate::error::ParseError;
-use crate::internal::{Err, IResult};
+use crate::internal::{Err, IResult, Parser};
 
-/// helper trait for the [alt()] combinator
+/// Helper trait for the [alt()] combinator.
 ///
-/// this trait is implemented for tuples of up to 21 elements
+/// This trait is implemented for tuples of up to 21 elements
 pub trait Alt<I, O, E> {
-  /// tests each parser in the tuple and returns the result of the first one that succeeds
-  fn choice(&self, input: I) -> IResult<I, O, E>;
+  /// Tests each parser in the tuple and returns the result of the first one that succeeds
+  fn choice(&mut self, input: I) -> IResult<I, O, E>;
 }
 
-/// tests a list of parsers one by one until one succeeds
+/// Tests a list of parsers one by one until one succeeds.
 ///
-/// It takes as argument a tuple of parsers.
+/// It takes as argument a tuple of parsers. There is a maximum of 21
+/// parsers. If you need more, it is possible to nest them in other `alt` calls,
+/// like this: `alt(parser_a, alt(parser_b, parser_c))`
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
+/// # use nom::error_position;
 /// # use nom::{Err,error::ErrorKind, Needed, IResult};
 /// use nom::character::complete::{alpha1, digit1};
 /// use nom::branch::alt;
@@ -40,35 +66,36 @@
 /// # }
 /// ```
 ///
-/// with a custom error type, it is possible to have alt return the error of the parser
+/// With a custom error type, it is possible to have alt return the error of the parser
 /// that went the farthest in the input data
-pub fn alt<I: Clone, O, E: ParseError<I>, List: Alt<I, O, E>>(l: List) -> impl Fn(I) -> IResult<I, O, E> {
+pub fn alt<I: Clone, O, E: ParseError<I>, List: Alt<I, O, E>>(
+  mut l: List,
+) -> impl FnMut(I) -> IResult<I, O, E> {
   move |i: I| l.choice(i)
 }
 
-/// helper trait for the [permutation()] combinator
+/// Helper trait for the [permutation()] combinator.
 ///
-/// this trait is implemented for tuples of up to 21 elements
+/// This trait is implemented for tuples of up to 21 elements
 pub trait Permutation<I, O, E> {
-  /// tries to apply all parsers in the tuple in various orders until all of them succeed
-  fn permutation(&self, input: I) -> IResult<I, O, E>;
+  /// Tries to apply all parsers in the tuple in various orders until all of them succeed
+  fn permutation(&mut self, input: I) -> IResult<I, O, E>;
 }
 
-/// applies a list of parsers in any order
+/// Applies a list of parsers in any order.
 ///
-/// permutation will succeed if all of the child parsers succeeded.
+/// Permutation will succeed if all of the child parsers succeeded.
 /// It takes as argument a tuple of parsers, and returns a
 /// tuple of the parser results.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,error::ErrorKind, Needed, IResult};
+/// # use nom::{Err,error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::character::complete::{alpha1, digit1};
 /// use nom::branch::permutation;
 /// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, (&str, &str)> {
 ///   permutation((alpha1, digit1))(input)
-/// };
+/// }
 ///
 /// // permutation recognizes alphabetic characters then digit
 /// assert_eq!(parser("abc123"), Ok(("", ("abc", "123"))));
@@ -77,10 +104,32 @@
 /// assert_eq!(parser("123abc"), Ok(("", ("abc", "123"))));
 ///
 /// // it will fail if one of the parsers failed
-/// assert_eq!(parser("abc;"), Err(Err::Error(error_position!(";", ErrorKind::Permutation))));
+/// assert_eq!(parser("abc;"), Err(Err::Error(Error::new(";", ErrorKind::Digit))));
 /// # }
 /// ```
-pub fn permutation<I: Clone, O, E: ParseError<I>, List: Permutation<I, O, E>>(l: List) -> impl Fn(I) -> IResult<I, O, E> {
+///
+/// The parsers are applied greedily: if there are multiple unapplied parsers
+/// that could parse the next slice of input, the first one is used.
+/// ```rust
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult};
+/// use nom::branch::permutation;
+/// use nom::character::complete::{anychar, char};
+///
+/// fn parser(input: &str) -> IResult<&str, (char, char)> {
+///   permutation((anychar, char('a')))(input)
+/// }
+///
+/// // anychar parses 'b', then char('a') parses 'a'
+/// assert_eq!(parser("ba"), Ok(("", ('b', 'a'))));
+///
+/// // anychar parses 'a', then char('a') fails on 'b',
+/// // even though char('a') followed by anychar would succeed
+/// assert_eq!(parser("ab"), Err(Err::Error(Error::new("b", ErrorKind::Char))));
+/// ```
+///
+pub fn permutation<I: Clone, O, E: ParseError<I>, List: Permutation<I, O, E>>(
+  mut l: List,
+) -> impl FnMut(I) -> IResult<I, O, E> {
   move |i: I| l.permutation(i)
 }
 
@@ -103,14 +152,14 @@
   ($($id:ident)+) => (
     impl<
       Input: Clone, Output, Error: ParseError<Input>,
-      $($id: Fn(Input) -> IResult<Input, Output, Error>),+
+      $($id: Parser<Input, Output, Error>),+
     > Alt<Input, Output, Error> for ( $($id),+ ) {
 
-      fn choice(&self, input: Input) -> IResult<Input, Output, Error> {
-        let mut err: Option<Error> = None;
-        alt_trait_inner!(0, self, input, err, $($id)+);
-
-        Err(Err::Error(Error::append(input, ErrorKind::Alt, err.unwrap())))
+      fn choice(&mut self, input: Input) -> IResult<Input, Output, Error> {
+        match self.0.parse(input.clone()) {
+          Err(Err::Error(e)) => alt_trait_inner!(1, self, input, e, $($id)+),
+          res => res,
+        }
       }
     }
   );
@@ -118,75 +167,76 @@
 
 macro_rules! alt_trait_inner(
   ($it:tt, $self:expr, $input:expr, $err:expr, $head:ident $($id:ident)+) => (
-    match $self.$it($input.clone()) {
+    match $self.$it.parse($input.clone()) {
       Err(Err::Error(e)) => {
-        $err = Some(match $err.take() {
-          None => e,
-          Some(prev) => prev.or(e),
-        });
-        succ!($it, alt_trait_inner!($self, $input, $err, $($id)+))
-      },
-      res => return res,
+        let err = $err.or(e);
+        succ!($it, alt_trait_inner!($self, $input, err, $($id)+))
+      }
+      res => res,
     }
   );
   ($it:tt, $self:expr, $input:expr, $err:expr, $head:ident) => (
-    match $self.$it($input.clone()) {
-      Err(Err::Error(e)) => {
-        $err = Some(match $err.take() {
-          None => e,
-          Some(prev) => prev.or(e),
-        });
-      },
-      res => return res,
-    }
+    Err(Err::Error(Error::append($input, ErrorKind::Alt, $err)))
   );
 );
 
 alt_trait!(A B C D E F G H I J K L M N O P Q R S T U);
 
+// Manually implement Alt for (A,), the 1-tuple type
+impl<Input, Output, Error: ParseError<Input>, A: Parser<Input, Output, Error>>
+  Alt<Input, Output, Error> for (A,)
+{
+  fn choice(&mut self, input: Input) -> IResult<Input, Output, Error> {
+    self.0.parse(input)
+  }
+}
+
 macro_rules! permutation_trait(
-  ($name1:ident $ty1:ident, $name2:ident $ty2:ident) => (
-    permutation_trait_impl!($name1 $ty1, $name2 $ty2);
+  (
+    $name1:ident $ty1:ident $item1:ident
+    $name2:ident $ty2:ident $item2:ident
+    $($name3:ident $ty3:ident $item3:ident)*
+  ) => (
+    permutation_trait!(__impl $name1 $ty1 $item1, $name2 $ty2 $item2; $($name3 $ty3 $item3)*);
   );
-  ($name1:ident $ty1:ident, $name2: ident $ty2:ident, $($name:ident $ty:ident),*) => (
-    permutation_trait!(__impl $name1 $ty1, $name2 $ty2; $($name $ty),*);
+  (
+    __impl $($name:ident $ty:ident $item:ident),+;
+    $name1:ident $ty1:ident $item1:ident $($name2:ident $ty2:ident $item2:ident)*
+  ) => (
+    permutation_trait_impl!($($name $ty $item),+);
+    permutation_trait!(__impl $($name $ty $item),+ , $name1 $ty1 $item1; $($name2 $ty2 $item2)*);
   );
-  (__impl $($name:ident $ty: ident),+; $name1:ident $ty1:ident, $($name2:ident $ty2:ident),*) => (
-    permutation_trait_impl!($($name $ty),+);
-    permutation_trait!(__impl $($name $ty),+ , $name1 $ty1; $($name2 $ty2),*);
-  );
-  (__impl $($name:ident $ty: ident),+; $name1:ident $ty1:ident) => (
-    permutation_trait_impl!($($name $ty),+);
-    permutation_trait_impl!($($name $ty),+, $name1 $ty1);
+  (__impl $($name:ident $ty:ident $item:ident),+;) => (
+    permutation_trait_impl!($($name $ty $item),+);
   );
 );
 
 macro_rules! permutation_trait_impl(
-  ($($name:ident $ty: ident),+) => (
+  ($($name:ident $ty:ident $item:ident),+) => (
     impl<
       Input: Clone, $($ty),+ , Error: ParseError<Input>,
-      $($name: Fn(Input) -> IResult<Input, $ty, Error>),+
+      $($name: Parser<Input, $ty, Error>),+
     > Permutation<Input, ( $($ty),+ ), Error> for ( $($name),+ ) {
 
-      fn permutation(&self, mut input: Input) -> IResult<Input, ( $($ty),+ ), Error> {
-        let mut res = permutation_init!((), $($name),+);
+      fn permutation(&mut self, mut input: Input) -> IResult<Input, ( $($ty),+ ), Error> {
+        let mut res = ($(Option::<$ty>::None),+);
 
         loop {
-          let mut all_done = true;
-          permutation_trait_inner!(0, self, input, res, all_done, $($name)+);
+          let mut err: Option<Error> = None;
+          permutation_trait_inner!(0, self, input, res, err, $($name)+);
 
-          //if we reach that part, it means none of the parsers were able to read anything
-          if !all_done {
-            //FIXME: should wrap the error returned by the child parser
-            return Err(Err::Error(error_position!(input, ErrorKind::Permutation)));
+          // If we reach here, every iterator has either been applied before,
+          // or errored on the remaining input
+          if let Some(err) = err {
+            // There are remaining parsers, and all errored on the remaining input
+            return Err(Err::Error(Error::append(input, ErrorKind::Permutation, err)));
           }
-          break;
-        }
 
-        if let Some(unwrapped_res) = { permutation_trait_unwrap!(0, (), res, $($name),+) } {
-          Ok((input, unwrapped_res))
-        } else {
-          Err(Err::Error(error_position!(input, ErrorKind::Permutation)))
+          // All parsers were applied
+          match res {
+            ($(Some($item)),+) => return Ok((input, ($($item),+))),
+            _ => unreachable!(),
+          }
         }
       }
     }
@@ -194,70 +244,48 @@
 );
 
 macro_rules! permutation_trait_inner(
-  ($it:tt, $self:expr, $input:ident, $res:expr, $all_done:expr, $head:ident $($id:ident)+) => ({
+  ($it:tt, $self:expr, $input:ident, $res:expr, $err:expr, $head:ident $($id:ident)*) => (
     if $res.$it.is_none() {
-      match $self.$it($input.clone()) {
-        Ok((i,o))     => {
+      match $self.$it.parse($input.clone()) {
+        Ok((i, o)) => {
           $input = i;
           $res.$it = Some(o);
           continue;
-        },
-        Err(Err::Error(_)) => {
-          $all_done = false;
-        },
-        Err(e) => {
-          return Err(e);
         }
+        Err(Err::Error(e)) => {
+          $err = Some(match $err {
+            Some(err) => err.or(e),
+            None => e,
+          });
+        }
+        Err(e) => return Err(e),
       };
     }
-    succ!($it, permutation_trait_inner!($self, $input, $res, $all_done, $($id)+));
-  });
-  ($it:tt, $self:expr, $input:ident, $res:expr, $all_done:expr, $head:ident) => ({
-    if $res.$it.is_none() {
-      match $self.$it($input.clone()) {
-        Ok((i,o))     => {
-          $input = i;
-          $res.$it = Some(o);
-          continue;
-        },
-        Err(Err::Error(_)) => {
-          $all_done = false;
-        },
-        Err(e) => {
-          return Err(e);
-        }
-      };
-    }
-  });
+    succ!($it, permutation_trait_inner!($self, $input, $res, $err, $($id)*));
+  );
+  ($it:tt, $self:expr, $input:ident, $res:expr, $err:expr,) => ();
 );
 
-macro_rules! permutation_trait_unwrap (
-  ($it:tt,  (), $res:ident, $e:ident, $($name:ident),+) => ({
-    let res = $res.$it;
-    if res.is_some() {
-      succ!($it, permutation_trait_unwrap!((res.unwrap()), $res, $($name),+))
-    } else {
-      $crate::lib::std::option::Option::None
-    }
-  });
-
-  ($it:tt, ($($parsed:expr),*), $res:ident, $e:ident, $($name:ident),+) => ({
-    let res = $res.$it;
-    if res.is_some() {
-      succ!($it, permutation_trait_unwrap!(($($parsed),* , res.unwrap()), $res, $($name),+))
-    } else {
-      $crate::lib::std::option::Option::None
-    }
-  });
-
-  ($it:tt, ($($parsed:expr),*), $res:ident, $name:ident) => ({
-    let res = $res.$it;
-    if res.is_some() {
-      $crate::lib::std::option::Option::Some(($($parsed),* , res.unwrap() ))
-    } else {
-      $crate::lib::std::option::Option::None
-    }
-  });
+permutation_trait!(
+  FnA A a
+  FnB B b
+  FnC C c
+  FnD D d
+  FnE E e
+  FnF F f
+  FnG G g
+  FnH H h
+  FnI I i
+  FnJ J j
+  FnK K k
+  FnL L l
+  FnM M m
+  FnN N n
+  FnO O o
+  FnP P p
+  FnQ Q q
+  FnR R r
+  FnS S s
+  FnT T t
+  FnU U u
 );
-
-permutation_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);
diff --git a/src/branch/tests.rs b/src/branch/tests.rs
new file mode 100644
index 0000000..ecd4440
--- /dev/null
+++ b/src/branch/tests.rs
@@ -0,0 +1,142 @@
+use crate::branch::{alt, permutation};
+use crate::bytes::streaming::tag;
+use crate::error::ErrorKind;
+use crate::internal::{Err, IResult, Needed};
+#[cfg(feature = "alloc")]
+use crate::{
+  error::ParseError,
+  lib::std::{
+    fmt::Debug,
+    string::{String, ToString},
+  },
+};
+
+#[cfg(feature = "alloc")]
+#[derive(Debug, Clone, PartialEq)]
+pub struct ErrorStr(String);
+
+#[cfg(feature = "alloc")]
+impl From<u32> for ErrorStr {
+  fn from(i: u32) -> Self {
+    ErrorStr(format!("custom error code: {}", i))
+  }
+}
+
+#[cfg(feature = "alloc")]
+impl<'a> From<&'a str> for ErrorStr {
+  fn from(i: &'a str) -> Self {
+    ErrorStr(format!("custom error message: {}", i))
+  }
+}
+
+#[cfg(feature = "alloc")]
+impl<I: Debug> ParseError<I> for ErrorStr {
+  fn from_error_kind(input: I, kind: ErrorKind) -> Self {
+    ErrorStr(format!("custom error message: ({:?}, {:?})", input, kind))
+  }
+
+  fn append(input: I, kind: ErrorKind, other: Self) -> Self {
+    ErrorStr(format!(
+      "custom error message: ({:?}, {:?}) - {:?}",
+      input, kind, other
+    ))
+  }
+}
+
+#[cfg(feature = "alloc")]
+#[test]
+fn alt_test() {
+  fn work(input: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
+    Ok((&b""[..], input))
+  }
+
+  #[allow(unused_variables)]
+  fn dont_work(input: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
+    Err(Err::Error(ErrorStr("abcd".to_string())))
+  }
+
+  fn work2(input: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
+    Ok((input, &b""[..]))
+  }
+
+  fn alt1(i: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
+    alt((dont_work, dont_work))(i)
+  }
+  fn alt2(i: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
+    alt((dont_work, work))(i)
+  }
+  fn alt3(i: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
+    alt((dont_work, dont_work, work2, dont_work))(i)
+  }
+  //named!(alt1, alt!(dont_work | dont_work));
+  //named!(alt2, alt!(dont_work | work));
+  //named!(alt3, alt!(dont_work | dont_work | work2 | dont_work));
+
+  let a = &b"abcd"[..];
+  assert_eq!(
+    alt1(a),
+    Err(Err::Error(error_node_position!(
+      a,
+      ErrorKind::Alt,
+      ErrorStr("abcd".to_string())
+    )))
+  );
+  assert_eq!(alt2(a), Ok((&b""[..], a)));
+  assert_eq!(alt3(a), Ok((a, &b""[..])));
+
+  fn alt4(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    alt((tag("abcd"), tag("efgh")))(i)
+  }
+  let b = &b"efgh"[..];
+  assert_eq!(alt4(a), Ok((&b""[..], a)));
+  assert_eq!(alt4(b), Ok((&b""[..], b)));
+}
+
+#[test]
+fn alt_incomplete() {
+  fn alt1(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    alt((tag("a"), tag("bc"), tag("def")))(i)
+  }
+
+  let a = &b""[..];
+  assert_eq!(alt1(a), Err(Err::Incomplete(Needed::new(1))));
+  let a = &b"b"[..];
+  assert_eq!(alt1(a), Err(Err::Incomplete(Needed::new(1))));
+  let a = &b"bcd"[..];
+  assert_eq!(alt1(a), Ok((&b"d"[..], &b"bc"[..])));
+  let a = &b"cde"[..];
+  assert_eq!(alt1(a), Err(Err::Error(error_position!(a, ErrorKind::Tag))));
+  let a = &b"de"[..];
+  assert_eq!(alt1(a), Err(Err::Incomplete(Needed::new(1))));
+  let a = &b"defg"[..];
+  assert_eq!(alt1(a), Ok((&b"g"[..], &b"def"[..])));
+}
+
+#[test]
+fn permutation_test() {
+  fn perm(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8], &[u8])> {
+    permutation((tag("abcd"), tag("efg"), tag("hi")))(i)
+  }
+
+  let expected = (&b"abcd"[..], &b"efg"[..], &b"hi"[..]);
+
+  let a = &b"abcdefghijk"[..];
+  assert_eq!(perm(a), Ok((&b"jk"[..], expected)));
+  let b = &b"efgabcdhijk"[..];
+  assert_eq!(perm(b), Ok((&b"jk"[..], expected)));
+  let c = &b"hiefgabcdjk"[..];
+  assert_eq!(perm(c), Ok((&b"jk"[..], expected)));
+
+  let d = &b"efgxyzabcdefghi"[..];
+  assert_eq!(
+    perm(d),
+    Err(Err::Error(error_node_position!(
+      &b"efgxyzabcdefghi"[..],
+      ErrorKind::Permutation,
+      error_position!(&b"xyzabcdefghi"[..], ErrorKind::Tag)
+    )))
+  );
+
+  let e = &b"efgabc"[..];
+  assert_eq!(perm(e), Err(Err::Incomplete(Needed::new(1))));
+}
diff --git a/src/bytes/complete.rs b/src/bytes/complete.rs
index 8bf4220..9375b1f 100644
--- a/src/bytes/complete.rs
+++ b/src/bytes/complete.rs
@@ -1,11 +1,14 @@
-//! parsers recognizing bytes streams, complete input version
+//! Parsers recognizing bytes streams, complete input version
 
 use crate::error::ErrorKind;
 use crate::error::ParseError;
-use crate::internal::{Err, IResult};
+use crate::internal::{Err, IResult, Parser};
 use crate::lib::std::ops::RangeFrom;
 use crate::lib::std::result::Result::*;
-use crate::traits::{Compare, CompareResult, FindSubstring, FindToken, InputIter, InputLength, InputTake, InputTakeAtPosition, Slice, ToUsize};
+use crate::traits::{
+  Compare, CompareResult, FindSubstring, FindToken, InputIter, InputLength, InputTake,
+  InputTakeAtPosition, Slice, ToUsize,
+};
 
 /// Recognizes a pattern
 ///
@@ -15,8 +18,7 @@
 /// It will return `Err(Err::Error((_, ErrorKind::Tag)))` if the input doesn't match the pattern
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::complete::tag;
 ///
 /// fn parser(s: &str) -> IResult<&str, &str> {
@@ -24,10 +26,12 @@
 /// }
 ///
 /// assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
-/// assert_eq!(parser("Something"), Err(Err::Error(("Something", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
+/// assert_eq!(parser("Something"), Err(Err::Error(Error::new("Something", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
 /// ```
-pub fn tag<'a, T: 'a, Input: 'a, Error: ParseError<Input>>(tag: T) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn tag<T, Input, Error: ParseError<Input>>(
+  tag: T,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTake + Compare<T>,
   T: InputLength + Clone,
@@ -46,16 +50,15 @@
   }
 }
 
-/// Recognizes a case insensitive pattern
+/// Recognizes a case insensitive pattern.
 ///
 /// The input data will be compared to the tag combinator's argument and will return the part of
-/// the input that matches the argument with no regard to case
+/// the input that matches the argument with no regard to case.
 ///
-/// It will return `Err(Err::Error((_, ErrorKind::Tag)))` if the input doesn't match the pattern
+/// It will return `Err(Err::Error((_, ErrorKind::Tag)))` if the input doesn't match the pattern.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::complete::tag_no_case;
 ///
 /// fn parser(s: &str) -> IResult<&str, &str> {
@@ -65,10 +68,12 @@
 /// assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
 /// assert_eq!(parser("hello, World!"), Ok((", World!", "hello")));
 /// assert_eq!(parser("HeLlO, World!"), Ok((", World!", "HeLlO")));
-/// assert_eq!(parser("Something"), Err(Err::Error(("Something", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
+/// assert_eq!(parser("Something"), Err(Err::Error(Error::new("Something", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
 /// ```
-pub fn tag_no_case<T, Input, Error: ParseError<Input>>(tag: T) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn tag_no_case<T, Input, Error: ParseError<Input>>(
+  tag: T,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTake + Compare<T>,
   T: InputLength + Clone,
@@ -88,17 +93,16 @@
   }
 }
 
-/// Parse till certain characters are met
+/// Parse till certain characters are met.
 ///
 /// The parser will return the longest slice till one of the characters of the combinator's argument are met.
 ///
-/// It doesn't consume the matched character,
+/// It doesn't consume the matched character.
 ///
-/// It will return a `Err::Error(("", ErrorKind::IsNot))` if the pattern wasn't met
+/// It will return a `Err::Error(("", ErrorKind::IsNot))` if the pattern wasn't met.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::complete::is_not;
 ///
 /// fn not_space(s: &str) -> IResult<&str, &str> {
@@ -108,12 +112,14 @@
 /// assert_eq!(not_space("Hello, World!"), Ok((" World!", "Hello,")));
 /// assert_eq!(not_space("Sometimes\t"), Ok(("\t", "Sometimes")));
 /// assert_eq!(not_space("Nospace"), Ok(("", "Nospace")));
-/// assert_eq!(not_space(""), Err(Err::Error(("", ErrorKind::IsNot))));
+/// assert_eq!(not_space(""), Err(Err::Error(Error::new("", ErrorKind::IsNot))));
 /// ```
-pub fn is_not<T, Input, Error: ParseError<Input>>(arr: T) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn is_not<T, Input, Error: ParseError<Input>>(
+  arr: T,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTakeAtPosition,
-  T: InputLength + FindToken<<Input as InputTakeAtPosition>::Item>,
+  T: FindToken<<Input as InputTakeAtPosition>::Item>,
 {
   move |i: Input| {
     let e: ErrorKind = ErrorKind::IsNot;
@@ -121,17 +127,15 @@
   }
 }
 
-/// Returns the longest slice of the matches the pattern
+/// Returns the longest slice of the matches the pattern.
 ///
 /// The parser will return the longest slice consisting of the characters in provided in the
-/// combinator's argument
+/// combinator's argument.
 ///
-/// It will return a `Err(Err::Error((_, ErrorKind::IsA)))` if the pattern wasn't met
-///
+/// It will return a `Err(Err::Error((_, ErrorKind::IsA)))` if the pattern wasn't met.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::complete::is_a;
 ///
 /// fn hex(s: &str) -> IResult<&str, &str> {
@@ -142,12 +146,14 @@
 /// assert_eq!(hex("DEADBEEF and others"), Ok((" and others", "DEADBEEF")));
 /// assert_eq!(hex("BADBABEsomething"), Ok(("something", "BADBABE")));
 /// assert_eq!(hex("D15EA5E"), Ok(("", "D15EA5E")));
-/// assert_eq!(hex(""), Err(Err::Error(("", ErrorKind::IsA))));
+/// assert_eq!(hex(""), Err(Err::Error(Error::new("", ErrorKind::IsA))));
 /// ```
-pub fn is_a<T, Input, Error: ParseError<Input>>(arr: T) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn is_a<T, Input, Error: ParseError<Input>>(
+  arr: T,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTakeAtPosition,
-  T: InputLength + FindToken<<Input as InputTakeAtPosition>::Item>,
+  T: FindToken<<Input as InputTakeAtPosition>::Item>,
 {
   move |i: Input| {
     let e: ErrorKind = ErrorKind::IsA;
@@ -155,14 +161,12 @@
   }
 }
 
-/// Returns the longest input slice (if any) that matches the predicate
+/// Returns the longest input slice (if any) that matches the predicate.
 ///
 /// The parser will return the longest slice that matches the given predicate *(a function that
-/// takes the input and returns a bool)*
-///
+/// takes the input and returns a bool)*.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// use nom::bytes::complete::take_while;
 /// use nom::character::is_alphabetic;
@@ -176,7 +180,9 @@
 /// assert_eq!(alpha(b"latin"), Ok((&b""[..], &b"latin"[..])));
 /// assert_eq!(alpha(b""), Ok((&b""[..], &b""[..])));
 /// ```
-pub fn take_while<F, Input, Error: ParseError<Input>>(cond: F) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take_while<F, Input, Error: ParseError<Input>>(
+  cond: F,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTakeAtPosition,
   F: Fn(<Input as InputTakeAtPosition>::Item) -> bool,
@@ -184,17 +190,15 @@
   move |i: Input| i.split_at_position_complete(|c| !cond(c))
 }
 
-/// Returns the longest (atleast 1) input slice that matches the predicate
+/// Returns the longest (at least 1) input slice that matches the predicate.
 ///
 /// The parser will return the longest slice that matches the given predicate *(a function that
-/// takes the input and returns a bool)*
+/// takes the input and returns a bool)*.
 ///
-/// It will return an `Err(Err::Error((_, ErrorKind::TakeWhile1)))` if the pattern wasn't met
-///
+/// It will return an `Err(Err::Error((_, ErrorKind::TakeWhile1)))` if the pattern wasn't met.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::complete::take_while1;
 /// use nom::character::is_alphabetic;
 ///
@@ -204,9 +208,11 @@
 ///
 /// assert_eq!(alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
 /// assert_eq!(alpha(b"latin"), Ok((&b""[..], &b"latin"[..])));
-/// assert_eq!(alpha(b"12345"), Err(Err::Error((&b"12345"[..], ErrorKind::TakeWhile1))));
+/// assert_eq!(alpha(b"12345"), Err(Err::Error(Error::new(&b"12345"[..], ErrorKind::TakeWhile1))));
 /// ```
-pub fn take_while1<F, Input, Error: ParseError<Input>>(cond: F) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take_while1<F, Input, Error: ParseError<Input>>(
+  cond: F,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTakeAtPosition,
   F: Fn(<Input as InputTakeAtPosition>::Item) -> bool,
@@ -217,18 +223,16 @@
   }
 }
 
-/// Returns the longest (m <= len <= n) input slice  that matches the predicate
+/// Returns the longest (m <= len <= n) input slice  that matches the predicate.
 ///
 /// The parser will return the longest slice that matches the given predicate *(a function that
-/// takes the input and returns a bool)*
+/// takes the input and returns a bool)*.
 ///
 /// It will return an `Err::Error((_, ErrorKind::TakeWhileMN))` if the pattern wasn't met or is out
-/// of range (m <= len <= n)
-///
+/// of range (m <= len <= n).
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::complete::take_while_m_n;
 /// use nom::character::is_alphabetic;
 ///
@@ -239,10 +243,14 @@
 /// assert_eq!(short_alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
 /// assert_eq!(short_alpha(b"lengthy"), Ok((&b"y"[..], &b"length"[..])));
 /// assert_eq!(short_alpha(b"latin"), Ok((&b""[..], &b"latin"[..])));
-/// assert_eq!(short_alpha(b"ed"), Err(Err::Error((&b"ed"[..], ErrorKind::TakeWhileMN))));
-/// assert_eq!(short_alpha(b"12345"), Err(Err::Error((&b"12345"[..], ErrorKind::TakeWhileMN))));
+/// assert_eq!(short_alpha(b"ed"), Err(Err::Error(Error::new(&b"ed"[..], ErrorKind::TakeWhileMN))));
+/// assert_eq!(short_alpha(b"12345"), Err(Err::Error(Error::new(&b"12345"[..], ErrorKind::TakeWhileMN))));
 /// ```
-pub fn take_while_m_n<F, Input, Error: ParseError<Input>>(m: usize, n: usize, cond: F) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take_while_m_n<F, Input, Error: ParseError<Input>>(
+  m: usize,
+  n: usize,
+  cond: F,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTake + InputIter + InputLength + Slice<RangeFrom<usize>>,
   F: Fn(<Input as InputIter>::Item) -> bool,
@@ -254,17 +262,23 @@
       Some(idx) => {
         if idx >= m {
           if idx <= n {
-            let res: IResult<_, _, Error> = if let Some(index) = input.slice_index(idx) {
+            let res: IResult<_, _, Error> = if let Ok(index) = input.slice_index(idx) {
               Ok(input.take_split(index))
             } else {
-              Err(Err::Error(Error::from_error_kind(input, ErrorKind::TakeWhileMN)))
+              Err(Err::Error(Error::from_error_kind(
+                input,
+                ErrorKind::TakeWhileMN,
+              )))
             };
             res
           } else {
-            let res: IResult<_, _, Error> = if let Some(index) = input.slice_index(n) {
+            let res: IResult<_, _, Error> = if let Ok(index) = input.slice_index(n) {
               Ok(input.take_split(index))
             } else {
-              Err(Err::Error(Error::from_error_kind(input, ErrorKind::TakeWhileMN)))
+              Err(Err::Error(Error::from_error_kind(
+                input,
+                ErrorKind::TakeWhileMN,
+              )))
             };
             res
           }
@@ -277,31 +291,30 @@
         let len = input.input_len();
         if len >= n {
           match input.slice_index(n) {
-            Some(index) => Ok(input.take_split(index)),
-            None => Err(Err::Error(Error::from_error_kind(input, ErrorKind::TakeWhileMN)))
+            Ok(index) => Ok(input.take_split(index)),
+            Err(_needed) => Err(Err::Error(Error::from_error_kind(
+              input,
+              ErrorKind::TakeWhileMN,
+            ))),
           }
+        } else if len >= m && len <= n {
+          let res: IResult<_, _, Error> = Ok((input.slice(len..), input));
+          res
         } else {
-          if len >= m && len <= n {
-            let res: IResult<_, _, Error> = Ok((input.slice(len..), input));
-            res
-          } else {
-            let e = ErrorKind::TakeWhileMN;
-            Err(Err::Error(Error::from_error_kind(input, e)))
-          }
+          let e = ErrorKind::TakeWhileMN;
+          Err(Err::Error(Error::from_error_kind(input, e)))
         }
       }
     }
   }
 }
 
-/// Returns the longest input slice (if any) till a predicate is met
+/// Returns the longest input slice (if any) till a predicate is met.
 ///
 /// The parser will return the longest slice till the given predicate *(a function that
-/// takes the input and returns a bool)*
-///
+/// takes the input and returns a bool)*.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// use nom::bytes::complete::take_till;
 ///
@@ -314,7 +327,9 @@
 /// assert_eq!(till_colon("12345"), Ok(("", "12345")));
 /// assert_eq!(till_colon(""), Ok(("", "")));
 /// ```
-pub fn take_till<F, Input, Error: ParseError<Input>>(cond: F) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take_till<F, Input, Error: ParseError<Input>>(
+  cond: F,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTakeAtPosition,
   F: Fn(<Input as InputTakeAtPosition>::Item) -> bool,
@@ -322,18 +337,16 @@
   move |i: Input| i.split_at_position_complete(|c| cond(c))
 }
 
-/// Returns the longest (atleast 1) input slice till a predicate is met
+/// Returns the longest (at least 1) input slice till a predicate is met.
 ///
 /// The parser will return the longest slice till the given predicate *(a function that
-/// takes the input and returns a bool)*
+/// takes the input and returns a bool)*.
 ///
 /// It will return `Err(Err::Error((_, ErrorKind::TakeTill1)))` if the input is empty or the
-/// predicate matches the first input
-///
+/// predicate matches the first input.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::complete::take_till1;
 ///
 /// fn till_colon(s: &str) -> IResult<&str, &str> {
@@ -341,11 +354,13 @@
 /// }
 ///
 /// assert_eq!(till_colon("latin:123"), Ok((":123", "latin")));
-/// assert_eq!(till_colon(":empty matched"), Err(Err::Error((":empty matched", ErrorKind::TakeTill1))));
+/// assert_eq!(till_colon(":empty matched"), Err(Err::Error(Error::new(":empty matched", ErrorKind::TakeTill1))));
 /// assert_eq!(till_colon("12345"), Ok(("", "12345")));
-/// assert_eq!(till_colon(""), Err(Err::Error(("", ErrorKind::TakeTill1))));
+/// assert_eq!(till_colon(""), Err(Err::Error(Error::new("", ErrorKind::TakeTill1))));
 /// ```
-pub fn take_till1<F, Input, Error: ParseError<Input>>(cond: F) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take_till1<F, Input, Error: ParseError<Input>>(
+  cond: F,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTakeAtPosition,
   F: Fn(<Input as InputTakeAtPosition>::Item) -> bool,
@@ -356,14 +371,12 @@
   }
 }
 
-/// Returns an input slice containing the first N input elements (Input[..N])
+/// Returns an input slice containing the first N input elements (Input[..N]).
 ///
-/// It will return `Err(Err::Error((_, ErrorKind::Eof)))` if the input is shorter than the argument
-///
+/// It will return `Err(Err::Error((_, ErrorKind::Eof)))` if the input is shorter than the argument.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::complete::take;
 ///
 /// fn take6(s: &str) -> IResult<&str, &str> {
@@ -372,30 +385,30 @@
 ///
 /// assert_eq!(take6("1234567"), Ok(("7", "123456")));
 /// assert_eq!(take6("things"), Ok(("", "things")));
-/// assert_eq!(take6("short"), Err(Err::Error(("short", ErrorKind::Eof))));
-/// assert_eq!(take6(""), Err(Err::Error(("", ErrorKind::Eof))));
+/// assert_eq!(take6("short"), Err(Err::Error(Error::new("short", ErrorKind::Eof))));
+/// assert_eq!(take6(""), Err(Err::Error(Error::new("", ErrorKind::Eof))));
 /// ```
-pub fn take<C, Input, Error: ParseError<Input>>(count: C) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take<C, Input, Error: ParseError<Input>>(
+  count: C,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputIter + InputTake,
   C: ToUsize,
 {
   let c = count.to_usize();
   move |i: Input| match i.slice_index(c) {
-    None => Err(Err::Error(Error::from_error_kind(i, ErrorKind::Eof))),
-    Some(index) => Ok(i.take_split(index)),
+    Err(_needed) => Err(Err::Error(Error::from_error_kind(i, ErrorKind::Eof))),
+    Ok(index) => Ok(i.take_split(index)),
   }
 }
 
-/// 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
-///
+/// if the pattern wasn't met.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::complete::take_until;
 ///
 /// fn until_eof(s: &str) -> IResult<&str, &str> {
@@ -403,10 +416,13 @@
 /// }
 ///
 /// assert_eq!(until_eof("hello, worldeof"), Ok(("eof", "hello, world")));
-/// assert_eq!(until_eof("hello, world"), Err(Err::Error(("hello, world", ErrorKind::TakeUntil))));
-/// assert_eq!(until_eof(""), Err(Err::Error(("", ErrorKind::TakeUntil))));
+/// 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) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take_until<T, Input, Error: ParseError<Input>>(
+  tag: T,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTake + FindSubstring<T>,
   T: InputLength + Clone,
@@ -421,15 +437,50 @@
   }
 }
 
+/// Returns the non empty 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.
+/// # Example
+/// ```rust
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
+/// use nom::bytes::complete::take_until1;
+///
+/// fn until_eof(s: &str) -> IResult<&str, &str> {
+///   take_until1("eof")(s)
+/// }
+///
+/// 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")));
+/// assert_eq!(until_eof("eof"), Err(Err::Error(Error::new("eof", ErrorKind::TakeUntil))));
+/// ```
+pub fn take_until1<T, Input, Error: ParseError<Input>>(
+  tag: T,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
+where
+  Input: InputTake + FindSubstring<T>,
+  T: InputLength + Clone,
+{
+  move |i: Input| {
+    let t = tag.clone();
+    let res: IResult<_, _, Error> = match i.find_substring(t) {
+      None => Err(Err::Error(Error::from_error_kind(i, ErrorKind::TakeUntil))),
+      Some(0) => Err(Err::Error(Error::from_error_kind(i, ErrorKind::TakeUntil))),
+      Some(index) => Ok(i.take_split(index)),
+    };
+    res
+  }
+}
+
 /// Matches a byte string with escaped characters.
 ///
-/// * The first argument matches the normal characters (it must not accept the control character),
-/// * the second argument is the control character (like `\` in most languages),
-/// * the third argument matches the escaped characters
-///
+/// * The first argument matches the normal characters (it must not accept the control character)
+/// * The second argument is the control character (like `\` in most languages)
+/// * The third argument matches the escaped characters
 /// # Example
 /// ```
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// # use nom::character::complete::digit1;
 /// use nom::bytes::complete::escaped;
@@ -443,12 +494,22 @@
 /// assert_eq!(esc(r#"12\"34;"#), Ok((";", r#"12\"34"#)));
 /// ```
 ///
-pub fn escaped<Input, Error, F, G, O1, O2>(normal: F, control_char: char, escapable: G) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn escaped<'a, Input: 'a, Error, F, G, O1, O2>(
+  mut normal: F,
+  control_char: char,
+  mut escapable: G,
+) -> impl FnMut(Input) -> IResult<Input, Input, Error>
 where
-  Input: Clone + crate::traits::Offset + InputLength + InputTake + InputTakeAtPosition + Slice<RangeFrom<usize>> + InputIter,
+  Input: Clone
+    + crate::traits::Offset
+    + InputLength
+    + InputTake
+    + InputTakeAtPosition
+    + Slice<RangeFrom<usize>>
+    + InputIter,
   <Input as InputIter>::Item: crate::traits::AsChar,
-  F: Fn(Input) -> IResult<Input, O1, Error>,
-  G: Fn(Input) -> IResult<Input, O2, Error>,
+  F: Parser<Input, O1, Error>,
+  G: Parser<Input, O2, Error>,
   Error: ParseError<Input>,
 {
   use crate::traits::AsChar;
@@ -457,10 +518,17 @@
     let mut i = input.clone();
 
     while i.input_len() > 0 {
-      match normal(i.clone()) {
+      let current_len = i.input_len();
+
+      match normal.parse(i.clone()) {
         Ok((i2, _)) => {
+          // return if we consumed everything or if the normal parser
+          // does not consume anything
           if i2.input_len() == 0 {
             return Ok((input.slice(input.input_len()..), input));
+          } else if i2.input_len() == current_len {
+            let index = input.offset(&i2);
+            return Ok(input.take_split(index));
           } else {
             i = i2;
           }
@@ -470,9 +538,12 @@
           if i.iter_elements().next().unwrap().as_char() == control_char {
             let next = control_char.len_utf8();
             if next >= i.input_len() {
-              return Err(Err::Error(Error::from_error_kind(input, ErrorKind::Escaped)));
+              return Err(Err::Error(Error::from_error_kind(
+                input,
+                ErrorKind::Escaped,
+              )));
             } else {
-              match escapable(i.slice(next..)) {
+              match escapable.parse(i.slice(next..)) {
                 Ok((i2, _)) => {
                   if i2.input_len() == 0 {
                     return Ok((input.slice(input.input_len()..), input));
@@ -486,7 +557,10 @@
           } else {
             let index = input.offset(&i);
             if index == 0 {
-              return Err(Err::Error(Error::from_error_kind(input, ErrorKind::Escaped)));
+              return Err(Err::Error(Error::from_error_kind(
+                input,
+                ErrorKind::Escaped,
+              )));
             }
             return Ok(input.take_split(index));
           }
@@ -501,64 +575,58 @@
   }
 }
 
-#[doc(hidden)]
-pub fn escapedc<Input, Error, F, G, O1, O2>(i: Input, normal: F, control_char: char, escapable: G) -> IResult<Input, Input, Error>
-where
-  Input: Clone + crate::traits::Offset + InputLength + InputTake + InputTakeAtPosition + Slice<RangeFrom<usize>> + InputIter,
-  <Input as InputIter>::Item: crate::traits::AsChar,
-  F: Fn(Input) -> IResult<Input, O1, Error>,
-  G: Fn(Input) -> IResult<Input, O2, Error>,
-  Error: ParseError<Input>,
-{
-  escaped(normal, control_char, escapable)(i)
-}
-
 /// Matches a byte string with escaped characters.
 ///
-/// * The first argument matches the normal characters (it must not match the control character),
-/// * the second argument is the control character (like `\` in most languages),
-/// * the third argument matches the escaped characters and transforms them.
+/// * The first argument matches the normal characters (it must not match the control character)
+/// * The second argument is the control character (like `\` in most languages)
+/// * The third argument matches the escaped characters and transforms them
 ///
 /// As an example, the chain `abc\tdef` could be `abc    def` (it also consumes the control character)
 ///
 /// ```
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// # use std::str::from_utf8;
-/// use nom::bytes::complete::escaped_transform;
+/// use nom::bytes::complete::{escaped_transform, tag};
 /// use nom::character::complete::alpha1;
+/// use nom::branch::alt;
+/// use nom::combinator::value;
 ///
 /// fn parser(input: &str) -> IResult<&str, String> {
 ///   escaped_transform(
 ///     alpha1,
 ///     '\\',
-///     |i:&str| alt!(i,
-///         tag!("\\")       => { |_| "\\" }
-///       | tag!("\"")       => { |_| "\"" }
-///       | tag!("n")        => { |_| "\n" }
-///     )
+///     alt((
+///       value("\\", tag("\\")),
+///       value("\"", tag("\"")),
+///       value("\n", tag("n")),
+///     ))
 ///   )(input)
 /// }
 ///
 /// assert_eq!(parser("ab\\\"cd"), Ok(("", String::from("ab\"cd"))));
+/// assert_eq!(parser("ab\\ncd"), Ok(("", String::from("ab\ncd"))));
 /// ```
 #[cfg(feature = "alloc")]
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
 pub fn escaped_transform<Input, Error, F, G, O1, O2, ExtendItem, Output>(
-  normal: F,
+  mut normal: F,
   control_char: char,
-  transform: G,
-) -> impl Fn(Input) -> IResult<Input, Output, Error>
+  mut transform: G,
+) -> impl FnMut(Input) -> IResult<Input, Output, Error>
 where
-  Input: Clone + crate::traits::Offset + InputLength + InputTake + InputTakeAtPosition + Slice<RangeFrom<usize>> + InputIter,
+  Input: Clone
+    + crate::traits::Offset
+    + InputLength
+    + InputTake
+    + InputTakeAtPosition
+    + Slice<RangeFrom<usize>>
+    + InputIter,
   Input: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
   O1: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
   O2: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
-  Output: core::iter::Extend<<Input as crate::traits::ExtendInto>::Item>,
-  Output: core::iter::Extend<<O1 as crate::traits::ExtendInto>::Item>,
-  Output: core::iter::Extend<<O2 as crate::traits::ExtendInto>::Item>,
   <Input as InputIter>::Item: crate::traits::AsChar,
-  F: Fn(Input) -> IResult<Input, O1, Error>,
-  G: Fn(Input) -> IResult<Input, O2, Error>,
+  F: Parser<Input, O1, Error>,
+  G: Parser<Input, O2, Error>,
   Error: ParseError<Input>,
 {
   use crate::traits::AsChar;
@@ -570,12 +638,15 @@
     let i = input.clone();
 
     while index < i.input_len() {
+      let current_len = i.input_len();
       let remainder = i.slice(index..);
-      match normal(remainder.clone()) {
+      match normal.parse(remainder.clone()) {
         Ok((i2, o)) => {
           o.extend_into(&mut res);
           if i2.input_len() == 0 {
             return Ok((i.slice(i.input_len()..), res));
+          } else if i2.input_len() == current_len {
+            return Ok((remainder, res));
           } else {
             index = input.offset(&i2);
           }
@@ -587,9 +658,12 @@
             let input_len = input.input_len();
 
             if next >= input_len {
-              return Err(Err::Error(Error::from_error_kind(remainder, ErrorKind::EscapedTransform)));
+              return Err(Err::Error(Error::from_error_kind(
+                remainder,
+                ErrorKind::EscapedTransform,
+              )));
             } else {
-              match transform(i.slice(next..)) {
+              match transform.parse(i.slice(next..)) {
                 Ok((i2, o)) => {
                   o.extend_into(&mut res);
                   if i2.input_len() == 0 {
@@ -603,7 +677,10 @@
             }
           } else {
             if index == 0 {
-              return Err(Err::Error(Error::from_error_kind(remainder, ErrorKind::EscapedTransform)));
+              return Err(Err::Error(Error::from_error_kind(
+                remainder,
+                ErrorKind::EscapedTransform,
+              )));
             }
             return Ok((remainder, res));
           }
@@ -615,44 +692,53 @@
   }
 }
 
-#[doc(hidden)]
-#[cfg(feature = "alloc")]
-pub fn escaped_transformc<Input, Error, F, G, O1, O2, ExtendItem, Output>(
-  i: Input,
-  normal: F,
-  control_char: char,
-  transform: G,
-) -> IResult<Input, Output, Error>
-where
-  Input: Clone + crate::traits::Offset + InputLength + InputTake + InputTakeAtPosition + Slice<RangeFrom<usize>> + InputIter,
-  Input: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
-  O1: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
-  O2: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
-  Output: core::iter::Extend<<Input as crate::traits::ExtendInto>::Item>,
-  Output: core::iter::Extend<<O1 as crate::traits::ExtendInto>::Item>,
-  Output: core::iter::Extend<<O2 as crate::traits::ExtendInto>::Item>,
-  <Input as InputIter>::Item: crate::traits::AsChar,
-  F: Fn(Input) -> IResult<Input, O1, Error>,
-  G: Fn(Input) -> IResult<Input, O2, Error>,
-  Error: ParseError<Input>,
-{
-  escaped_transform(normal, control_char, transform)(i)
-
-}
-
 #[cfg(test)]
 mod tests {
   use super::*;
 
   #[test]
   fn complete_take_while_m_n_utf8_all_matching() {
-    let result: IResult<&str, &str> = super::take_while_m_n(1, 4, |c: char| c.is_alphabetic())("øn");
+    let result: IResult<&str, &str> =
+      super::take_while_m_n(1, 4, |c: char| c.is_alphabetic())("øn");
     assert_eq!(result, Ok(("", "øn")));
   }
 
   #[test]
   fn complete_take_while_m_n_utf8_all_matching_substring() {
-    let result: IResult<&str, &str> = super::take_while_m_n(1, 1, |c: char| c.is_alphabetic())("øn");
+    let result: IResult<&str, &str> =
+      super::take_while_m_n(1, 1, |c: char| c.is_alphabetic())("øn");
     assert_eq!(result, Ok(("n", "ø")));
   }
+
+  // issue #1336 "escaped hangs if normal parser accepts empty"
+  fn escaped_string(input: &str) -> IResult<&str, &str> {
+    use crate::character::complete::{alpha0, one_of};
+    escaped(alpha0, '\\', one_of("n"))(input)
+  }
+
+  // issue #1336 "escaped hangs if normal parser accepts empty"
+  #[test]
+  fn escaped_hang() {
+    escaped_string("7").unwrap();
+    escaped_string("a7").unwrap();
+  }
+
+  // issue ##1118 escaped does not work with empty string
+  fn unquote<'a>(input: &'a str) -> IResult<&'a str, &'a str> {
+    use crate::bytes::complete::*;
+    use crate::character::complete::*;
+    use crate::combinator::opt;
+    use crate::sequence::delimited;
+
+    delimited(
+      char('"'),
+      escaped(opt(none_of(r#"\""#)), '\\', one_of(r#"\"rnt"#)),
+      char('"'),
+    )(input)
+  }
+
+  #[test]
+  fn escaped_hang_1118() {
+    assert_eq!(unquote(r#""""#), Ok(("", "")));
+  }
 }
diff --git a/src/bytes/macros.rs b/src/bytes/macros.rs
deleted file mode 100644
index 1e24ba8..0000000
--- a/src/bytes/macros.rs
+++ /dev/null
@@ -1,938 +0,0 @@
-//! Byte level parsers and combinators
-//!
-#[allow(unused_variables)]
-
-/// `tag!(&[T]: nom::AsBytes) => &[T] -> IResult<&[T], &[T]>`
-/// declares a byte array as a suite to recognize
-///
-/// consumes the recognized characters
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(x, tag!("abcd"));
-///  let r = x(&b"abcdefgh"[..]);
-///  assert_eq!(r, Ok((&b"efgh"[..], &b"abcd"[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! tag (
-  ($i:expr, $tag: expr) => ({
-    $crate::bytes::streaming::tag($tag)($i)
-  });
-);
-
-/// `tag_no_case!(&[T]) => &[T] -> IResult<&[T], &[T]>`
-/// declares a case insensitive ascii string as a suite to recognize
-///
-/// consumes the recognized characters
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(test, tag_no_case!("ABcd"));
-///
-///  let r = test(&b"aBCdefgh"[..]);
-///  assert_eq!(r, Ok((&b"efgh"[..], &b"aBCd"[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! tag_no_case (
-  ($i:expr, $tag: expr) => ({
-    $crate::bytes::streaming::tag_no_case($tag)($i)
-  });
-);
-
-/// `is_not!(&[T:AsBytes]) => &[T] -> IResult<&[T], &[T]>`
-/// returns the longest list of bytes that do not appear in the provided array
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!( not_space, is_not!( " \t\r\n" ) );
-///
-///  let r = not_space(&b"abcdefgh\nijkl"[..]);
-///  assert_eq!(r, Ok((&b"\nijkl"[..], &b"abcdefgh"[..])));
-///  # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! is_not (
-  ($input:expr, $arr:expr) => ({
-    $crate::bytes::streaming::is_not($arr)($input)
-  });
-);
-
-/// `is_a!(&[T]) => &[T] -> IResult<&[T], &[T]>`
-/// returns the longest list of bytes that appear in the provided array
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(abcd, is_a!( "abcd" ));
-///
-///  let r1 = abcd(&b"aaaaefgh"[..]);
-///  assert_eq!(r1, Ok((&b"efgh"[..], &b"aaaa"[..])));
-///
-///  let r2 = abcd(&b"dcbaefgh"[..]);
-///  assert_eq!(r2, Ok((&b"efgh"[..], &b"dcba"[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! is_a (
-  ($input:expr, $arr:expr) => ({
-    $crate::bytes::streaming::is_a($arr)($input)
-  });
-);
-
-/// `escaped!(T -> IResult<T, T>, U, T -> IResult<T, T>) => T -> IResult<T, T> where T: InputIter,
-/// U: AsChar`
-/// matches a byte string with escaped characters.
-///
-/// The first argument matches the normal characters (it must not accept the control character),
-/// the second argument is the control character (like `\` in most languages),
-/// the third argument matches the escaped characters
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::character::complete::digit1;
-/// # fn main() {
-///  named!(esc, escaped!(call!(digit1), '\\', one_of!("\"n\\")));
-///  assert_eq!(esc(&b"123;"[..]), Ok((&b";"[..], &b"123"[..])));
-///  assert_eq!(esc(&b"12\\\"34;"[..]), Ok((&b";"[..], &b"12\\\"34"[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! escaped (
-  ($i:expr, $submac1:ident!( $($args:tt)* ), $control_char: expr, $submac2:ident!( $($args2:tt)*) ) => (
-    {
-     escaped!($i, |i| $submac1!(i, $($args)*), $control_char,  |i| $submac2!(i, $($args2)*))
-    }
-  );
-  ($i:expr, $normal:expr, $control_char: expr, $submac2:ident!( $($args2:tt)*) ) => (
-    {
-     escaped!($i, $normal, $control_char,  |i| $submac2!(i, $($args2)*))
-    }
-  );
-  ($i:expr, $submac1:ident!( $($args:tt)* ), $control_char: expr, $escapable:expr ) => (
-    {
-     escaped!($i, |i| $submac1!(i, $($args)*), $control_char,  $escapable)
-    }
-  );
-  ($i:expr, $normal:expr, $control_char: expr, $escapable:expr) => (
-    {
-      $crate::bytes::complete::escapedc($i, $normal, $control_char, $escapable)
-    }
-  );
-);
-
-/// `escaped_transform!(&[T] -> IResult<&[T], &[T]>, T, &[T] -> IResult<&[T], &[T]>) => &[T] -> IResult<&[T], Vec<T>>`
-/// matches a byte string with escaped characters.
-///
-/// The first argument matches the normal characters (it must not match the control character),
-/// the second argument is the control character (like `\` in most languages),
-/// the third argument matches the escaped characters and transforms them.
-///
-/// As an example, the chain `abc\tdef` could be `abc    def` (it also consumes the control character)
-///
-/// # Example
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::character::complete::alpha1;
-/// # use nom::lib::std::str::from_utf8;
-/// # fn main() {
-/// fn to_s(i:Vec<u8>) -> String {
-///   String::from_utf8_lossy(&i).into_owned()
-/// }
-///
-///  named!(transform < String >,
-///    map!(
-///      escaped_transform!(call!(alpha1), '\\',
-///        alt!(
-///            tag!("\\")       => { |_| &b"\\"[..] }
-///          | tag!("\"")       => { |_| &b"\""[..] }
-///          | tag!("n")        => { |_| &b"\n"[..] }
-///        )
-///      ), to_s
-///    )
-///  );
-///  assert_eq!(transform(&b"ab\\\"cd"[..]), Ok((&b""[..], String::from("ab\"cd"))));
-/// # }
-/// ```
-#[cfg(feature = "alloc")]
-#[macro_export(local_inner_macros)]
-macro_rules! escaped_transform (
-  ($i:expr, $submac1:ident!( $($args:tt)* ), $control_char: expr, $submac2:ident!( $($args2:tt)*) ) => (
-    {
-     escaped_transform!($i, |i| $submac1!(i, $($args)*), $control_char,  |i| $submac2!(i, $($args2)*))
-    }
-  );
-  ($i:expr, $normal:expr, $control_char: expr, $submac2:ident!( $($args2:tt)*) ) => (
-    {
-     escaped_transform!($i, $normal, $control_char,  |i| $submac2!(i, $($args2)*))
-    }
-  );
-  ($i:expr, $submac1:ident!( $($args:tt)* ), $control_char: expr, $transform:expr ) => (
-    {
-     escaped_transform!($i, |i| $submac1!(i, $($args)*), $control_char,  $transform)
-    }
-  );
-  ($i:expr, $normal:expr, $control_char: expr, $transform:expr) => (
-    {
-      $crate::bytes::complete::escaped_transformc($i, $normal, $control_char, $transform)
-    }
-  );
-);
-
-/// `take_while!(T -> bool) => &[T] -> IResult<&[T], &[T]>`
-/// returns the longest list of bytes until the provided function fails.
-///
-/// The argument is either a function `T -> bool` or a macro returning a `bool`.
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::character::is_alphanumeric;
-/// # fn main() {
-///  named!( alpha, take_while!( is_alphanumeric ) );
-///
-///  let r = alpha(&b"abcd\nefgh"[..]);
-///  assert_eq!(r, Ok((&b"\nefgh"[..], &b"abcd"[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! take_while (
-  ($input:expr, $submac:ident!( $($args:tt)* )) => ({
-    let res: $crate::IResult<_, _, _> = take_while!($input, (|c| $submac!(c, $($args)*)));
-    res
-  });
-  ($input:expr, $f:expr) => (
-    $crate::bytes::streaming::take_while($f)($input)
-  );
-);
-
-/// `take_while1!(T -> bool) => &[T] -> IResult<&[T], &[T]>`
-/// returns the longest (non empty) list of bytes until the provided function fails.
-///
-/// The argument is either a function `&[T] -> bool` or a macro returning a `bool`
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,error::ErrorKind};
-/// # use nom::character::is_alphanumeric;
-/// # fn main() {
-///  named!( alpha, take_while1!( is_alphanumeric ) );
-///
-///  let r = alpha(&b"abcd\nefgh"[..]);
-///  assert_eq!(r, Ok((&b"\nefgh"[..], &b"abcd"[..])));
-///  let r = alpha(&b"\nefgh"[..]);
-///  assert_eq!(r, Err(Err::Error(error_position!(&b"\nefgh"[..], ErrorKind::TakeWhile1))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! take_while1 (
-  ($input:expr, $submac:ident!( $($args:tt)* )) => ({
-    let res: $crate::IResult<_, _, _> = take_while1!($input, (|c| $submac!(c, $($args)*)));
-    res
-  });
-  ($input:expr, $f:expr) => (
-    $crate::bytes::streaming::take_while1($f)($input)
-  );
-);
-
-/// `take_while_m_n!(m: usize, n: usize, T -> bool) => &[T] -> IResult<&[T], &[T]>`
-/// returns a list of bytes or characters for which the provided function returns true.
-/// the returned list's size will be at least m, and at most n
-///
-/// The argument is either a function `T -> bool` or a macro returning a `bool`.
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::character::is_alphanumeric;
-/// # fn main() {
-///  named!( alpha, take_while_m_n!(3, 6, is_alphanumeric ) );
-///
-///  let r = alpha(&b"abcd\nefgh"[..]);
-///  assert_eq!(r, Ok((&b"\nefgh"[..], &b"abcd"[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! take_while_m_n (
-  ($input:expr, $m:expr, $n: expr, $submac:ident!( $($args:tt)* )) => ({
-    let res: $crate::IResult<_, _, _> = take_while_m_n!($input, $m, $n, (|c| $submac!(c, $($args)*)));
-    res
-  });
-  ($input:expr, $m:expr, $n:expr, $f:expr) => (
-    $crate::bytes::streaming::take_while_m_n($m, $n, $f)($input)
-  );
-);
-
-/// `take_till!(T -> bool) => &[T] -> IResult<&[T], &[T]>`
-/// returns the longest list of bytes until the provided function succeeds
-///
-/// The argument is either a function `&[T] -> bool` or a macro returning a `bool`.
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!( till_colon, take_till!(|ch| ch == b':') );
-///
-///  let r = till_colon(&b"abcd:efgh"[..]);
-///  assert_eq!(r, Ok((&b":efgh"[..], &b"abcd"[..])));
-///  let r2 = till_colon(&b":abcdefgh"[..]); // empty match is allowed
-///  assert_eq!(r2, Ok((&b":abcdefgh"[..], &b""[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! take_till (
-  ($input:expr, $submac:ident!( $($args:tt)* )) => ({
-    let res: $crate::IResult<_, _, _> = take_till!($input, (|c| $submac!(c, $($args)*)));
-    res
-  });
-  ($input:expr, $f:expr) => (
-    $crate::bytes::streaming::take_till($f)($input)
-  );
-);
-
-/// `take_till1!(T -> bool) => &[T] -> IResult<&[T], &[T]>`
-/// returns the longest non empty list of bytes until the provided function succeeds
-///
-/// The argument is either a function `&[T] -> bool` or a macro returning a `bool`.
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind};
-/// # fn main() {
-///  named!( till1_colon, take_till1!(|ch| ch == b':') );
-///
-///  let r = till1_colon(&b"abcd:efgh"[..]);
-///  assert_eq!(r, Ok((&b":efgh"[..], &b"abcd"[..])));
-///
-///  let r2 = till1_colon(&b":abcdefgh"[..]); // empty match is error
-///  assert_eq!(r2, Err(Err::Error(error_position!(&b":abcdefgh"[..], ErrorKind::TakeTill1))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! take_till1 (
-  ($input:expr, $submac:ident!( $($args:tt)* )) => ({
-    let res: $crate::IResult<_, _, _> = take_till1!($input, (|c| $submac!(c, $($args)*)));
-    res
-  });
-  ($input:expr, $f:expr) => (
-    $crate::bytes::streaming::take_till1($f)($input)
-  );
-);
-
-/// `take!(nb) => &[T] -> IResult<&[T], &[T]>`
-/// generates a parser consuming the specified number of bytes
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  // Desmond parser
-///  named!(take5, take!( 5 ) );
-///
-///  let a = b"abcdefgh";
-///
-///  assert_eq!(take5(&a[..]), Ok((&b"fgh"[..], &b"abcde"[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! take (
-  ($i:expr, $count:expr) => ({
-    let c = $count as usize;
-    let res: $crate::IResult<_,_,_> = $crate::bytes::streaming::take(c)($i);
-    res
-  });
-);
-
-/// `take_str!(nb) => &[T] -> IResult<&[T], &str>`
-/// same as take! but returning a &str
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(take5( &[u8] ) -> &str, take_str!( 5 ) );
-///
-///  let a = b"abcdefgh";
-///
-///  assert_eq!(take5(&a[..]), Ok((&b"fgh"[..], "abcde")));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! take_str (
- ( $i:expr, $size:expr ) => (
-    {
-      let input: &[u8] = $i;
-
-      map_res!(input, take!($size), $crate::lib::std::str::from_utf8)
-    }
-  );
-);
-
-/// `take_until!(tag) => &[T] -> IResult<&[T], &[T]>`
-/// consumes data until it finds the specified tag.
-///
-/// The remainder still contains the tag.
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(x, take_until!("foo"));
-///  let r = x(&b"abcd foo efgh"[..]);
-///  assert_eq!(r, Ok((&b"foo efgh"[..], &b"abcd "[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! take_until (
-  ($i:expr, $substr:expr) => ({
-    let res: $crate::IResult<_,_,_> = $crate::bytes::streaming::take_until($substr)($i);
-    res
-  });
-);
-
-/// `take_until1!(tag) => &[T] -> IResult<&[T], &[T]>`
-/// consumes data (at least one byte) until it finds the specified tag
-///
-/// The remainder still contains the tag.
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(x, take_until1!("foo"));
-///
-///  let r = x(&b"abcd foo efgh"[..]);
-///
-///  assert_eq!(r, Ok((&b"foo efgh"[..], &b"abcd "[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! take_until1 (
-  ($i:expr, $substr:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::lib::std::option::Option::*;
-      use $crate::{Err,Needed,IResult,error::ErrorKind};
-      use $crate::InputLength;
-      use $crate::FindSubstring;
-      use $crate::InputTake;
-      let input = $i;
-
-      let res: IResult<_,_> = match input.find_substring($substr) {
-        None => {
-          Err(Err::Incomplete(Needed::Size(1 + $substr.input_len())))
-        },
-        Some(0) => {
-          let e = ErrorKind::TakeUntil;
-          Err(Err::Error(error_position!($i, e)))
-        },
-        Some(index) => {
-          Ok($i.take_split(index))
-        },
-      };
-      res
-    }
-  );
-);
-
-#[cfg(test)]
-mod tests {
-  use crate::internal::{Err, Needed, IResult};
-  #[cfg(feature = "alloc")]
-  use crate::lib::std::string::String;
-  #[cfg(feature = "alloc")]
-  use crate::lib::std::vec::Vec;
-  use crate::character::streaming::{alpha1 as alpha, alphanumeric1 as alphanumeric, digit1 as digit, hex_digit1 as hex_digit, multispace1 as multispace, oct_digit1 as oct_digit, space1 as space};
-  use crate::error::ErrorKind;
-  use crate::character::is_alphabetic;
-
-  #[cfg(feature = "alloc")]
-  macro_rules! one_of (
-    ($i:expr, $inp: expr) => (
-      {
-        use $crate::Err;
-        use $crate::Slice;
-        use $crate::AsChar;
-        use $crate::FindToken;
-        use $crate::InputIter;
-
-        match ($i).iter_elements().next().map(|c| {
-          $inp.find_token(c)
-        }) {
-          None        => Err::<_,_>(Err::Incomplete(Needed::Size(1))),
-          Some(false) => Err(Err::Error(error_position!($i, ErrorKind::OneOf))),
-          //the unwrap should be safe here
-          Some(true)  => Ok(($i.slice(1..), $i.iter_elements().next().unwrap().as_char()))
-        }
-      }
-    );
-  );
-
-  #[test]
-  fn is_a() {
-    named!(a_or_b, is_a!(&b"ab"[..]));
-
-    let a = &b"abcd"[..];
-    assert_eq!(a_or_b(a), Ok((&b"cd"[..], &b"ab"[..])));
-
-    let b = &b"bcde"[..];
-    assert_eq!(a_or_b(b), Ok((&b"cde"[..], &b"b"[..])));
-
-    let c = &b"cdef"[..];
-    assert_eq!(a_or_b(c), Err(Err::Error(error_position!(c, ErrorKind::IsA))));
-
-    let d = &b"bacdef"[..];
-    assert_eq!(a_or_b(d), Ok((&b"cdef"[..], &b"ba"[..])));
-  }
-
-  #[test]
-  fn is_not() {
-    named!(a_or_b, is_not!(&b"ab"[..]));
-
-    let a = &b"cdab"[..];
-    assert_eq!(a_or_b(a), Ok((&b"ab"[..], &b"cd"[..])));
-
-    let b = &b"cbde"[..];
-    assert_eq!(a_or_b(b), Ok((&b"bde"[..], &b"c"[..])));
-
-    let c = &b"abab"[..];
-    assert_eq!(a_or_b(c), Err(Err::Error(error_position!(c, ErrorKind::IsNot))));
-
-    let d = &b"cdefba"[..];
-    assert_eq!(a_or_b(d), Ok((&b"ba"[..], &b"cdef"[..])));
-
-    let e = &b"e"[..];
-    assert_eq!(a_or_b(e), Err(Err::Incomplete(Needed::Size(1))));
-  }
-
-  #[cfg(feature = "alloc")]
-  #[allow(unused_variables)]
-  #[test]
-  fn escaping() {
-    named!(esc, escaped!(call!(alpha), '\\', one_of!("\"n\\")));
-    assert_eq!(esc(&b"abcd;"[..]), Ok((&b";"[..], &b"abcd"[..])));
-    assert_eq!(esc(&b"ab\\\"cd;"[..]), Ok((&b";"[..], &b"ab\\\"cd"[..])));
-    assert_eq!(esc(&b"\\\"abcd;"[..]), Ok((&b";"[..], &b"\\\"abcd"[..])));
-    assert_eq!(esc(&b"\\n;"[..]), Ok((&b";"[..], &b"\\n"[..])));
-    assert_eq!(esc(&b"ab\\\"12"[..]), Ok((&b"12"[..], &b"ab\\\""[..])));
-    assert_eq!(esc(&b"AB\\"[..]), Err(Err::Error(error_position!(&b"AB\\"[..], ErrorKind::Escaped))));
-    assert_eq!(
-      esc(&b"AB\\A"[..]),
-      Err(Err::Error(error_node_position!(
-        &b"AB\\A"[..],
-        ErrorKind::Escaped,
-        error_position!(&b"A"[..], ErrorKind::OneOf)
-      )))
-    );
-
-    named!(esc2, escaped!(call!(digit), '\\', one_of!("\"n\\")));
-    assert_eq!(esc2(&b"12\\nnn34"[..]), Ok((&b"nn34"[..], &b"12\\n"[..])));
-  }
-
-  #[cfg(feature = "alloc")]
-  #[test]
-  fn escaping_str() {
-    named!(esc<&str, &str>, escaped!(call!(alpha), '\\', one_of!("\"n\\")));
-    assert_eq!(esc("abcd;"), Ok((";", "abcd")));
-    assert_eq!(esc("ab\\\"cd;"), Ok((";", "ab\\\"cd")));
-    assert_eq!(esc("\\\"abcd;"), Ok((";", "\\\"abcd")));
-    assert_eq!(esc("\\n;"), Ok((";", "\\n")));
-    assert_eq!(esc("ab\\\"12"), Ok(("12", "ab\\\"")));
-    assert_eq!(esc("AB\\"), Err(Err::Error(error_position!("AB\\", ErrorKind::Escaped))));
-    assert_eq!(
-      esc("AB\\A"),
-      Err(Err::Error(error_node_position!(
-        "AB\\A",
-        ErrorKind::Escaped,
-        error_position!("A", ErrorKind::OneOf)
-      )))
-    );
-
-    named!(esc2<&str, &str>, escaped!(call!(digit), '\\', one_of!("\"n\\")));
-    assert_eq!(esc2("12\\nnn34"), Ok(("nn34", "12\\n")));
-
-    named!(esc3<&str, &str>, escaped!(call!(alpha), '\u{241b}', one_of!("\"n")));
-    assert_eq!(esc3("ab␛ncd;"), Ok((";", "ab␛ncd")));
-  }
-
-  #[cfg(feature = "alloc")]
-  fn to_s(i: Vec<u8>) -> String {
-    String::from_utf8_lossy(&i).into_owned()
-  }
-
-  #[cfg(feature = "alloc")]
-  #[test]
-  fn escape_transform() {
-    use crate::lib::std::str;
-
-    named!(
-      esc<String>,
-      map!(
-        escaped_transform!(
-          alpha,
-          '\\',
-          alt!(
-              tag!("\\")       => { |_| &b"\\"[..] }
-            | tag!("\"")       => { |_| &b"\""[..] }
-            | tag!("n")        => { |_| &b"\n"[..] }
-          )
-        ),
-        to_s
-      )
-    );
-
-    assert_eq!(esc(&b"abcd;"[..]), Ok((&b";"[..], String::from("abcd"))));
-    assert_eq!(esc(&b"ab\\\"cd;"[..]), Ok((&b";"[..], String::from("ab\"cd"))));
-    assert_eq!(esc(&b"\\\"abcd;"[..]), Ok((&b";"[..], String::from("\"abcd"))));
-    assert_eq!(esc(&b"\\n;"[..]), Ok((&b";"[..], String::from("\n"))));
-    assert_eq!(esc(&b"ab\\\"12"[..]), Ok((&b"12"[..], String::from("ab\""))));
-    assert_eq!(esc(&b"AB\\"[..]), Err(Err::Error(error_position!(&b"\\"[..], ErrorKind::EscapedTransform))));
-    assert_eq!(
-      esc(&b"AB\\A"[..]),
-      Err(Err::Error(error_node_position!(
-        &b"AB\\A"[..],
-        ErrorKind::EscapedTransform,
-        error_position!(&b"A"[..], ErrorKind::Alt)
-      )))
-    );
-
-    named!(
-      esc2<String>,
-      map!(
-        escaped_transform!(
-          call!(alpha),
-          '&',
-          alt!(
-              tag!("egrave;") => { |_| str::as_bytes("è") }
-            | tag!("agrave;") => { |_| str::as_bytes("à") }
-          )
-        ),
-        to_s
-      )
-    );
-    assert_eq!(esc2(&b"ab&egrave;DEF;"[..]), Ok((&b";"[..], String::from("abèDEF"))));
-    assert_eq!(esc2(&b"ab&egrave;D&agrave;EF;"[..]), Ok((&b";"[..], String::from("abèDàEF"))));
-  }
-
-  #[cfg(feature = "std")]
-  #[test]
-  fn escape_transform_str() {
-    named!(esc<&str, String>, escaped_transform!(alpha, '\\',
-      alt!(
-          tag!("\\")       => { |_| "\\" }
-        | tag!("\"")       => { |_| "\"" }
-        | tag!("n")        => { |_| "\n" }
-      ))
-    );
-
-    assert_eq!(esc("abcd;"), Ok((";", String::from("abcd"))));
-    assert_eq!(esc("ab\\\"cd;"), Ok((";", String::from("ab\"cd"))));
-    assert_eq!(esc("\\\"abcd;"), Ok((";", String::from("\"abcd"))));
-    assert_eq!(esc("\\n;"), Ok((";", String::from("\n"))));
-    assert_eq!(esc("ab\\\"12"), Ok(("12", String::from("ab\""))));
-    assert_eq!(esc("AB\\"), Err(Err::Error(error_position!("\\", ErrorKind::EscapedTransform))));
-    assert_eq!(
-      esc("AB\\A"),
-      Err(Err::Error(error_node_position!(
-        "AB\\A",
-        ErrorKind::EscapedTransform,
-        error_position!("A", ErrorKind::Alt)
-      )))
-    );
-
-    named!(esc2<&str, String>, escaped_transform!(alpha, '&',
-      alt!(
-          tag!("egrave;") => { |_| "è" }
-        | tag!("agrave;") => { |_| "à" }
-      ))
-    );
-    assert_eq!(esc2("ab&egrave;DEF;"), Ok((";", String::from("abèDEF"))));
-    assert_eq!(esc2("ab&egrave;D&agrave;EF;"), Ok((";", String::from("abèDàEF"))));
-
-    named!(esc3<&str, String>, escaped_transform!(alpha, '␛',
-      alt!(
-        tag!("0") => { |_| "\0" } |
-        tag!("n") => { |_| "\n" })));
-    assert_eq!(esc3("a␛0bc␛n"), Ok(("", String::from("a\0bc\n"))));
-  }
-
-  #[test]
-  fn take_str_test() {
-    let a = b"omnomnom";
-
-    let res: IResult<_,_,(&[u8], ErrorKind)> = take_str!(&a[..], 5u32);
-    assert_eq!(res, Ok((&b"nom"[..], "omnom")));
-
-    let res: IResult<_,_,(&[u8], ErrorKind)> = take_str!(&a[..], 9u32);
-    assert_eq!(res, Err(Err::Incomplete(Needed::Size(9))));
-  }
-
-  #[test]
-  fn take_until_incomplete() {
-    named!(y, take_until!("end"));
-    assert_eq!(y(&b"nd"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(y(&b"123"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(y(&b"123en"[..]), Err(Err::Incomplete(Needed::Size(3))));
-  }
-
-  #[test]
-  fn take_until_incomplete_s() {
-    named!(ys<&str, &str>, take_until!("end"));
-    assert_eq!(ys("123en"), Err(Err::Incomplete(Needed::Size(3))));
-  }
-
-  #[test]
-  fn recognize() {
-    named!(x, recognize!(delimited!(tag!("<!--"), take!(5usize), tag!("-->"))));
-    let r = x(&b"<!-- abc --> aaa"[..]);
-    assert_eq!(r, Ok((&b" aaa"[..], &b"<!-- abc -->"[..])));
-
-    let semicolon = &b";"[..];
-
-    named!(ya, recognize!(alpha));
-    let ra = ya(&b"abc;"[..]);
-    assert_eq!(ra, Ok((semicolon, &b"abc"[..])));
-
-    named!(yd, recognize!(digit));
-    let rd = yd(&b"123;"[..]);
-    assert_eq!(rd, Ok((semicolon, &b"123"[..])));
-
-    named!(yhd, recognize!(hex_digit));
-    let rhd = yhd(&b"123abcDEF;"[..]);
-    assert_eq!(rhd, Ok((semicolon, &b"123abcDEF"[..])));
-
-    named!(yod, recognize!(oct_digit));
-    let rod = yod(&b"1234567;"[..]);
-    assert_eq!(rod, Ok((semicolon, &b"1234567"[..])));
-
-    named!(yan, recognize!(alphanumeric));
-    let ran = yan(&b"123abc;"[..]);
-    assert_eq!(ran, Ok((semicolon, &b"123abc"[..])));
-
-    named!(ys, recognize!(space));
-    let rs = ys(&b" \t;"[..]);
-    assert_eq!(rs, Ok((semicolon, &b" \t"[..])));
-
-    named!(yms, recognize!(multispace));
-    let rms = yms(&b" \t\r\n;"[..]);
-    assert_eq!(rms, Ok((semicolon, &b" \t\r\n"[..])));
-  }
-
-  #[test]
-  fn take_while() {
-    named!(f, take_while!(is_alphabetic));
-    let a = b"";
-    let b = b"abcd";
-    let c = b"abcd123";
-    let d = b"123";
-
-    assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(f(&b[..]), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(f(&c[..]), Ok((&d[..], &b[..])));
-    assert_eq!(f(&d[..]), Ok((&d[..], &a[..])));
-  }
-
-  #[test]
-  fn take_while1() {
-    named!(f, take_while1!(is_alphabetic));
-    let a = b"";
-    let b = b"abcd";
-    let c = b"abcd123";
-    let d = b"123";
-
-    assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(f(&b[..]), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(f(&c[..]), Ok((&b"123"[..], &b[..])));
-    assert_eq!(f(&d[..]), Err(Err::Error(error_position!(&d[..], ErrorKind::TakeWhile1))));
-  }
-
-  #[test]
-  fn take_while_m_n() {
-    named!(x, take_while_m_n!(2, 4, is_alphabetic));
-    let a = b"";
-    let b = b"a";
-    let c = b"abc";
-    let d = b"abc123";
-    let e = b"abcde";
-    let f = b"123";
-
-    assert_eq!(x(&a[..]), Err(Err::Incomplete(Needed::Size(2))));
-    assert_eq!(x(&b[..]), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(x(&c[..]), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(x(&d[..]), Ok((&b"123"[..], &c[..])));
-    assert_eq!(x(&e[..]), Ok((&b"e"[..], &b"abcd"[..])));
-    assert_eq!(x(&f[..]), Err(Err::Error(error_position!(&f[..], ErrorKind::TakeWhileMN))));
-  }
-
-  #[test]
-  fn take_till() {
-
-    named!(f, take_till!(is_alphabetic));
-    let a = b"";
-    let b = b"abcd";
-    let c = b"123abcd";
-    let d = b"123";
-
-    assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(f(&b[..]), Ok((&b"abcd"[..], &b""[..])));
-    assert_eq!(f(&c[..]), Ok((&b"abcd"[..], &b"123"[..])));
-    assert_eq!(f(&d[..]), Err(Err::Incomplete(Needed::Size(1))));
-  }
-
-  #[test]
-  fn take_till1() {
-
-    named!(f, take_till1!(is_alphabetic));
-    let a = b"";
-    let b = b"abcd";
-    let c = b"123abcd";
-    let d = b"123";
-
-    assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(f(&b[..]), Err(Err::Error(error_position!(&b[..], ErrorKind::TakeTill1))));
-    assert_eq!(f(&c[..]), Ok((&b"abcd"[..], &b"123"[..])));
-    assert_eq!(f(&d[..]), Err(Err::Incomplete(Needed::Size(1))));
-  }
-
-  #[test]
-  fn take_while_utf8() {
-    named!(f<&str,&str>, take_while!(|c:char| { c != '點' }));
-
-    assert_eq!(f(""), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(f("abcd"), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(f("abcd點"), Ok(("點", "abcd")));
-    assert_eq!(f("abcd點a"), Ok(("點a", "abcd")));
-
-    named!(g<&str,&str>, take_while!(|c:char| { c == '點' }));
-
-    assert_eq!(g(""), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(g("點abcd"), Ok(("abcd", "點")));
-    assert_eq!(g("點點點a"), Ok(("a", "點點點")));
-  }
-
-  #[test]
-  fn take_till_utf8() {
-    named!(f<&str,&str>, take_till!(|c:char| { c == '點' }));
-
-    assert_eq!(f(""), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(f("abcd"), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(f("abcd點"), Ok(("點", "abcd")));
-    assert_eq!(f("abcd點a"), Ok(("點a", "abcd")));
-
-    named!(g<&str,&str>, take_till!(|c:char| { c != '點' }));
-
-    assert_eq!(g(""), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(g("點abcd"), Ok(("abcd", "點")));
-    assert_eq!(g("點點點a"), Ok(("a", "點點點")));
-  }
-
-  #[test]
-  fn take_utf8() {
-    named!(f<&str,&str>, take!(3));
-
-    assert_eq!(f(""), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(f("ab"), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(f("點"), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(f("ab點cd"), Ok(("cd", "ab點")));
-    assert_eq!(f("a點bcd"), Ok(("cd", "a點b")));
-    assert_eq!(f("a點b"), Ok(("", "a點b")));
-
-    named!(g<&str,&str>, take_while!(|c:char| { c == '點' }));
-
-    assert_eq!(g(""), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(g("點abcd"), Ok(("abcd", "點")));
-    assert_eq!(g("點點點a"), Ok(("a", "點點點")));
-  }
-
-  #[test]
-  fn take_while_m_n_utf8() {
-    named!(parser<&str, &str>, take_while_m_n!(1, 1, |c| c == 'A' || c == '😃'));
-    assert_eq!(parser("A!"), Ok(("!", "A")));
-    assert_eq!(parser("😃!"), Ok(("!", "😃")));
-  }
-
-  #[test]
-  fn take_while_m_n_utf8_full_match() {
-    named!(parser<&str, &str>, take_while_m_n!(1, 1, |c: char| c.is_alphabetic()));
-    assert_eq!(parser("øn"), Ok(("n", "ø")));
-  }
-
-  #[cfg(nightly)]
-  use test::Bencher;
-
-  #[cfg(nightly)]
-  #[bench]
-  fn take_while_bench(b: &mut Bencher) {
-
-    named!(f, take_while!(is_alphabetic));
-    b.iter(|| f(&b"abcdefghijklABCDEejfrfrjgro12aa"[..]));
-  }
-
-  #[test]
-  #[cfg(feature = "std")]
-  fn recognize_take_while() {
-    use crate::character::is_alphanumeric;
-    named!(x, take_while!(is_alphanumeric));
-    named!(y, recognize!(x));
-    assert_eq!(x(&b"ab."[..]), Ok((&b"."[..], &b"ab"[..])));
-    println!("X: {:?}", x(&b"ab"[..]));
-    assert_eq!(y(&b"ab."[..]), Ok((&b"."[..], &b"ab"[..])));
-  }
-
-  #[test]
-  fn length_bytes() {
-    use crate::number::streaming::le_u8;
-    named!(x, length_data!(le_u8));
-    assert_eq!(x(b"\x02..>>"), Ok((&b">>"[..], &b".."[..])));
-    assert_eq!(x(b"\x02.."), Ok((&[][..], &b".."[..])));
-    assert_eq!(x(b"\x02."), Err(Err::Incomplete(Needed::Size(2))));
-    assert_eq!(x(b"\x02"), Err(Err::Incomplete(Needed::Size(2))));
-
-    named!(y, do_parse!(tag!("magic") >> b: length_data!(le_u8) >> (b)));
-    assert_eq!(y(b"magic\x02..>>"), Ok((&b">>"[..], &b".."[..])));
-    assert_eq!(y(b"magic\x02.."), Ok((&[][..], &b".."[..])));
-    assert_eq!(y(b"magic\x02."), Err(Err::Incomplete(Needed::Size(2))));
-    assert_eq!(y(b"magic\x02"), Err(Err::Incomplete(Needed::Size(2))));
-  }
-
-  #[cfg(feature = "alloc")]
-  #[test]
-  fn case_insensitive() {
-    named!(test, tag_no_case!("ABcd"));
-    assert_eq!(test(&b"aBCdefgh"[..]), Ok((&b"efgh"[..], &b"aBCd"[..])));
-    assert_eq!(test(&b"abcdefgh"[..]), Ok((&b"efgh"[..], &b"abcd"[..])));
-    assert_eq!(test(&b"ABCDefgh"[..]), Ok((&b"efgh"[..], &b"ABCD"[..])));
-    assert_eq!(test(&b"ab"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(test(&b"Hello"[..]), Err(Err::Error(error_position!(&b"Hello"[..], ErrorKind::Tag))));
-    assert_eq!(test(&b"Hel"[..]), Err(Err::Error(error_position!(&b"Hel"[..], ErrorKind::Tag))));
-
-    named!(test2<&str, &str>, tag_no_case!("ABcd"));
-    assert_eq!(test2("aBCdefgh"), Ok(("efgh", "aBCd")));
-    assert_eq!(test2("abcdefgh"), Ok(("efgh", "abcd")));
-    assert_eq!(test2("ABCDefgh"), Ok(("efgh", "ABCD")));
-    assert_eq!(test2("ab"), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(test2("Hello"), Err(Err::Error(error_position!(&"Hello"[..], ErrorKind::Tag))));
-    assert_eq!(test2("Hel"), Err(Err::Error(error_position!(&"Hel"[..], ErrorKind::Tag))));
-  }
-
-  #[test]
-  fn tag_fixed_size_array() {
-    named!(test, tag!([0x42]));
-    named!(test2, tag!(&[0x42]));
-    let input = [0x42, 0x00];
-    assert_eq!(test(&input), Ok((&b"\x00"[..], &b"\x42"[..])));
-    assert_eq!(test2(&input), Ok((&b"\x00"[..], &b"\x42"[..])));
-  }
-}
diff --git a/src/bytes/mod.rs b/src/bytes/mod.rs
index 13b2012..7bc2d15 100644
--- a/src/bytes/mod.rs
+++ b/src/bytes/mod.rs
@@ -1,7 +1,6 @@
-//! parsers recognizing bytes streams
+//! Parsers recognizing bytes streams
 
-#[macro_use]
-mod macros;
-pub mod streaming;
 pub mod complete;
-
+pub mod streaming;
+#[cfg(test)]
+mod tests;
diff --git a/src/bytes/streaming.rs b/src/bytes/streaming.rs
index f6e6706..e972760 100644
--- a/src/bytes/streaming.rs
+++ b/src/bytes/streaming.rs
@@ -1,20 +1,22 @@
-//! parsers recognizing bytes streams, streaming version
+//! Parsers recognizing bytes streams, streaming version
 
 use crate::error::ErrorKind;
 use crate::error::ParseError;
-use crate::internal::{Err, IResult, Needed};
+use crate::internal::{Err, IResult, Needed, Parser};
 use crate::lib::std::ops::RangeFrom;
 use crate::lib::std::result::Result::*;
-use crate::traits::{Compare, CompareResult, FindSubstring, FindToken, InputIter, InputLength, InputTake, InputTakeAtPosition, Slice, ToUsize};
+use crate::traits::{
+  Compare, CompareResult, FindSubstring, FindToken, InputIter, InputLength, InputTake,
+  InputTakeAtPosition, Slice, ToUsize,
+};
 
-/// Recognizes a pattern
+/// Recognizes a pattern.
 ///
 /// The input data will be compared to the tag combinator's argument and will return the part of
-/// the input that matches the argument
+/// the input that matches the argument.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::streaming::tag;
 ///
 /// fn parser(s: &str) -> IResult<&str, &str> {
@@ -22,12 +24,15 @@
 /// }
 ///
 /// assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
-/// assert_eq!(parser("Something"), Err(Err::Error(("Something", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(Err::Incomplete(Needed::Size(5))));
+/// assert_eq!(parser("Something"), Err(Err::Error(Error::new("Something", ErrorKind::Tag))));
+/// assert_eq!(parser("S"), Err(Err::Error(Error::new("S", ErrorKind::Tag))));
+/// assert_eq!(parser("H"), Err(Err::Incomplete(Needed::new(4))));
 /// ```
-pub fn tag<'a, T: 'a, Input: 'a, Error: ParseError<Input>>(tag: T) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn tag<T, Input, Error: ParseError<Input>>(
+  tag: T,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
-  Input: InputTake + Compare<T>,
+  Input: InputTake + InputLength + Compare<T>,
   T: InputLength + Clone,
 {
   move |i: Input| {
@@ -36,7 +41,7 @@
 
     let res: IResult<_, _, Error> = match i.compare(t) {
       CompareResult::Ok => Ok(i.take_split(tag_len)),
-      CompareResult::Incomplete => Err(Err::Incomplete(Needed::Size(tag_len))),
+      CompareResult::Incomplete => Err(Err::Incomplete(Needed::new(tag_len - i.input_len()))),
       CompareResult::Error => {
         let e: ErrorKind = ErrorKind::Tag;
         Err(Err::Error(Error::from_error_kind(i, e)))
@@ -46,14 +51,13 @@
   }
 }
 
-/// Recognizes a case insensitive pattern
+/// Recognizes a case insensitive pattern.
 ///
 /// The input data will be compared to the tag combinator's argument and will return the part of
-/// the input that matches the argument with no regard to case
+/// the input that matches the argument with no regard to case.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::streaming::tag_no_case;
 ///
 /// fn parser(s: &str) -> IResult<&str, &str> {
@@ -63,12 +67,14 @@
 /// assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
 /// assert_eq!(parser("hello, World!"), Ok((", World!", "hello")));
 /// assert_eq!(parser("HeLlO, World!"), Ok((", World!", "HeLlO")));
-/// assert_eq!(parser("Something"), Err(Err::Error(("Something", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(Err::Incomplete(Needed::Size(5))));
+/// assert_eq!(parser("Something"), Err(Err::Error(Error::new("Something", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(Err::Incomplete(Needed::new(5))));
 /// ```
-pub fn tag_no_case<T, Input, Error: ParseError<Input>>(tag: T) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn tag_no_case<T, Input, Error: ParseError<Input>>(
+  tag: T,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
-  Input: InputTake + Compare<T>,
+  Input: InputTake + InputLength + Compare<T>,
   T: InputLength + Clone,
 {
   move |i: Input| {
@@ -77,7 +83,7 @@
 
     let res: IResult<_, _, Error> = match (i).compare_no_case(t) {
       CompareResult::Ok => Ok(i.take_split(tag_len)),
-      CompareResult::Incomplete => Err(Err::Incomplete(Needed::Size(tag_len))),
+      CompareResult::Incomplete => Err(Err::Incomplete(Needed::new(tag_len - i.input_len()))),
       CompareResult::Error => {
         let e: ErrorKind = ErrorKind::Tag;
         Err(Err::Error(Error::from_error_kind(i, e)))
@@ -87,16 +93,15 @@
   }
 }
 
-/// Parse till certain characters are met
+/// Parse till certain characters are met.
 ///
 /// The parser will return the longest slice till one of the characters of the combinator's argument are met.
 ///
-/// It doesn't consume the matched character,
+/// It doesn't consume the matched character.
 ///
-/// It will return a `Err::Incomplete(Needed::Size(1))` if the pattern wasn't met
+/// It will return a `Err::Incomplete(Needed::new(1))` if the pattern wasn't met.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// use nom::bytes::streaming::is_not;
 ///
@@ -106,13 +111,15 @@
 ///
 /// assert_eq!(not_space("Hello, World!"), Ok((" World!", "Hello,")));
 /// assert_eq!(not_space("Sometimes\t"), Ok(("\t", "Sometimes")));
-/// assert_eq!(not_space("Nospace"), Err(Err::Incomplete(Needed::Size(1))));
-/// assert_eq!(not_space(""), Err(Err::Incomplete(Needed::Size(1))));
+/// assert_eq!(not_space("Nospace"), Err(Err::Incomplete(Needed::new(1))));
+/// assert_eq!(not_space(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
-pub fn is_not<T, Input, Error: ParseError<Input>>(arr: T) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn is_not<T, Input, Error: ParseError<Input>>(
+  arr: T,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTakeAtPosition,
-  T: InputLength + FindToken<<Input as InputTakeAtPosition>::Item>,
+  T: FindToken<<Input as InputTakeAtPosition>::Item>,
 {
   move |i: Input| {
     let e: ErrorKind = ErrorKind::IsNot;
@@ -120,17 +127,16 @@
   }
 }
 
-/// Returns the longest slice of the matches the pattern
+/// Returns the longest slice of the matches the pattern.
 ///
 /// The parser will return the longest slice consisting of the characters in provided in the
-/// combinator's argument
+/// combinator's argument.
 ///
 /// # Streaming specific
-/// *Streaming version* will return a `Err::Incomplete(Needed::Size(1))` if the pattern wasn't met
-/// or if the pattern reaches the end of the input
+/// *Streaming version* will return a `Err::Incomplete(Needed::new(1))` if the pattern wasn't met
+/// or if the pattern reaches the end of the input.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// use nom::bytes::streaming::is_a;
 ///
@@ -141,13 +147,15 @@
 /// assert_eq!(hex("123 and voila"), Ok((" and voila", "123")));
 /// assert_eq!(hex("DEADBEEF and others"), Ok((" and others", "DEADBEEF")));
 /// assert_eq!(hex("BADBABEsomething"), Ok(("something", "BADBABE")));
-/// assert_eq!(hex("D15EA5E"), Err(Err::Incomplete(Needed::Size(1))));
-/// assert_eq!(hex(""), Err(Err::Incomplete(Needed::Size(1))));
+/// assert_eq!(hex("D15EA5E"), Err(Err::Incomplete(Needed::new(1))));
+/// assert_eq!(hex(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
-pub fn is_a<T, Input, Error: ParseError<Input>>(arr: T) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn is_a<T, Input, Error: ParseError<Input>>(
+  arr: T,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTakeAtPosition,
-  T: InputLength + FindToken<<Input as InputTakeAtPosition>::Item>,
+  T: FindToken<<Input as InputTakeAtPosition>::Item>,
 {
   move |i: Input| {
     let e: ErrorKind = ErrorKind::IsA;
@@ -155,16 +163,15 @@
   }
 }
 
-/// Returns the longest input slice (if any) that matches the predicate
+/// Returns the longest input slice (if any) that matches the predicate.
 ///
 /// The parser will return the longest slice that matches the given predicate *(a function that
-/// takes the input and returns a bool)*
+/// takes the input and returns a bool)*.
 ///
 /// # Streaming Specific
-/// *Streaming version* will return a `Err::Incomplete(Needed::Size(1))` if the pattern reaches the end of the input
+/// *Streaming version* will return a `Err::Incomplete(Needed::new(1))` if the pattern reaches the end of the input.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// use nom::bytes::streaming::take_while;
 /// use nom::character::is_alphabetic;
@@ -175,10 +182,12 @@
 ///
 /// assert_eq!(alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
 /// assert_eq!(alpha(b"12345"), Ok((&b"12345"[..], &b""[..])));
-/// assert_eq!(alpha(b"latin"), Err(Err::Incomplete(Needed::Size(1))));
-/// assert_eq!(alpha(b""), Err(Err::Incomplete(Needed::Size(1))));
+/// assert_eq!(alpha(b"latin"), Err(Err::Incomplete(Needed::new(1))));
+/// assert_eq!(alpha(b""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
-pub fn take_while<F, Input, Error: ParseError<Input>>(cond: F) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take_while<F, Input, Error: ParseError<Input>>(
+  cond: F,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTakeAtPosition,
   F: Fn(<Input as InputTakeAtPosition>::Item) -> bool,
@@ -186,20 +195,19 @@
   move |i: Input| i.split_at_position(|c| !cond(c))
 }
 
-/// Returns the longest (atleast 1) input slice that matches the predicate
+/// Returns the longest (at least 1) input slice that matches the predicate.
 ///
 /// The parser will return the longest slice that matches the given predicate *(a function that
-/// takes the input and returns a bool)*
+/// takes the input and returns a bool)*.
 ///
-/// It will return an `Err(Err::Error((_, ErrorKind::TakeWhile1)))` if the pattern wasn't met
+/// It will return an `Err(Err::Error((_, ErrorKind::TakeWhile1)))` if the pattern wasn't met.
 ///
 /// # Streaming Specific
-/// *Streaming version* will return a `Err::Incomplete(Needed::Size(1))` or if the pattern reaches the end of the input.
+/// *Streaming version* will return a `Err::Incomplete(Needed::new(1))` or if the pattern reaches the end of the input.
 ///
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::streaming::take_while1;
 /// use nom::character::is_alphabetic;
 ///
@@ -208,10 +216,12 @@
 /// }
 ///
 /// assert_eq!(alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
-/// assert_eq!(alpha(b"latin"), Err(Err::Incomplete(Needed::Size(1))));
-/// assert_eq!(alpha(b"12345"), Err(Err::Error((&b"12345"[..], ErrorKind::TakeWhile1))));
+/// assert_eq!(alpha(b"latin"), Err(Err::Incomplete(Needed::new(1))));
+/// assert_eq!(alpha(b"12345"), Err(Err::Error(Error::new(&b"12345"[..], ErrorKind::TakeWhile1))));
 /// ```
-pub fn take_while1<F, Input, Error: ParseError<Input>>(cond: F) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take_while1<F, Input, Error: ParseError<Input>>(
+  cond: F,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTakeAtPosition,
   F: Fn(<Input as InputTakeAtPosition>::Item) -> bool,
@@ -222,19 +232,18 @@
   }
 }
 
-/// Returns the longest (m <= len <= n) input slice  that matches the predicate
+/// Returns the longest (m <= len <= n) input slice  that matches the predicate.
 ///
 /// The parser will return the longest slice that matches the given predicate *(a function that
-/// takes the input and returns a bool)*
+/// takes the input and returns a bool)*.
 ///
-/// It will return an `Err::Error((_, ErrorKind::TakeWhileMN))` if the pattern wasn't met
+/// It will return an `Err::Error((_, ErrorKind::TakeWhileMN))` if the pattern wasn't met.
 /// # Streaming Specific
-/// *Streaming version* will return a `Err::Incomplete(Needed::Size(1))`  if the pattern reaches the end of the input or is too short.
+/// *Streaming version* will return a `Err::Incomplete(Needed::new(1))`  if the pattern reaches the end of the input or is too short.
 ///
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::streaming::take_while_m_n;
 /// use nom::character::is_alphabetic;
 ///
@@ -244,13 +253,17 @@
 ///
 /// assert_eq!(short_alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
 /// assert_eq!(short_alpha(b"lengthy"), Ok((&b"y"[..], &b"length"[..])));
-/// assert_eq!(short_alpha(b"latin"), Err(Err::Incomplete(Needed::Size(1))));
-/// assert_eq!(short_alpha(b"ed"), Err(Err::Incomplete(Needed::Size(1))));
-/// assert_eq!(short_alpha(b"12345"), Err(Err::Error((&b"12345"[..], ErrorKind::TakeWhileMN))));
+/// assert_eq!(short_alpha(b"latin"), Err(Err::Incomplete(Needed::new(1))));
+/// assert_eq!(short_alpha(b"ed"), Err(Err::Incomplete(Needed::new(1))));
+/// assert_eq!(short_alpha(b"12345"), Err(Err::Error(Error::new(&b"12345"[..], ErrorKind::TakeWhileMN))));
 /// ```
-pub fn take_while_m_n<F, Input, Error: ParseError<Input>>(m: usize, n: usize, cond: F) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take_while_m_n<F, Input, Error: ParseError<Input>>(
+  m: usize,
+  n: usize,
+  cond: F,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
-  Input: InputTake + InputIter + InputLength + Slice<RangeFrom<usize>>,
+  Input: InputTake + InputIter + InputLength,
   F: Fn(<Input as InputIter>::Item) -> bool,
 {
   move |i: Input| {
@@ -260,17 +273,23 @@
       Some(idx) => {
         if idx >= m {
           if idx <= n {
-            let res: IResult<_, _, Error> = if let Some(index) = input.slice_index(idx) {
+            let res: IResult<_, _, Error> = if let Ok(index) = input.slice_index(idx) {
               Ok(input.take_split(index))
             } else {
-              Err(Err::Error(Error::from_error_kind(input, ErrorKind::TakeWhileMN)))
+              Err(Err::Error(Error::from_error_kind(
+                input,
+                ErrorKind::TakeWhileMN,
+              )))
             };
             res
           } else {
-            let res: IResult<_, _, Error> = if let Some(index) = input.slice_index(n) {
+            let res: IResult<_, _, Error> = if let Ok(index) = input.slice_index(n) {
               Ok(input.take_split(index))
             } else {
-              Err(Err::Error(Error::from_error_kind(input, ErrorKind::TakeWhileMN)))
+              Err(Err::Error(Error::from_error_kind(
+                input,
+                ErrorKind::TakeWhileMN,
+              )))
             };
             res
           }
@@ -283,30 +302,32 @@
         let len = input.input_len();
         if len >= n {
           match input.slice_index(n) {
-            Some(index) => Ok(input.take_split(index)),
-            None => Err(Err::Error(Error::from_error_kind(input, ErrorKind::TakeWhileMN)))
+            Ok(index) => Ok(input.take_split(index)),
+            Err(_needed) => Err(Err::Error(Error::from_error_kind(
+              input,
+              ErrorKind::TakeWhileMN,
+            ))),
           }
         } else {
           let needed = if m > len { m - len } else { 1 };
-          Err(Err::Incomplete(Needed::Size(needed)))
+          Err(Err::Incomplete(Needed::new(needed)))
         }
       }
     }
   }
 }
 
-/// Returns the longest input slice (if any) till a predicate is met
+/// Returns the longest input slice (if any) till a predicate is met.
 ///
 /// The parser will return the longest slice till the given predicate *(a function that
-/// takes the input and returns a bool)*
+/// takes the input and returns a bool)*.
 ///
 /// # Streaming Specific
-/// *Streaming version* will return a `Err::Incomplete(Needed::Size(1))` if the match reaches the
-/// end of input or if there was not match
+/// *Streaming version* will return a `Err::Incomplete(Needed::new(1))` if the match reaches the
+/// end of input or if there was not match.
 ///
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// use nom::bytes::streaming::take_till;
 ///
@@ -316,10 +337,12 @@
 ///
 /// assert_eq!(till_colon("latin:123"), Ok((":123", "latin")));
 /// assert_eq!(till_colon(":empty matched"), Ok((":empty matched", ""))); //allowed
-/// assert_eq!(till_colon("12345"), Err(Err::Incomplete(Needed::Size(1))));
-/// assert_eq!(till_colon(""), Err(Err::Incomplete(Needed::Size(1))));
+/// assert_eq!(till_colon("12345"), Err(Err::Incomplete(Needed::new(1))));
+/// assert_eq!(till_colon(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
-pub fn take_till<F, Input, Error: ParseError<Input>>(cond: F) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take_till<F, Input, Error: ParseError<Input>>(
+  cond: F,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTakeAtPosition,
   F: Fn(<Input as InputTakeAtPosition>::Item) -> bool,
@@ -327,18 +350,17 @@
   move |i: Input| i.split_at_position(|c| cond(c))
 }
 
-/// Returns the longest (atleast 1) input slice till a predicate is met
+/// Returns the longest (at least 1) input slice till a predicate is met.
 ///
 /// The parser will return the longest slice till the given predicate *(a function that
-/// takes the input and returns a bool)*
+/// takes the input and returns a bool)*.
 ///
 /// # Streaming Specific
-/// *Streaming version* will return a `Err::Incomplete(Needed::Size(1))` if the match reaches the
-/// end of input or if there was not match
+/// *Streaming version* will return a `Err::Incomplete(Needed::new(1))` if the match reaches the
+/// end of input or if there was not match.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::bytes::streaming::take_till1;
 ///
 /// fn till_colon(s: &str) -> IResult<&str, &str> {
@@ -346,11 +368,13 @@
 /// }
 ///
 /// assert_eq!(till_colon("latin:123"), Ok((":123", "latin")));
-/// assert_eq!(till_colon(":empty matched"), Err(Err::Error((":empty matched", ErrorKind::TakeTill1))));
-/// assert_eq!(till_colon("12345"), Err(Err::Incomplete(Needed::Size(1))));
-/// assert_eq!(till_colon(""), Err(Err::Incomplete(Needed::Size(1))));
+/// assert_eq!(till_colon(":empty matched"), Err(Err::Error(Error::new(":empty matched", ErrorKind::TakeTill1))));
+/// assert_eq!(till_colon("12345"), Err(Err::Incomplete(Needed::new(1))));
+/// assert_eq!(till_colon(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
-pub fn take_till1<F, Input, Error: ParseError<Input>>(cond: F) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take_till1<F, Input, Error: ParseError<Input>>(
+  cond: F,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
   Input: InputTakeAtPosition,
   F: Fn(<Input as InputTakeAtPosition>::Item) -> bool,
@@ -361,14 +385,18 @@
   }
 }
 
-/// Returns an input slice containing the first N input elements (Input[..N])
+/// Returns an input slice containing the first N input elements (Input[..N]).
 ///
 /// # Streaming Specific
-/// *Streaming version* will return a `Err::Incomplete(Needed::Size(N))` where N is the
-/// argument if the input is less than the length provided
+/// *Streaming version* if the input has less than N elements, `take` will
+/// return a `Err::Incomplete(Needed::new(M))` where M is the number of
+/// additional bytes the parser would need to succeed.
+/// It is well defined for `&[u8]` as the number of elements is the byte size,
+/// but for types like `&str`, we cannot know how many bytes correspond for
+/// the next few chars, so the result will be `Err::Incomplete(Needed::Unknown)`
+///
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// use nom::bytes::streaming::take;
 ///
@@ -378,31 +406,31 @@
 ///
 /// assert_eq!(take6("1234567"), Ok(("7", "123456")));
 /// assert_eq!(take6("things"), Ok(("", "things")));
-/// assert_eq!(take6("short"), Err(Err::Incomplete(Needed::Size(6)))); //N doesn't change
-/// assert_eq!(take6(""), Err(Err::Incomplete(Needed::Size(6))));
+/// assert_eq!(take6("short"), Err(Err::Incomplete(Needed::Unknown)));
 /// ```
-pub fn take<C, Input, Error: ParseError<Input>>(count: C) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take<C, Input, Error: ParseError<Input>>(
+  count: C,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
-  Input: InputIter + InputTake,
+  Input: InputIter + InputTake + InputLength,
   C: ToUsize,
 {
   let c = count.to_usize();
   move |i: Input| match i.slice_index(c) {
-    None => Err(Err::Incomplete(Needed::Size(c))),
-    Some(index) => Ok(i.take_split(index)),
+    Err(i) => Err(Err::Incomplete(i)),
+    Ok(index) => Ok(i.take_split(index)),
   }
 }
 
-/// 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 doesn't consume the pattern.
 ///
 /// # Streaming Specific
-/// *Streaming version* will return a `Err::Incomplete(Needed::Size(N))` if the input doesn't
-/// contain the pattern or if the input is smaller than the pattern
+/// *Streaming version* will return a `Err::Incomplete(Needed::new(N))` if the input doesn't
+/// contain the pattern or if the input is smaller than the pattern.
 /// # Example
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// use nom::bytes::streaming::take_until;
 ///
@@ -411,20 +439,63 @@
 /// }
 ///
 /// assert_eq!(until_eof("hello, worldeof"), Ok(("eof", "hello, world")));
-/// assert_eq!(until_eof("hello, world"), Err(Err::Incomplete(Needed::Size(3))));
-/// assert_eq!(until_eof(""), Err(Err::Incomplete(Needed::Size(3))));
+/// 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) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn take_until<T, Input, Error: ParseError<Input>>(
+  tag: T,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
 where
-  Input: InputTake + FindSubstring<T>,
-  T: InputLength + Clone,
+  Input: InputTake + InputLength + FindSubstring<T>,
+  T: Clone,
 {
   move |i: Input| {
-    let len = tag.input_len();
     let t = tag.clone();
 
     let res: IResult<_, _, Error> = match i.find_substring(t) {
-      None => Err(Err::Incomplete(Needed::Size(len))),
+      None => Err(Err::Incomplete(Needed::Unknown)),
+      Some(index) => Ok(i.take_split(index)),
+    };
+    res
+  }
+}
+
+/// Returns the non empty input slice up to the first occurrence of the pattern.
+///
+/// It doesn't consume the pattern.
+///
+/// # Streaming Specific
+/// *Streaming version* will return a `Err::Incomplete(Needed::new(N))` if the input doesn't
+/// contain the pattern or if the input is smaller than the pattern.
+/// # Example
+/// ```rust
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
+/// use nom::bytes::streaming::take_until1;
+///
+/// fn until_eof(s: &str) -> IResult<&str, &str> {
+///   take_until1("eof")(s)
+/// }
+///
+/// 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")));
+/// assert_eq!(until_eof("eof"),  Err(Err::Error(Error::new("eof", ErrorKind::TakeUntil))));
+/// ```
+pub fn take_until1<T, Input, Error: ParseError<Input>>(
+  tag: T,
+) -> impl Fn(Input) -> IResult<Input, Input, Error>
+where
+  Input: InputTake + InputLength + FindSubstring<T>,
+  T: Clone,
+{
+  move |i: Input| {
+    let t = tag.clone();
+
+    let res: IResult<_, _, Error> = match i.find_substring(t) {
+      None => Err(Err::Incomplete(Needed::Unknown)),
+      Some(0) => Err(Err::Error(Error::from_error_kind(i, ErrorKind::TakeUntil))),
       Some(index) => Ok(i.take_split(index)),
     };
     res
@@ -433,13 +504,11 @@
 
 /// Matches a byte string with escaped characters.
 ///
-/// * The first argument matches the normal characters (it must not accept the control character),
-/// * the second argument is the control character (like `\` in most languages),
-/// * the third argument matches the escaped characters
-///
+/// * The first argument matches the normal characters (it must not accept the control character)
+/// * The second argument is the control character (like `\` in most languages)
+/// * The third argument matches the escaped characters
 /// # Example
 /// ```
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// # use nom::character::complete::digit1;
 /// use nom::bytes::streaming::escaped;
@@ -453,12 +522,22 @@
 /// assert_eq!(esc("12\\\"34;"), Ok((";", "12\\\"34")));
 /// ```
 ///
-pub fn escaped<Input, Error, F, G, O1, O2>(normal: F, control_char: char, escapable: G) -> impl Fn(Input) -> IResult<Input, Input, Error>
+pub fn escaped<Input, Error, F, G, O1, O2>(
+  mut normal: F,
+  control_char: char,
+  mut escapable: G,
+) -> impl FnMut(Input) -> IResult<Input, Input, Error>
 where
-  Input: Clone + crate::traits::Offset + InputLength + InputTake + InputTakeAtPosition + Slice<RangeFrom<usize>> + InputIter,
+  Input: Clone
+    + crate::traits::Offset
+    + InputLength
+    + InputTake
+    + InputTakeAtPosition
+    + Slice<RangeFrom<usize>>
+    + InputIter,
   <Input as InputIter>::Item: crate::traits::AsChar,
-  F: Fn(Input) -> IResult<Input, O1, Error>,
-  G: Fn(Input) -> IResult<Input, O2, Error>,
+  F: Parser<Input, O1, Error>,
+  G: Parser<Input, O2, Error>,
   Error: ParseError<Input>,
 {
   use crate::traits::AsChar;
@@ -467,10 +546,15 @@
     let mut i = input.clone();
 
     while i.input_len() > 0 {
-      match normal(i.clone()) {
+      let current_len = i.input_len();
+
+      match normal.parse(i.clone()) {
         Ok((i2, _)) => {
           if i2.input_len() == 0 {
             return Err(Err::Incomplete(Needed::Unknown));
+          } else if i2.input_len() == current_len {
+            let index = input.offset(&i2);
+            return Ok(input.take_split(index));
           } else {
             i = i2;
           }
@@ -480,9 +564,9 @@
           if i.iter_elements().next().unwrap().as_char() == control_char {
             let next = control_char.len_utf8();
             if next >= i.input_len() {
-              return Err(Err::Incomplete(Needed::Size(1)));
+              return Err(Err::Incomplete(Needed::new(1)));
             } else {
-              match escapable(i.slice(next..)) {
+              match escapable.parse(i.slice(next..)) {
                 Ok((i2, _)) => {
                   if i2.input_len() == 0 {
                     return Err(Err::Incomplete(Needed::Unknown));
@@ -508,64 +592,57 @@
   }
 }
 
-#[doc(hidden)]
-pub fn escapedc<Input, Error, F, G, O1, O2>(i: Input, normal: F, control_char: char, escapable: G) -> IResult<Input, Input, Error>
-where
-  Input: Clone + crate::traits::Offset + InputLength + InputTake + InputTakeAtPosition + Slice<RangeFrom<usize>> + InputIter,
-  <Input as InputIter>::Item: crate::traits::AsChar,
-  F: Fn(Input) -> IResult<Input, O1, Error>,
-  G: Fn(Input) -> IResult<Input, O2, Error>,
-  Error: ParseError<Input>,
-{
-  escaped(normal, control_char, escapable)(i)
-}
-
 /// Matches a byte string with escaped characters.
 ///
-/// * The first argument matches the normal characters (it must not match the control character),
-/// * the second argument is the control character (like `\` in most languages),
-/// * the third argument matches the escaped characters and transforms them.
+/// * The first argument matches the normal characters (it must not match the control character)
+/// * The second argument is the control character (like `\` in most languages)
+/// * The third argument matches the escaped characters and transforms them
 ///
 /// As an example, the chain `abc\tdef` could be `abc    def` (it also consumes the control character)
 ///
 /// ```
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// # use std::str::from_utf8;
-/// use nom::bytes::streaming::escaped_transform;
+/// use nom::bytes::streaming::{escaped_transform, tag};
 /// use nom::character::streaming::alpha1;
+/// use nom::branch::alt;
+/// use nom::combinator::value;
 ///
 /// fn parser(input: &str) -> IResult<&str, String> {
 ///   escaped_transform(
 ///     alpha1,
 ///     '\\',
-///     |i:&str| alt!(i,
-///         tag!("\\")       => { |_| "\\" }
-///       | tag!("\"")       => { |_| "\"" }
-///       | tag!("n")        => { |_| "\n" }
-///     )
+///     alt((
+///       value("\\", tag("\\")),
+///       value("\"", tag("\"")),
+///       value("\n", tag("n")),
+///     ))
 ///   )(input)
 /// }
 ///
 /// assert_eq!(parser("ab\\\"cd\""), Ok(("\"", String::from("ab\"cd"))));
 /// ```
 #[cfg(feature = "alloc")]
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
 pub fn escaped_transform<Input, Error, F, G, O1, O2, ExtendItem, Output>(
-  normal: F,
+  mut normal: F,
   control_char: char,
-  transform: G,
-) -> impl Fn(Input) -> IResult<Input, Output, Error>
+  mut transform: G,
+) -> impl FnMut(Input) -> IResult<Input, Output, Error>
 where
-  Input: Clone + crate::traits::Offset + InputLength + InputTake + InputTakeAtPosition + Slice<RangeFrom<usize>> + InputIter,
+  Input: Clone
+    + crate::traits::Offset
+    + InputLength
+    + InputTake
+    + InputTakeAtPosition
+    + Slice<RangeFrom<usize>>
+    + InputIter,
   Input: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
   O1: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
   O2: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
-  Output: core::iter::Extend<<Input as crate::traits::ExtendInto>::Item>,
-  Output: core::iter::Extend<<O1 as crate::traits::ExtendInto>::Item>,
-  Output: core::iter::Extend<<O2 as crate::traits::ExtendInto>::Item>,
   <Input as InputIter>::Item: crate::traits::AsChar,
-  F: Fn(Input) -> IResult<Input, O1, Error>,
-  G: Fn(Input) -> IResult<Input, O2, Error>,
+  F: Parser<Input, O1, Error>,
+  G: Parser<Input, O2, Error>,
   Error: ParseError<Input>,
 {
   use crate::traits::AsChar;
@@ -577,12 +654,15 @@
     let i = input.clone();
 
     while index < i.input_len() {
+      let current_len = i.input_len();
       let remainder = i.slice(index..);
-      match normal(remainder.clone()) {
+      match normal.parse(remainder.clone()) {
         Ok((i2, o)) => {
           o.extend_into(&mut res);
           if i2.input_len() == 0 {
             return Err(Err::Incomplete(Needed::Unknown));
+          } else if i2.input_len() == current_len {
+            return Ok((remainder, res));
           } else {
             index = input.offset(&i2);
           }
@@ -596,7 +676,7 @@
             if next >= input_len {
               return Err(Err::Incomplete(Needed::Unknown));
             } else {
-              match transform(i.slice(next..)) {
+              match transform.parse(i.slice(next..)) {
                 Ok((i2, o)) => {
                   o.extend_into(&mut res);
                   if i2.input_len() == 0 {
@@ -618,28 +698,3 @@
     Err(Err::Incomplete(Needed::Unknown))
   }
 }
-
-#[doc(hidden)]
-#[cfg(feature = "alloc")]
-pub fn escaped_transformc<Input, Error, F, G, O1, O2, ExtendItem, Output>(
-  i: Input,
-  normal: F,
-  control_char: char,
-  transform: G,
-) -> IResult<Input, Output, Error>
-where
-  Input: Clone + crate::traits::Offset + InputLength + InputTake + InputTakeAtPosition + Slice<RangeFrom<usize>> + InputIter,
-  Input: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
-  O1: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
-  O2: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
-  Output: core::iter::Extend<<Input as crate::traits::ExtendInto>::Item>,
-  Output: core::iter::Extend<<O1 as crate::traits::ExtendInto>::Item>,
-  Output: core::iter::Extend<<O2 as crate::traits::ExtendInto>::Item>,
-  <Input as InputIter>::Item: crate::traits::AsChar,
-  F: Fn(Input) -> IResult<Input, O1, Error>,
-  G: Fn(Input) -> IResult<Input, O2, Error>,
-  Error: ParseError<Input>,
-{
-  escaped_transform(normal, control_char, transform)(i)
-
-}
diff --git a/src/bytes/tests.rs b/src/bytes/tests.rs
new file mode 100644
index 0000000..159c4b4
--- /dev/null
+++ b/src/bytes/tests.rs
@@ -0,0 +1,636 @@
+use crate::character::is_alphabetic;
+use crate::character::streaming::{
+  alpha1 as alpha, alphanumeric1 as alphanumeric, digit1 as digit, hex_digit1 as hex_digit,
+  multispace1 as multispace, oct_digit1 as oct_digit, space1 as space,
+};
+use crate::error::ErrorKind;
+use crate::internal::{Err, IResult, Needed};
+#[cfg(feature = "alloc")]
+use crate::{
+  branch::alt,
+  bytes::complete::{escaped, escaped_transform, tag},
+  combinator::{map, value},
+  lib::std::string::String,
+  lib::std::vec::Vec,
+};
+
+#[test]
+fn is_a() {
+  use crate::bytes::streaming::is_a;
+
+  fn a_or_b(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    is_a("ab")(i)
+  }
+
+  let a = &b"abcd"[..];
+  assert_eq!(a_or_b(a), Ok((&b"cd"[..], &b"ab"[..])));
+
+  let b = &b"bcde"[..];
+  assert_eq!(a_or_b(b), Ok((&b"cde"[..], &b"b"[..])));
+
+  let c = &b"cdef"[..];
+  assert_eq!(
+    a_or_b(c),
+    Err(Err::Error(error_position!(c, ErrorKind::IsA)))
+  );
+
+  let d = &b"bacdef"[..];
+  assert_eq!(a_or_b(d), Ok((&b"cdef"[..], &b"ba"[..])));
+}
+
+#[test]
+fn is_not() {
+  use crate::bytes::streaming::is_not;
+
+  fn a_or_b(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    is_not("ab")(i)
+  }
+
+  let a = &b"cdab"[..];
+  assert_eq!(a_or_b(a), Ok((&b"ab"[..], &b"cd"[..])));
+
+  let b = &b"cbde"[..];
+  assert_eq!(a_or_b(b), Ok((&b"bde"[..], &b"c"[..])));
+
+  let c = &b"abab"[..];
+  assert_eq!(
+    a_or_b(c),
+    Err(Err::Error(error_position!(c, ErrorKind::IsNot)))
+  );
+
+  let d = &b"cdefba"[..];
+  assert_eq!(a_or_b(d), Ok((&b"ba"[..], &b"cdef"[..])));
+
+  let e = &b"e"[..];
+  assert_eq!(a_or_b(e), Err(Err::Incomplete(Needed::new(1))));
+}
+
+#[cfg(feature = "alloc")]
+#[allow(unused_variables)]
+#[test]
+fn escaping() {
+  use crate::character::streaming::one_of;
+
+  fn esc(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    escaped(alpha, '\\', one_of("\"n\\"))(i)
+  }
+  assert_eq!(esc(&b"abcd;"[..]), Ok((&b";"[..], &b"abcd"[..])));
+  assert_eq!(esc(&b"ab\\\"cd;"[..]), Ok((&b";"[..], &b"ab\\\"cd"[..])));
+  assert_eq!(esc(&b"\\\"abcd;"[..]), Ok((&b";"[..], &b"\\\"abcd"[..])));
+  assert_eq!(esc(&b"\\n;"[..]), Ok((&b";"[..], &b"\\n"[..])));
+  assert_eq!(esc(&b"ab\\\"12"[..]), Ok((&b"12"[..], &b"ab\\\""[..])));
+  assert_eq!(
+    esc(&b"AB\\"[..]),
+    Err(Err::Error(error_position!(
+      &b"AB\\"[..],
+      ErrorKind::Escaped
+    )))
+  );
+  assert_eq!(
+    esc(&b"AB\\A"[..]),
+    Err(Err::Error(error_node_position!(
+      &b"AB\\A"[..],
+      ErrorKind::Escaped,
+      error_position!(&b"A"[..], ErrorKind::OneOf)
+    )))
+  );
+
+  fn esc2(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    escaped(digit, '\\', one_of("\"n\\"))(i)
+  }
+  assert_eq!(esc2(&b"12\\nnn34"[..]), Ok((&b"nn34"[..], &b"12\\n"[..])));
+}
+
+#[cfg(feature = "alloc")]
+#[test]
+fn escaping_str() {
+  use crate::character::streaming::one_of;
+
+  fn esc(i: &str) -> IResult<&str, &str> {
+    escaped(alpha, '\\', one_of("\"n\\"))(i)
+  }
+  assert_eq!(esc("abcd;"), Ok((";", "abcd")));
+  assert_eq!(esc("ab\\\"cd;"), Ok((";", "ab\\\"cd")));
+  assert_eq!(esc("\\\"abcd;"), Ok((";", "\\\"abcd")));
+  assert_eq!(esc("\\n;"), Ok((";", "\\n")));
+  assert_eq!(esc("ab\\\"12"), Ok(("12", "ab\\\"")));
+  assert_eq!(
+    esc("AB\\"),
+    Err(Err::Error(error_position!("AB\\", ErrorKind::Escaped)))
+  );
+  assert_eq!(
+    esc("AB\\A"),
+    Err(Err::Error(error_node_position!(
+      "AB\\A",
+      ErrorKind::Escaped,
+      error_position!("A", ErrorKind::OneOf)
+    )))
+  );
+
+  fn esc2(i: &str) -> IResult<&str, &str> {
+    escaped(digit, '\\', one_of("\"n\\"))(i)
+  }
+  assert_eq!(esc2("12\\nnn34"), Ok(("nn34", "12\\n")));
+
+  fn esc3(i: &str) -> IResult<&str, &str> {
+    escaped(alpha, '\u{241b}', one_of("\"n"))(i)
+  }
+  assert_eq!(esc3("ab␛ncd;"), Ok((";", "ab␛ncd")));
+}
+
+#[cfg(feature = "alloc")]
+fn to_s(i: Vec<u8>) -> String {
+  String::from_utf8_lossy(&i).into_owned()
+}
+
+#[cfg(feature = "alloc")]
+#[test]
+fn escape_transform() {
+  fn esc(i: &[u8]) -> IResult<&[u8], String> {
+    map(
+      escaped_transform(
+        alpha,
+        '\\',
+        alt((
+          value(&b"\\"[..], tag("\\")),
+          value(&b"\""[..], tag("\"")),
+          value(&b"\n"[..], tag("n")),
+        )),
+      ),
+      to_s,
+    )(i)
+  }
+
+  assert_eq!(esc(&b"abcd;"[..]), Ok((&b";"[..], String::from("abcd"))));
+  assert_eq!(
+    esc(&b"ab\\\"cd;"[..]),
+    Ok((&b";"[..], String::from("ab\"cd")))
+  );
+  assert_eq!(
+    esc(&b"\\\"abcd;"[..]),
+    Ok((&b";"[..], String::from("\"abcd")))
+  );
+  assert_eq!(esc(&b"\\n;"[..]), Ok((&b";"[..], String::from("\n"))));
+  assert_eq!(
+    esc(&b"ab\\\"12"[..]),
+    Ok((&b"12"[..], String::from("ab\"")))
+  );
+  assert_eq!(
+    esc(&b"AB\\"[..]),
+    Err(Err::Error(error_position!(
+      &b"\\"[..],
+      ErrorKind::EscapedTransform
+    )))
+  );
+  assert_eq!(
+    esc(&b"AB\\A"[..]),
+    Err(Err::Error(error_node_position!(
+      &b"AB\\A"[..],
+      ErrorKind::EscapedTransform,
+      error_position!(&b"A"[..], ErrorKind::Tag)
+    )))
+  );
+
+  fn esc2(i: &[u8]) -> IResult<&[u8], String> {
+    map(
+      escaped_transform(
+        alpha,
+        '&',
+        alt((
+          value("è".as_bytes(), tag("egrave;")),
+          value("à".as_bytes(), tag("agrave;")),
+        )),
+      ),
+      to_s,
+    )(i)
+  }
+  assert_eq!(
+    esc2(&b"ab&egrave;DEF;"[..]),
+    Ok((&b";"[..], String::from("abèDEF")))
+  );
+  assert_eq!(
+    esc2(&b"ab&egrave;D&agrave;EF;"[..]),
+    Ok((&b";"[..], String::from("abèDàEF")))
+  );
+}
+
+#[cfg(feature = "std")]
+#[test]
+fn escape_transform_str() {
+  fn esc(i: &str) -> IResult<&str, String> {
+    escaped_transform(
+      alpha,
+      '\\',
+      alt((
+        value("\\", tag("\\")),
+        value("\"", tag("\"")),
+        value("\n", tag("n")),
+      )),
+    )(i)
+  }
+
+  assert_eq!(esc("abcd;"), Ok((";", String::from("abcd"))));
+  assert_eq!(esc("ab\\\"cd;"), Ok((";", String::from("ab\"cd"))));
+  assert_eq!(esc("\\\"abcd;"), Ok((";", String::from("\"abcd"))));
+  assert_eq!(esc("\\n;"), Ok((";", String::from("\n"))));
+  assert_eq!(esc("ab\\\"12"), Ok(("12", String::from("ab\""))));
+  assert_eq!(
+    esc("AB\\"),
+    Err(Err::Error(error_position!(
+      "\\",
+      ErrorKind::EscapedTransform
+    )))
+  );
+  assert_eq!(
+    esc("AB\\A"),
+    Err(Err::Error(error_node_position!(
+      "AB\\A",
+      ErrorKind::EscapedTransform,
+      error_position!("A", ErrorKind::Tag)
+    )))
+  );
+
+  fn esc2(i: &str) -> IResult<&str, String> {
+    escaped_transform(
+      alpha,
+      '&',
+      alt((value("è", tag("egrave;")), value("à", tag("agrave;")))),
+    )(i)
+  }
+  assert_eq!(esc2("ab&egrave;DEF;"), Ok((";", String::from("abèDEF"))));
+  assert_eq!(
+    esc2("ab&egrave;D&agrave;EF;"),
+    Ok((";", String::from("abèDàEF")))
+  );
+
+  fn esc3(i: &str) -> IResult<&str, String> {
+    escaped_transform(
+      alpha,
+      '␛',
+      alt((value("\0", tag("0")), value("\n", tag("n")))),
+    )(i)
+  }
+  assert_eq!(esc3("a␛0bc␛n"), Ok(("", String::from("a\0bc\n"))));
+}
+
+#[test]
+fn take_until_incomplete() {
+  use crate::bytes::streaming::take_until;
+  fn y(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    take_until("end")(i)
+  }
+  assert_eq!(y(&b"nd"[..]), Err(Err::Incomplete(Needed::Unknown)));
+  assert_eq!(y(&b"123"[..]), Err(Err::Incomplete(Needed::Unknown)));
+  assert_eq!(y(&b"123en"[..]), Err(Err::Incomplete(Needed::Unknown)));
+}
+
+#[test]
+fn take_until_incomplete_s() {
+  use crate::bytes::streaming::take_until;
+  fn ys(i: &str) -> IResult<&str, &str> {
+    take_until("end")(i)
+  }
+  assert_eq!(ys("123en"), Err(Err::Incomplete(Needed::Unknown)));
+}
+
+#[test]
+fn recognize() {
+  use crate::bytes::streaming::{tag, take};
+  use crate::combinator::recognize;
+  use crate::sequence::delimited;
+
+  fn x(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    recognize(delimited(tag("<!--"), take(5_usize), tag("-->")))(i)
+  }
+  let r = x(&b"<!-- abc --> aaa"[..]);
+  assert_eq!(r, Ok((&b" aaa"[..], &b"<!-- abc -->"[..])));
+
+  let semicolon = &b";"[..];
+
+  fn ya(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    recognize(alpha)(i)
+  }
+  let ra = ya(&b"abc;"[..]);
+  assert_eq!(ra, Ok((semicolon, &b"abc"[..])));
+
+  fn yd(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    recognize(digit)(i)
+  }
+  let rd = yd(&b"123;"[..]);
+  assert_eq!(rd, Ok((semicolon, &b"123"[..])));
+
+  fn yhd(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    recognize(hex_digit)(i)
+  }
+  let rhd = yhd(&b"123abcDEF;"[..]);
+  assert_eq!(rhd, Ok((semicolon, &b"123abcDEF"[..])));
+
+  fn yod(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    recognize(oct_digit)(i)
+  }
+  let rod = yod(&b"1234567;"[..]);
+  assert_eq!(rod, Ok((semicolon, &b"1234567"[..])));
+
+  fn yan(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    recognize(alphanumeric)(i)
+  }
+  let ran = yan(&b"123abc;"[..]);
+  assert_eq!(ran, Ok((semicolon, &b"123abc"[..])));
+
+  fn ys(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    recognize(space)(i)
+  }
+  let rs = ys(&b" \t;"[..]);
+  assert_eq!(rs, Ok((semicolon, &b" \t"[..])));
+
+  fn yms(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    recognize(multispace)(i)
+  }
+  let rms = yms(&b" \t\r\n;"[..]);
+  assert_eq!(rms, Ok((semicolon, &b" \t\r\n"[..])));
+}
+
+#[test]
+fn take_while() {
+  use crate::bytes::streaming::take_while;
+
+  fn f(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    take_while(is_alphabetic)(i)
+  }
+  let a = b"";
+  let b = b"abcd";
+  let c = b"abcd123";
+  let d = b"123";
+
+  assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(f(&b[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(f(&c[..]), Ok((&d[..], &b[..])));
+  assert_eq!(f(&d[..]), Ok((&d[..], &a[..])));
+}
+
+#[test]
+fn take_while1() {
+  use crate::bytes::streaming::take_while1;
+
+  fn f(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    take_while1(is_alphabetic)(i)
+  }
+  let a = b"";
+  let b = b"abcd";
+  let c = b"abcd123";
+  let d = b"123";
+
+  assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(f(&b[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(f(&c[..]), Ok((&b"123"[..], &b[..])));
+  assert_eq!(
+    f(&d[..]),
+    Err(Err::Error(error_position!(&d[..], ErrorKind::TakeWhile1)))
+  );
+}
+
+#[test]
+fn take_while_m_n() {
+  use crate::bytes::streaming::take_while_m_n;
+
+  fn x(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    take_while_m_n(2, 4, is_alphabetic)(i)
+  }
+  let a = b"";
+  let b = b"a";
+  let c = b"abc";
+  let d = b"abc123";
+  let e = b"abcde";
+  let f = b"123";
+
+  assert_eq!(x(&a[..]), Err(Err::Incomplete(Needed::new(2))));
+  assert_eq!(x(&b[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(x(&c[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(x(&d[..]), Ok((&b"123"[..], &c[..])));
+  assert_eq!(x(&e[..]), Ok((&b"e"[..], &b"abcd"[..])));
+  assert_eq!(
+    x(&f[..]),
+    Err(Err::Error(error_position!(&f[..], ErrorKind::TakeWhileMN)))
+  );
+}
+
+#[test]
+fn take_till() {
+  use crate::bytes::streaming::take_till;
+
+  fn f(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    take_till(is_alphabetic)(i)
+  }
+  let a = b"";
+  let b = b"abcd";
+  let c = b"123abcd";
+  let d = b"123";
+
+  assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(f(&b[..]), Ok((&b"abcd"[..], &b""[..])));
+  assert_eq!(f(&c[..]), Ok((&b"abcd"[..], &b"123"[..])));
+  assert_eq!(f(&d[..]), Err(Err::Incomplete(Needed::new(1))));
+}
+
+#[test]
+fn take_till1() {
+  use crate::bytes::streaming::take_till1;
+
+  fn f(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    take_till1(is_alphabetic)(i)
+  }
+  let a = b"";
+  let b = b"abcd";
+  let c = b"123abcd";
+  let d = b"123";
+
+  assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(
+    f(&b[..]),
+    Err(Err::Error(error_position!(&b[..], ErrorKind::TakeTill1)))
+  );
+  assert_eq!(f(&c[..]), Ok((&b"abcd"[..], &b"123"[..])));
+  assert_eq!(f(&d[..]), Err(Err::Incomplete(Needed::new(1))));
+}
+
+#[test]
+fn take_while_utf8() {
+  use crate::bytes::streaming::take_while;
+
+  fn f(i: &str) -> IResult<&str, &str> {
+    take_while(|c| c != '點')(i)
+  }
+
+  assert_eq!(f(""), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(f("abcd"), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(f("abcd點"), Ok(("點", "abcd")));
+  assert_eq!(f("abcd點a"), Ok(("點a", "abcd")));
+
+  fn g(i: &str) -> IResult<&str, &str> {
+    take_while(|c| c == '點')(i)
+  }
+
+  assert_eq!(g(""), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(g("點abcd"), Ok(("abcd", "點")));
+  assert_eq!(g("點點點a"), Ok(("a", "點點點")));
+}
+
+#[test]
+fn take_till_utf8() {
+  use crate::bytes::streaming::take_till;
+
+  fn f(i: &str) -> IResult<&str, &str> {
+    take_till(|c| c == '點')(i)
+  }
+
+  assert_eq!(f(""), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(f("abcd"), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(f("abcd點"), Ok(("點", "abcd")));
+  assert_eq!(f("abcd點a"), Ok(("點a", "abcd")));
+
+  fn g(i: &str) -> IResult<&str, &str> {
+    take_till(|c| c != '點')(i)
+  }
+
+  assert_eq!(g(""), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(g("點abcd"), Ok(("abcd", "點")));
+  assert_eq!(g("點點點a"), Ok(("a", "點點點")));
+}
+
+#[test]
+fn take_utf8() {
+  use crate::bytes::streaming::{take, take_while};
+
+  fn f(i: &str) -> IResult<&str, &str> {
+    take(3_usize)(i)
+  }
+
+  assert_eq!(f(""), Err(Err::Incomplete(Needed::Unknown)));
+  assert_eq!(f("ab"), Err(Err::Incomplete(Needed::Unknown)));
+  assert_eq!(f("點"), Err(Err::Incomplete(Needed::Unknown)));
+  assert_eq!(f("ab點cd"), Ok(("cd", "ab點")));
+  assert_eq!(f("a點bcd"), Ok(("cd", "a點b")));
+  assert_eq!(f("a點b"), Ok(("", "a點b")));
+
+  fn g(i: &str) -> IResult<&str, &str> {
+    take_while(|c| c == '點')(i)
+  }
+
+  assert_eq!(g(""), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(g("點abcd"), Ok(("abcd", "點")));
+  assert_eq!(g("點點點a"), Ok(("a", "點點點")));
+}
+
+#[test]
+fn take_while_m_n_utf8() {
+  use crate::bytes::streaming::take_while_m_n;
+
+  fn parser(i: &str) -> IResult<&str, &str> {
+    take_while_m_n(1, 1, |c| c == 'A' || c == '😃')(i)
+  }
+  assert_eq!(parser("A!"), Ok(("!", "A")));
+  assert_eq!(parser("😃!"), Ok(("!", "😃")));
+}
+
+#[test]
+fn take_while_m_n_utf8_full_match() {
+  use crate::bytes::streaming::take_while_m_n;
+
+  fn parser(i: &str) -> IResult<&str, &str> {
+    take_while_m_n(1, 1, |c: char| c.is_alphabetic())(i)
+  }
+  assert_eq!(parser("øn"), Ok(("n", "ø")));
+}
+
+#[test]
+#[cfg(feature = "std")]
+fn recognize_take_while() {
+  use crate::bytes::streaming::take_while;
+  use crate::character::is_alphanumeric;
+  use crate::combinator::recognize;
+
+  fn x(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    take_while(is_alphanumeric)(i)
+  }
+  fn y(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    recognize(x)(i)
+  }
+  assert_eq!(x(&b"ab."[..]), Ok((&b"."[..], &b"ab"[..])));
+  println!("X: {:?}", x(&b"ab"[..]));
+  assert_eq!(y(&b"ab."[..]), Ok((&b"."[..], &b"ab"[..])));
+}
+
+#[test]
+fn length_bytes() {
+  use crate::{bytes::streaming::tag, multi::length_data, number::streaming::le_u8};
+
+  fn x(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    length_data(le_u8)(i)
+  }
+  assert_eq!(x(b"\x02..>>"), Ok((&b">>"[..], &b".."[..])));
+  assert_eq!(x(b"\x02.."), Ok((&[][..], &b".."[..])));
+  assert_eq!(x(b"\x02."), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(x(b"\x02"), Err(Err::Incomplete(Needed::new(2))));
+
+  fn y(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    let (i, _) = tag("magic")(i)?;
+    length_data(le_u8)(i)
+  }
+  assert_eq!(y(b"magic\x02..>>"), Ok((&b">>"[..], &b".."[..])));
+  assert_eq!(y(b"magic\x02.."), Ok((&[][..], &b".."[..])));
+  assert_eq!(y(b"magic\x02."), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(y(b"magic\x02"), Err(Err::Incomplete(Needed::new(2))));
+}
+
+#[cfg(feature = "alloc")]
+#[test]
+fn case_insensitive() {
+  use crate::bytes::streaming::tag_no_case;
+
+  fn test(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    tag_no_case("ABcd")(i)
+  }
+  assert_eq!(test(&b"aBCdefgh"[..]), Ok((&b"efgh"[..], &b"aBCd"[..])));
+  assert_eq!(test(&b"abcdefgh"[..]), Ok((&b"efgh"[..], &b"abcd"[..])));
+  assert_eq!(test(&b"ABCDefgh"[..]), Ok((&b"efgh"[..], &b"ABCD"[..])));
+  assert_eq!(test(&b"ab"[..]), Err(Err::Incomplete(Needed::new(2))));
+  assert_eq!(
+    test(&b"Hello"[..]),
+    Err(Err::Error(error_position!(&b"Hello"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    test(&b"Hel"[..]),
+    Err(Err::Error(error_position!(&b"Hel"[..], ErrorKind::Tag)))
+  );
+
+  fn test2(i: &str) -> IResult<&str, &str> {
+    tag_no_case("ABcd")(i)
+  }
+  assert_eq!(test2("aBCdefgh"), Ok(("efgh", "aBCd")));
+  assert_eq!(test2("abcdefgh"), Ok(("efgh", "abcd")));
+  assert_eq!(test2("ABCDefgh"), Ok(("efgh", "ABCD")));
+  assert_eq!(test2("ab"), Err(Err::Incomplete(Needed::new(2))));
+  assert_eq!(
+    test2("Hello"),
+    Err(Err::Error(error_position!(&"Hello"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    test2("Hel"),
+    Err(Err::Error(error_position!(&"Hel"[..], ErrorKind::Tag)))
+  );
+}
+
+#[test]
+fn tag_fixed_size_array() {
+  use crate::bytes::streaming::tag;
+
+  fn test(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    tag([0x42])(i)
+  }
+  fn test2(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    tag(&[0x42])(i)
+  }
+  let input = [0x42, 0x00];
+  assert_eq!(test(&input), Ok((&b"\x00"[..], &b"\x42"[..])));
+  assert_eq!(test2(&input), Ok((&b"\x00"[..], &b"\x42"[..])));
+}
diff --git a/src/character/complete.rs b/src/character/complete.rs
index beddc3f..5b73c14 100644
--- a/src/character/complete.rs
+++ b/src/character/complete.rs
@@ -2,27 +2,32 @@
 //!
 //! Functions recognizing specific characters.
 
-use crate::internal::{Err, IResult};
-use crate::error::ParseError;
-use crate::lib::std::ops::{Range, RangeFrom, RangeTo};
-use crate::traits::{AsChar, FindToken, InputIter, InputLength, InputTakeAtPosition, Slice};
-use crate::traits::{Compare, CompareResult};
+use crate::branch::alt;
+use crate::combinator::opt;
 use crate::error::ErrorKind;
+use crate::error::ParseError;
+use crate::internal::{Err, IResult};
+use crate::lib::std::ops::{Range, RangeFrom, RangeTo};
+use crate::traits::{
+  AsChar, FindToken, InputIter, InputLength, InputTake, InputTakeAtPosition, Slice,
+};
+use crate::traits::{Compare, CompareResult};
 
 /// Recognizes one character.
 ///
-/// *complete version*: Will return an error if there's not enough input data.
-///
+/// *Complete version*: Will return an error if there's not enough input data.
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind};
+/// # use nom::{Err, error::{ErrorKind, Error}, IResult};
 /// # use nom::character::complete::char;
-/// # fn main() {
-/// assert_eq!(char::<_, (&str, ErrorKind)>('a')("abc"), Ok(("bc", 'a')));
-/// assert_eq!(char::<_, (&str, ErrorKind)>('a')("bc"), Err(Err::Error(("bc", ErrorKind::Char))));
-/// assert_eq!(char::<_, (&str, ErrorKind)>('a')(""), Err(Err::Error(("", ErrorKind::Char))));
-/// # }
+/// fn parser(i: &str) -> IResult<&str, char> {
+///     char('a')(i)
+/// }
+/// assert_eq!(parser("abc"), Ok(("bc", 'a')));
+/// assert_eq!(parser(" abc"), Err(Err::Error(Error::new(" abc", ErrorKind::Char))));
+/// assert_eq!(parser("bc"), Err(Err::Error(Error::new("bc", ErrorKind::Char))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Char))));
 /// ```
 pub fn char<I, Error: ParseError<I>>(c: char) -> impl Fn(I) -> IResult<I, char, Error>
 where
@@ -38,20 +43,48 @@
   }
 }
 
+/// Recognizes one character and checks that it satisfies a predicate
+///
+/// *Complete version*: Will return an error if there's not enough input data.
+/// # Example
+///
+/// ```
+/// # use nom::{Err, error::{ErrorKind, Error}, Needed, IResult};
+/// # use nom::character::complete::satisfy;
+/// fn parser(i: &str) -> IResult<&str, char> {
+///     satisfy(|c| c == 'a' || c == 'b')(i)
+/// }
+/// assert_eq!(parser("abc"), Ok(("bc", 'a')));
+/// assert_eq!(parser("cd"), Err(Err::Error(Error::new("cd", ErrorKind::Satisfy))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Satisfy))));
+/// ```
+pub fn satisfy<F, I, Error: ParseError<I>>(cond: F) -> impl Fn(I) -> IResult<I, char, Error>
+where
+  I: Slice<RangeFrom<usize>> + InputIter,
+  <I as InputIter>::Item: AsChar,
+  F: Fn(char) -> bool,
+{
+  move |i: I| match (i).iter_elements().next().map(|t| {
+    let c = t.as_char();
+    let b = cond(c);
+    (c, b)
+  }) {
+    Some((c, true)) => Ok((i.slice(c.len()..), c)),
+    _ => Err(Err::Error(Error::from_error_kind(i, ErrorKind::Satisfy))),
+  }
+}
+
 /// Recognizes one of the provided characters.
 ///
-/// *complete version*: Will return an error if there's not enough input data.
-///
+/// *Complete version*: Will return an error if there's not enough input data.
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind};
 /// # use nom::character::complete::one_of;
-/// # fn main() {
 /// assert_eq!(one_of::<_, _, (&str, ErrorKind)>("abc")("b"), Ok(("", 'b')));
 /// assert_eq!(one_of::<_, _, (&str, ErrorKind)>("a")("bc"), Err(Err::Error(("bc", ErrorKind::OneOf))));
 /// assert_eq!(one_of::<_, _, (&str, ErrorKind)>("a")(""), Err(Err::Error(("", ErrorKind::OneOf))));
-/// # }
 /// ```
 pub fn one_of<I, T, Error: ParseError<I>>(list: T) -> impl Fn(I) -> IResult<I, char, Error>
 where
@@ -67,18 +100,15 @@
 
 /// Recognizes a character that is not in the provided characters.
 ///
-/// *complete version*: Will return an error if there's not enough input data.
-///
+/// *Complete version*: Will return an error if there's not enough input data.
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind};
 /// # use nom::character::complete::none_of;
-/// # fn main() {
 /// assert_eq!(none_of::<_, _, (&str, ErrorKind)>("abc")("z"), Ok(("", 'z')));
 /// assert_eq!(none_of::<_, _, (&str, ErrorKind)>("ab")("a"), Err(Err::Error(("a", ErrorKind::NoneOf))));
 /// assert_eq!(none_of::<_, _, (&str, ErrorKind)>("a")(""), Err(Err::Error(("", ErrorKind::NoneOf))));
-/// # }
 /// ```
 pub fn none_of<I, T, Error: ParseError<I>>(list: T) -> impl Fn(I) -> IResult<I, char, Error>
 where
@@ -94,26 +124,23 @@
 
 /// Recognizes the string "\r\n".
 ///
-/// *complete version*: Will return an error if there's not enough input data.
-///
+/// *Complete version*: Will return an error if there's not enough input data.
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult};
 /// # use nom::character::complete::crlf;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     crlf(input)
 /// }
 ///
 /// assert_eq!(parser("\r\nc"), Ok(("c", "\r\n")));
-/// assert_eq!(parser("ab\r\nc"), Err(Err::Error(("ab\r\nc", ErrorKind::CrLf))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::CrLf))));
-/// # }
+/// assert_eq!(parser("ab\r\nc"), Err(Err::Error(Error::new("ab\r\nc", ErrorKind::CrLf))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::CrLf))));
 /// ```
 pub fn crlf<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
-  T: Slice<Range<usize>> + Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
+  T: Slice<Range<usize>> + Slice<RangeFrom<usize>>,
   T: InputIter,
   T: Compare<&'static str>,
 {
@@ -128,24 +155,24 @@
 }
 
 //FIXME: there's still an incomplete
-/// Recognizes a string of any char except '\r' or '\n'.
+/// Recognizes a string of any char except '\r\n' or '\n'.
 ///
-/// *complete version*: Will return an error if there's not enough input data.
-///
+/// *Complete version*: Will return an error if there's not enough input data.
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult, Needed};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
 /// # use nom::character::complete::not_line_ending;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     not_line_ending(input)
 /// }
 ///
 /// assert_eq!(parser("ab\r\nc"), Ok(("\r\nc", "ab")));
+/// assert_eq!(parser("ab\nc"), Ok(("\nc", "ab")));
 /// assert_eq!(parser("abc"), Ok(("", "abc")));
 /// assert_eq!(parser(""), Ok(("", "")));
-/// # }
+/// assert_eq!(parser("a\rb\nc"), Err(Err::Error(Error { input: "a\rb\nc", code: ErrorKind::Tag })));
+/// assert_eq!(parser("a\rbc"), Err(Err::Error(Error { input: "a\rbc", code: ErrorKind::Tag })));
 /// ```
 pub fn not_line_ending<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -159,9 +186,7 @@
     let c = item.as_char();
     c == '\r' || c == '\n'
   }) {
-    None => {
-      Ok((input.slice(input.input_len()..), input))
-    }
+    None => Ok((input.slice(input.input_len()..), input)),
     Some(index) => {
       let mut it = input.slice(index..).iter_elements();
       let nth = it.next().unwrap().as_char();
@@ -185,22 +210,19 @@
 
 /// Recognizes an end of line (both '\n' and '\r\n').
 ///
-/// *complete version*: Will return an error if there's not enough input data.
-///
+/// *Complete version*: Will return an error if there's not enough input data.
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult, Needed};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
 /// # use nom::character::complete::line_ending;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     line_ending(input)
 /// }
 ///
 /// assert_eq!(parser("\r\nc"), Ok(("c", "\r\n")));
-/// assert_eq!(parser("ab\r\nc"), Err(Err::Error(("ab\r\nc", ErrorKind::CrLf))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::CrLf))));
-/// # }
+/// assert_eq!(parser("ab\r\nc"), Err(Err::Error(Error::new("ab\r\nc", ErrorKind::CrLf))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::CrLf))));
 /// ```
 pub fn line_ending<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -223,22 +245,19 @@
 
 /// Matches a newline character '\n'.
 ///
-/// *complete version*: Will return an error if there's not enough input data.
-///
+/// *Complete version*: Will return an error if there's not enough input data.
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult, Needed};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
 /// # use nom::character::complete::newline;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, char> {
 ///     newline(input)
 /// }
 ///
 /// assert_eq!(parser("\nc"), Ok(("c", '\n')));
-/// assert_eq!(parser("\r\nc"), Err(Err::Error(("\r\nc", ErrorKind::Char))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Char))));
-/// # }
+/// assert_eq!(parser("\r\nc"), Err(Err::Error(Error::new("\r\nc", ErrorKind::Char))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Char))));
 /// ```
 pub fn newline<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>
 where
@@ -250,22 +269,19 @@
 
 /// Matches a tab character '\t'.
 ///
-/// *complete version*: Will return an error if there's not enough input data.
-///
+/// *Complete version*: Will return an error if there's not enough input data.
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult, Needed};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
 /// # use nom::character::complete::tab;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, char> {
 ///     tab(input)
 /// }
 ///
 /// assert_eq!(parser("\tc"), Ok(("c", '\t')));
-/// assert_eq!(parser("\r\nc"), Err(Err::Error(("\r\nc", ErrorKind::Char))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Char))));
-/// # }
+/// assert_eq!(parser("\r\nc"), Err(Err::Error(Error::new("\r\nc", ErrorKind::Char))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Char))));
 /// ```
 pub fn tab<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>
 where
@@ -278,20 +294,17 @@
 /// Matches one byte as a character. Note that the input type will
 /// accept a `str`, but not a `&[u8]`, unlike many other nom parsers.
 ///
-/// *complete version*: Will return an error if there's not enough input data.
-///
+/// *Complete version*: Will return an error if there's not enough input data.
 /// # Example
 ///
 /// ```
-/// # use nom::{character::complete::anychar, Err, error::ErrorKind, IResult};
-/// # fn main() {
+/// # use nom::{character::complete::anychar, Err, error::{Error, ErrorKind}, IResult};
 /// fn parser(input: &str) -> IResult<&str, char> {
 ///     anychar(input)
 /// }
 ///
 /// assert_eq!(parser("abc"), Ok(("bc",'a')));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Eof))));
-/// # }
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Eof))));
 /// ```
 pub fn anychar<T, E: ParseError<T>>(input: T) -> IResult<T, char, E>
 where
@@ -310,15 +323,13 @@
 
 /// Recognizes zero or more lowercase and uppercase ASCII alphabetic characters: a-z, A-Z
 ///
-/// *complete version*: Will return the whole input if no terminating token is found (a non
+/// *Complete version*: Will return the whole input if no terminating token is found (a non
 /// alphabetic character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::complete::alpha0;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     alpha0(input)
 /// }
@@ -326,7 +337,6 @@
 /// assert_eq!(parser("ab1c"), Ok(("1c", "ab")));
 /// assert_eq!(parser("1c"), Ok(("1c", "")));
 /// assert_eq!(parser(""), Ok(("", "")));
-/// # }
 /// ```
 pub fn alpha0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -338,23 +348,20 @@
 
 /// Recognizes one or more lowercase and uppercase ASCII alphabetic characters: a-z, A-Z
 ///
-/// *complete version*: Will return an error if there's not enough input data,
+/// *Complete version*: Will return an error if there's not enough input data,
 /// or the whole input if no terminating token is found  (a non alphabetic character).
-///
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult, Needed};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
 /// # use nom::character::complete::alpha1;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     alpha1(input)
 /// }
 ///
 /// assert_eq!(parser("aB1c"), Ok(("1c", "aB")));
-/// assert_eq!(parser("1c"), Err(Err::Error(("1c", ErrorKind::Alpha))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Alpha))));
-/// # }
+/// assert_eq!(parser("1c"), Err(Err::Error(Error::new("1c", ErrorKind::Alpha))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Alpha))));
 /// ```
 pub fn alpha1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -366,15 +373,13 @@
 
 /// Recognizes zero or more ASCII numerical characters: 0-9
 ///
-/// *complete version*: Will return an error if there's not enough input data,
+/// *Complete version*: Will return an error if there's not enough input data,
 /// or the whole input if no terminating token is found (a non digit character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::complete::digit0;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     digit0(input)
 /// }
@@ -383,7 +388,6 @@
 /// assert_eq!(parser("21"), Ok(("", "21")));
 /// assert_eq!(parser("a21c"), Ok(("a21c", "")));
 /// assert_eq!(parser(""), Ok(("", "")));
-/// # }
 /// ```
 pub fn digit0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -395,23 +399,20 @@
 
 /// Recognizes one or more ASCII numerical characters: 0-9
 ///
-/// *complete version*: Will return an error if there's not enough input data,
+/// *Complete version*: Will return an error if there's not enough input data,
 /// or the whole input if no terminating token is found (a non digit character).
-///
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult, Needed};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
 /// # use nom::character::complete::digit1;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     digit1(input)
 /// }
 ///
 /// assert_eq!(parser("21c"), Ok(("c", "21")));
-/// assert_eq!(parser("c1"), Err(Err::Error(("c1", ErrorKind::Digit))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Digit))));
-/// # }
+/// assert_eq!(parser("c1"), Err(Err::Error(Error::new("c1", ErrorKind::Digit))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Digit))));
 /// ```
 pub fn digit1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -423,14 +424,12 @@
 
 /// Recognizes zero or more ASCII hexadecimal numerical characters: 0-9, A-F, a-f
 ///
-/// *complete version*: Will return the whole input if no terminating token is found (a non hexadecimal digit character).
-///
+/// *Complete version*: Will return the whole input if no terminating token is found (a non hexadecimal digit character).
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::complete::hex_digit0;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     hex_digit0(input)
 /// }
@@ -438,7 +437,6 @@
 /// assert_eq!(parser("21cZ"), Ok(("Z", "21c")));
 /// assert_eq!(parser("Z21c"), Ok(("Z21c", "")));
 /// assert_eq!(parser(""), Ok(("", "")));
-/// # }
 /// ```
 pub fn hex_digit0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -449,23 +447,20 @@
 }
 /// Recognizes one or more ASCII hexadecimal numerical characters: 0-9, A-F, a-f
 ///
-/// *complete version*: Will return an error if there's not enough input data,
+/// *Complete version*: Will return an error if there's not enough input data,
 /// or the whole input if no terminating token is found (a non hexadecimal digit character).
-///
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult, Needed};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
 /// # use nom::character::complete::hex_digit1;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     hex_digit1(input)
 /// }
 ///
 /// assert_eq!(parser("21cZ"), Ok(("Z", "21c")));
-/// assert_eq!(parser("H2"), Err(Err::Error(("H2", ErrorKind::HexDigit))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::HexDigit))));
-/// # }
+/// assert_eq!(parser("H2"), Err(Err::Error(Error::new("H2", ErrorKind::HexDigit))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::HexDigit))));
 /// ```
 pub fn hex_digit1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -477,15 +472,13 @@
 
 /// Recognizes zero or more octal characters: 0-7
 ///
-/// *complete version*: Will return the whole input if no terminating token is found (a non octal
+/// *Complete version*: Will return the whole input if no terminating token is found (a non octal
 /// digit character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::complete::oct_digit0;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     oct_digit0(input)
 /// }
@@ -493,7 +486,6 @@
 /// assert_eq!(parser("21cZ"), Ok(("cZ", "21")));
 /// assert_eq!(parser("Z21c"), Ok(("Z21c", "")));
 /// assert_eq!(parser(""), Ok(("", "")));
-/// # }
 /// ```
 pub fn oct_digit0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -505,23 +497,20 @@
 
 /// Recognizes one or more octal characters: 0-7
 ///
-/// *complete version*: Will return an error if there's not enough input data,
+/// *Complete version*: Will return an error if there's not enough input data,
 /// or the whole input if no terminating token is found (a non octal digit character).
-///
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult, Needed};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
 /// # use nom::character::complete::oct_digit1;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     oct_digit1(input)
 /// }
 ///
 /// assert_eq!(parser("21cZ"), Ok(("cZ", "21")));
-/// assert_eq!(parser("H2"), Err(Err::Error(("H2", ErrorKind::OctDigit))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::OctDigit))));
-/// # }
+/// assert_eq!(parser("H2"), Err(Err::Error(Error::new("H2", ErrorKind::OctDigit))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::OctDigit))));
 /// ```
 pub fn oct_digit1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -533,15 +522,13 @@
 
 /// Recognizes zero or more ASCII numerical and alphabetic characters: 0-9, a-z, A-Z
 ///
-/// *complete version*: Will return the whole input if no terminating token is found (a non
+/// *Complete version*: Will return the whole input if no terminating token is found (a non
 /// alphanumerical character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::complete::alphanumeric0;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     alphanumeric0(input)
 /// }
@@ -549,7 +536,6 @@
 /// assert_eq!(parser("21cZ%1"), Ok(("%1", "21cZ")));
 /// assert_eq!(parser("&Z21c"), Ok(("&Z21c", "")));
 /// assert_eq!(parser(""), Ok(("", "")));
-/// # }
 /// ```
 pub fn alphanumeric0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -561,23 +547,20 @@
 
 /// Recognizes one or more ASCII numerical and alphabetic characters: 0-9, a-z, A-Z
 ///
-/// *complete version*: Will return an error if there's not enough input data,
+/// *Complete version*: Will return an error if there's not enough input data,
 /// or the whole input if no terminating token is found (a non alphanumerical character).
-///
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult, Needed};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
 /// # use nom::character::complete::alphanumeric1;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     alphanumeric1(input)
 /// }
 ///
 /// assert_eq!(parser("21cZ%1"), Ok(("%1", "21cZ")));
-/// assert_eq!(parser("&H2"), Err(Err::Error(("&H2", ErrorKind::AlphaNumeric))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::AlphaNumeric))));
-/// # }
+/// assert_eq!(parser("&H2"), Err(Err::Error(Error::new("&H2", ErrorKind::AlphaNumeric))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::AlphaNumeric))));
 /// ```
 pub fn alphanumeric1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -589,15 +572,13 @@
 
 /// Recognizes zero or more spaces and tabs.
 ///
-/// *complete version*: Will return the whole input if no terminating token is found (a non space
+/// *Complete version*: Will return the whole input if no terminating token is found (a non space
 /// character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::complete::space0;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     space0(input)
 /// }
@@ -605,7 +586,6 @@
 /// assert_eq!(parser(" \t21c"), Ok(("21c", " \t")));
 /// assert_eq!(parser("Z21c"), Ok(("Z21c", "")));
 /// assert_eq!(parser(""), Ok(("", "")));
-/// # }
 /// ```
 pub fn space0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -613,30 +593,27 @@
   <T as InputTakeAtPosition>::Item: AsChar + Clone,
 {
   input.split_at_position_complete(|item| {
-    let c = item.clone().as_char();
+    let c = item.as_char();
     !(c == ' ' || c == '\t')
   })
 }
 
 /// Recognizes one or more spaces and tabs.
 ///
-/// *complete version*: Will return an error if there's not enough input data,
+/// *Complete version*: Will return an error if there's not enough input data,
 /// or the whole input if no terminating token is found (a non space character).
-///
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult, Needed};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
 /// # use nom::character::complete::space1;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     space1(input)
 /// }
 ///
 /// assert_eq!(parser(" \t21c"), Ok(("21c", " \t")));
-/// assert_eq!(parser("H2"), Err(Err::Error(("H2", ErrorKind::Space))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Space))));
-/// # }
+/// assert_eq!(parser("H2"), Err(Err::Error(Error::new("H2", ErrorKind::Space))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Space))));
 /// ```
 pub fn space1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -645,7 +622,7 @@
 {
   input.split_at_position1_complete(
     |item| {
-      let c = item.clone().as_char();
+      let c = item.as_char();
       !(c == ' ' || c == '\t')
     },
     ErrorKind::Space,
@@ -654,15 +631,13 @@
 
 /// Recognizes zero or more spaces, tabs, carriage returns and line feeds.
 ///
-/// *complete version*: will return the whole input if no terminating token is found (a non space
+/// *Complete version*: will return the whole input if no terminating token is found (a non space
 /// character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::complete::multispace0;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     multispace0(input)
 /// }
@@ -670,7 +645,6 @@
 /// assert_eq!(parser(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
 /// assert_eq!(parser("Z21c"), Ok(("Z21c", "")));
 /// assert_eq!(parser(""), Ok(("", "")));
-/// # }
 /// ```
 pub fn multispace0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -678,30 +652,27 @@
   <T as InputTakeAtPosition>::Item: AsChar + Clone,
 {
   input.split_at_position_complete(|item| {
-    let c = item.clone().as_char();
+    let c = item.as_char();
     !(c == ' ' || c == '\t' || c == '\r' || c == '\n')
   })
 }
 
 /// Recognizes one or more spaces, tabs, carriage returns and line feeds.
 ///
-/// *complete version*: will return an error if there's not enough input data,
+/// *Complete version*: will return an error if there's not enough input data,
 /// or the whole input if no terminating token is found (a non space character).
-///
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult, Needed};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
 /// # use nom::character::complete::multispace1;
-/// # fn main() {
 /// fn parser(input: &str) -> IResult<&str, &str> {
 ///     multispace1(input)
 /// }
 ///
 /// assert_eq!(parser(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
-/// assert_eq!(parser("H2"), Err(Err::Error(("H2", ErrorKind::MultiSpace))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::MultiSpace))));
-/// # }
+/// assert_eq!(parser("H2"), Err(Err::Error(Error::new("H2", ErrorKind::MultiSpace))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::MultiSpace))));
 /// ```
 pub fn multispace1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -710,17 +681,141 @@
 {
   input.split_at_position1_complete(
     |item| {
-      let c = item.clone().as_char();
+      let c = item.as_char();
       !(c == ' ' || c == '\t' || c == '\r' || c == '\n')
     },
     ErrorKind::MultiSpace,
   )
 }
 
+pub(crate) fn sign<T, E: ParseError<T>>(input: T) -> IResult<T, bool, E>
+where
+  T: Clone + InputTake,
+  T: for<'a> Compare<&'a [u8]>,
+{
+  use crate::bytes::complete::tag;
+  use crate::combinator::value;
+
+  let (i, opt_sign) = opt(alt((
+    value(false, tag(&b"-"[..])),
+    value(true, tag(&b"+"[..])),
+  )))(input)?;
+  let sign = opt_sign.unwrap_or(true);
+
+  Ok((i, sign))
+}
+
+#[doc(hidden)]
+macro_rules! ints {
+    ($($t:tt)+) => {
+        $(
+        /// will parse a number in text form to a number
+        ///
+        /// *Complete version*: can parse until the end of input.
+        pub fn $t<T, E: ParseError<T>>(input: T) -> IResult<T, $t, E>
+            where
+            T: InputIter + Slice<RangeFrom<usize>> + InputLength + InputTake + Clone,
+            <T as InputIter>::Item: AsChar,
+            T: for <'a> Compare<&'a[u8]>,
+            {
+                let (i, sign) = sign(input.clone())?;
+
+                if i.input_len() == 0 {
+                    return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit)));
+                }
+
+                let mut value: $t = 0;
+                if sign {
+                    for (pos, c) in i.iter_indices() {
+                        match c.as_char().to_digit(10) {
+                            None => {
+                                if pos == 0 {
+                                    return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit)));
+                                } else {
+                                    return Ok((i.slice(pos..), value));
+                                }
+                            },
+                            Some(d) => match value.checked_mul(10).and_then(|v| v.checked_add(d as $t)) {
+                                None => return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit))),
+                                Some(v) => value = v,
+                            }
+                        }
+                    }
+                } else {
+                    for (pos, c) in i.iter_indices() {
+                        match c.as_char().to_digit(10) {
+                            None => {
+                                if pos == 0 {
+                                    return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit)));
+                                } else {
+                                    return Ok((i.slice(pos..), value));
+                                }
+                            },
+                            Some(d) => match value.checked_mul(10).and_then(|v| v.checked_sub(d as $t)) {
+                                None => return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit))),
+                                Some(v) => value = v,
+                            }
+                        }
+                    }
+                }
+
+                Ok((i.slice(i.input_len()..), value))
+            }
+        )+
+    }
+}
+
+ints! { i8 i16 i32 i64 i128 }
+
+#[doc(hidden)]
+macro_rules! uints {
+    ($($t:tt)+) => {
+        $(
+        /// will parse a number in text form to a number
+        ///
+        /// *Complete version*: can parse until the end of input.
+        pub fn $t<T, E: ParseError<T>>(input: T) -> IResult<T, $t, E>
+            where
+            T: InputIter + Slice<RangeFrom<usize>> + InputLength,
+            <T as InputIter>::Item: AsChar,
+            {
+                let i = input;
+
+                if i.input_len() == 0 {
+                    return Err(Err::Error(E::from_error_kind(i, ErrorKind::Digit)));
+                }
+
+                let mut value: $t = 0;
+                for (pos, c) in i.iter_indices() {
+                    match c.as_char().to_digit(10) {
+                        None => {
+                            if pos == 0 {
+                                return Err(Err::Error(E::from_error_kind(i, ErrorKind::Digit)));
+                            } else {
+                                return Ok((i.slice(pos..), value));
+                            }
+                        },
+                        Some(d) => match value.checked_mul(10).and_then(|v| v.checked_add(d as $t)) {
+                            None => return Err(Err::Error(E::from_error_kind(i, ErrorKind::Digit))),
+                            Some(v) => value = v,
+                        }
+                    }
+                }
+
+                Ok((i.slice(i.input_len()..), value))
+            }
+        )+
+    }
+}
+
+uints! { u8 u16 u32 u64 u128 }
+
 #[cfg(test)]
 mod tests {
   use super::*;
   use crate::internal::Err;
+  use crate::traits::ParseTo;
+  use proptest::prelude::*;
 
   macro_rules! assert_parse(
     ($left: expr, $right: expr) => {
@@ -729,7 +824,6 @@
     };
   );
 
-
   #[test]
   fn character() {
     let empty: &[u8] = b"";
@@ -741,50 +835,35 @@
     let f: &[u8] = b" ;";
     //assert_eq!(alpha1::<_, (_, ErrorKind)>(a), Err(Err::Incomplete(Needed::Size(1))));
     assert_parse!(alpha1(a), Ok((empty, a)));
-    assert_eq!(
-      alpha1(b),
-      Err(Err::Error((b, ErrorKind::Alpha)))
-    );
+    assert_eq!(alpha1(b), Err(Err::Error((b, ErrorKind::Alpha))));
     assert_eq!(alpha1::<_, (_, ErrorKind)>(c), Ok((&c[1..], &b"a"[..])));
-    assert_eq!(alpha1::<_, (_, ErrorKind)>(d), Ok(("é12".as_bytes(), &b"az"[..])));
     assert_eq!(
-      digit1(a),
-      Err(Err::Error((a, ErrorKind::Digit)))
+      alpha1::<_, (_, ErrorKind)>(d),
+      Ok(("é12".as_bytes(), &b"az"[..]))
     );
+    assert_eq!(digit1(a), Err(Err::Error((a, ErrorKind::Digit))));
     assert_eq!(digit1::<_, (_, ErrorKind)>(b), Ok((empty, b)));
-    assert_eq!(
-      digit1(c),
-      Err(Err::Error((c, ErrorKind::Digit)))
-    );
-    assert_eq!(
-      digit1(d),
-      Err(Err::Error((d, ErrorKind::Digit)))
-    );
+    assert_eq!(digit1(c), Err(Err::Error((c, ErrorKind::Digit))));
+    assert_eq!(digit1(d), Err(Err::Error((d, ErrorKind::Digit))));
     assert_eq!(hex_digit1::<_, (_, ErrorKind)>(a), Ok((empty, a)));
     assert_eq!(hex_digit1::<_, (_, ErrorKind)>(b), Ok((empty, b)));
     assert_eq!(hex_digit1::<_, (_, ErrorKind)>(c), Ok((empty, c)));
-    assert_eq!(hex_digit1::<_, (_, ErrorKind)>(d), Ok(("zé12".as_bytes(), &b"a"[..])));
     assert_eq!(
-      hex_digit1(e),
-      Err(Err::Error((e, ErrorKind::HexDigit)))
+      hex_digit1::<_, (_, ErrorKind)>(d),
+      Ok(("zé12".as_bytes(), &b"a"[..]))
     );
-    assert_eq!(
-      oct_digit1(a),
-      Err(Err::Error((a, ErrorKind::OctDigit)))
-    );
+    assert_eq!(hex_digit1(e), Err(Err::Error((e, ErrorKind::HexDigit))));
+    assert_eq!(oct_digit1(a), Err(Err::Error((a, ErrorKind::OctDigit))));
     assert_eq!(oct_digit1::<_, (_, ErrorKind)>(b), Ok((empty, b)));
-    assert_eq!(
-      oct_digit1(c),
-      Err(Err::Error((c, ErrorKind::OctDigit)))
-    );
-    assert_eq!(
-      oct_digit1(d),
-      Err(Err::Error((d, ErrorKind::OctDigit)))
-    );
+    assert_eq!(oct_digit1(c), Err(Err::Error((c, ErrorKind::OctDigit))));
+    assert_eq!(oct_digit1(d), Err(Err::Error((d, ErrorKind::OctDigit))));
     assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(a), Ok((empty, a)));
     //assert_eq!(fix_error!(b,(), alphanumeric), Ok((empty, b)));
     assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(c), Ok((empty, c)));
-    assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(d), Ok(("é12".as_bytes(), &b"az"[..])));
+    assert_eq!(
+      alphanumeric1::<_, (_, ErrorKind)>(d),
+      Ok(("é12".as_bytes(), &b"az"[..]))
+    );
     assert_eq!(space1::<_, (_, ErrorKind)>(e), Ok((empty, e)));
     assert_eq!(space1::<_, (_, ErrorKind)>(f), Ok((&b";"[..], &b" "[..])));
   }
@@ -799,46 +878,22 @@
     let d = "azé12";
     let e = " ";
     assert_eq!(alpha1::<_, (_, ErrorKind)>(a), Ok((empty, a)));
-    assert_eq!(
-      alpha1(b),
-      Err(Err::Error((b, ErrorKind::Alpha)))
-    );
+    assert_eq!(alpha1(b), Err(Err::Error((b, ErrorKind::Alpha))));
     assert_eq!(alpha1::<_, (_, ErrorKind)>(c), Ok((&c[1..], &"a"[..])));
     assert_eq!(alpha1::<_, (_, ErrorKind)>(d), Ok(("é12", &"az"[..])));
-    assert_eq!(
-      digit1(a),
-      Err(Err::Error((a, ErrorKind::Digit)))
-    );
+    assert_eq!(digit1(a), Err(Err::Error((a, ErrorKind::Digit))));
     assert_eq!(digit1::<_, (_, ErrorKind)>(b), Ok((empty, b)));
-    assert_eq!(
-      digit1(c),
-      Err(Err::Error((c, ErrorKind::Digit)))
-    );
-    assert_eq!(
-      digit1(d),
-      Err(Err::Error((d, ErrorKind::Digit)))
-    );
+    assert_eq!(digit1(c), Err(Err::Error((c, ErrorKind::Digit))));
+    assert_eq!(digit1(d), Err(Err::Error((d, ErrorKind::Digit))));
     assert_eq!(hex_digit1::<_, (_, ErrorKind)>(a), Ok((empty, a)));
     assert_eq!(hex_digit1::<_, (_, ErrorKind)>(b), Ok((empty, b)));
     assert_eq!(hex_digit1::<_, (_, ErrorKind)>(c), Ok((empty, c)));
     assert_eq!(hex_digit1::<_, (_, ErrorKind)>(d), Ok(("zé12", &"a"[..])));
-    assert_eq!(
-      hex_digit1(e),
-      Err(Err::Error((e, ErrorKind::HexDigit)))
-    );
-    assert_eq!(
-      oct_digit1(a),
-      Err(Err::Error((a, ErrorKind::OctDigit)))
-    );
+    assert_eq!(hex_digit1(e), Err(Err::Error((e, ErrorKind::HexDigit))));
+    assert_eq!(oct_digit1(a), Err(Err::Error((a, ErrorKind::OctDigit))));
     assert_eq!(oct_digit1::<_, (_, ErrorKind)>(b), Ok((empty, b)));
-    assert_eq!(
-      oct_digit1(c),
-      Err(Err::Error((c, ErrorKind::OctDigit)))
-    );
-    assert_eq!(
-      oct_digit1(d),
-      Err(Err::Error((d, ErrorKind::OctDigit)))
-    );
+    assert_eq!(oct_digit1(c), Err(Err::Error((c, ErrorKind::OctDigit))));
+    assert_eq!(oct_digit1(d), Err(Err::Error((d, ErrorKind::OctDigit))));
     assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(a), Ok((empty, a)));
     //assert_eq!(fix_error!(b,(), alphanumeric), Ok((empty, b)));
     assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(c), Ok((empty, c)));
@@ -903,7 +958,10 @@
   #[test]
   fn is_not_line_ending_bytes() {
     let a: &[u8] = b"ab12cd\nefgh";
-    assert_eq!(not_line_ending::<_, (_, ErrorKind)>(a), Ok((&b"\nefgh"[..], &b"ab12cd"[..])));
+    assert_eq!(
+      not_line_ending::<_, (_, ErrorKind)>(a),
+      Ok((&b"\nefgh"[..], &b"ab12cd"[..]))
+    );
 
     let b: &[u8] = b"ab12cd\nefgh\nijkl";
     assert_eq!(
@@ -918,12 +976,14 @@
     );
 
     let d: &[u8] = b"ab12cd";
-    assert_eq!(not_line_ending::<_, (_, ErrorKind)>(d), Ok((&[][..], &d[..])));
+    assert_eq!(
+      not_line_ending::<_, (_, ErrorKind)>(d),
+      Ok((&[][..], &d[..]))
+    );
   }
 
   #[test]
   fn is_not_line_ending_str() {
-
     /*
     let a: &str = "ab12cd\nefgh";
     assert_eq!(not_line_ending(a), Ok((&"\nefgh"[..], &"ab12cd"[..])));
@@ -942,10 +1002,7 @@
     */
 
     let f = "βèƒôřè\rÂßÇáƒƭèř";
-    assert_eq!(
-      not_line_ending(f),
-      Err(Err::Error((f, ErrorKind::Tag)))
-    );
+    assert_eq!(not_line_ending(f), Err(Err::Error((f, ErrorKind::Tag))));
 
     let g2: &str = "ab12cd";
     assert_eq!(not_line_ending::<_, (_, ErrorKind)>(g2), Ok(("", g2)));
@@ -1007,12 +1064,10 @@
 
   #[test]
   fn full_line_windows() {
-    //let not_line_ending = |i:&[u8]| take_while(|c| c != b'\r' && c != b'\n')(i);
-
-    named!(
-      take_full_line<(&[u8], &[u8])>,
-      tuple!(not_line_ending, line_ending)
-    );
+    use crate::sequence::pair;
+    fn take_full_line(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
+      pair(not_line_ending, line_ending)(i)
+    }
     let input = b"abc\r\n";
     let output = take_full_line(input);
     assert_eq!(output, Ok((&b""[..], (&b"abc"[..], &b"\r\n"[..]))));
@@ -1020,11 +1075,10 @@
 
   #[test]
   fn full_line_unix() {
-    //let not_line_ending = |i:&[u8]| take_while(|c| c != b'\n')(i);
-    named!(
-      take_full_line<(&[u8], &[u8])>,
-      tuple!(not_line_ending, line_ending)
-    );
+    use crate::sequence::pair;
+    fn take_full_line(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
+      pair(not_line_ending, line_ending)(i)
+    }
     let input = b"abc\n";
     let output = take_full_line(input);
     assert_eq!(output, Ok((&b""[..], (&b"abc"[..], &b"\n"[..]))));
@@ -1047,14 +1101,20 @@
   #[test]
   fn cr_lf() {
     assert_parse!(crlf(&b"\r\na"[..]), Ok((&b"a"[..], &b"\r\n"[..])));
-    assert_parse!(crlf(&b"\r"[..]), Err(Err::Error(error_position!(&b"\r"[..], ErrorKind::CrLf))));
+    assert_parse!(
+      crlf(&b"\r"[..]),
+      Err(Err::Error(error_position!(&b"\r"[..], ErrorKind::CrLf)))
+    );
     assert_parse!(
       crlf(&b"\ra"[..]),
       Err(Err::Error(error_position!(&b"\ra"[..], ErrorKind::CrLf)))
     );
 
     assert_parse!(crlf("\r\na"), Ok(("a", "\r\n")));
-    assert_parse!(crlf("\r"), Err(Err::Error(error_position!(&"\r"[..], ErrorKind::CrLf))));
+    assert_parse!(
+      crlf("\r"),
+      Err(Err::Error(error_position!(&"\r"[..], ErrorKind::CrLf)))
+    );
     assert_parse!(
       crlf("\ra"),
       Err(Err::Error(error_position!("\ra", ErrorKind::CrLf)))
@@ -1065,7 +1125,10 @@
   fn end_of_line() {
     assert_parse!(line_ending(&b"\na"[..]), Ok((&b"a"[..], &b"\n"[..])));
     assert_parse!(line_ending(&b"\r\na"[..]), Ok((&b"a"[..], &b"\r\n"[..])));
-    assert_parse!(line_ending(&b"\r"[..]), Err(Err::Error(error_position!(&b"\r"[..], ErrorKind::CrLf))));
+    assert_parse!(
+      line_ending(&b"\r"[..]),
+      Err(Err::Error(error_position!(&b"\r"[..], ErrorKind::CrLf)))
+    );
     assert_parse!(
       line_ending(&b"\ra"[..]),
       Err(Err::Error(error_position!(&b"\ra"[..], ErrorKind::CrLf)))
@@ -1073,10 +1136,74 @@
 
     assert_parse!(line_ending("\na"), Ok(("a", "\n")));
     assert_parse!(line_ending("\r\na"), Ok(("a", "\r\n")));
-    assert_parse!(line_ending("\r"), Err(Err::Error(error_position!(&"\r"[..], ErrorKind::CrLf))));
+    assert_parse!(
+      line_ending("\r"),
+      Err(Err::Error(error_position!(&"\r"[..], ErrorKind::CrLf)))
+    );
     assert_parse!(
       line_ending("\ra"),
       Err(Err::Error(error_position!("\ra", ErrorKind::CrLf)))
     );
   }
+
+  fn digit_to_i16(input: &str) -> IResult<&str, i16> {
+    let i = input;
+    let (i, opt_sign) = opt(alt((char('+'), char('-'))))(i)?;
+    let sign = match opt_sign {
+      Some('+') => true,
+      Some('-') => false,
+      _ => true,
+    };
+
+    let (i, s) = match digit1::<_, crate::error::Error<_>>(i) {
+      Ok((i, s)) => (i, s),
+      Err(_) => {
+        return Err(Err::Error(crate::error::Error::from_error_kind(
+          input,
+          ErrorKind::Digit,
+        )))
+      }
+    };
+
+    match s.parse_to() {
+      Some(n) => {
+        if sign {
+          Ok((i, n))
+        } else {
+          Ok((i, -n))
+        }
+      }
+      None => Err(Err::Error(crate::error::Error::from_error_kind(
+        i,
+        ErrorKind::Digit,
+      ))),
+    }
+  }
+
+  fn digit_to_u32(i: &str) -> IResult<&str, u32> {
+    let (i, s) = digit1(i)?;
+    match s.parse_to() {
+      Some(n) => Ok((i, n)),
+      None => Err(Err::Error(crate::error::Error::from_error_kind(
+        i,
+        ErrorKind::Digit,
+      ))),
+    }
+  }
+
+  proptest! {
+    #[test]
+    fn ints(s in "\\PC*") {
+        let res1 = digit_to_i16(&s);
+        let res2 = i16(s.as_str());
+        assert_eq!(res1, res2);
+    }
+
+    #[test]
+    fn uints(s in "\\PC*") {
+        let res1 = digit_to_u32(&s);
+        let res2 = u32(s.as_str());
+        assert_eq!(res1, res2);
+    }
+  }
 }
diff --git a/src/character/macros.rs b/src/character/macros.rs
deleted file mode 100644
index 097ee40..0000000
--- a/src/character/macros.rs
+++ /dev/null
@@ -1,112 +0,0 @@
-/// Character level parsers
-
-/// matches one of the provided characters
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-/// named!(simple<char>, one_of!(&b"abc"[..]));
-/// assert_eq!(simple(b"a123"), Ok((&b"123"[..], 'a')));
-///
-/// named!(a_or_b<&str, char>, one_of!("ab汉"));
-/// assert_eq!(a_or_b("汉jiosfe"), Ok(("jiosfe", '汉')));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! one_of (
-  ($i:expr, $inp: expr) => ( $crate::character::streaming::one_of($inp)($i) );
-);
-
-/// matches anything but the provided characters
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,error::ErrorKind};
-/// # fn main() {
-/// named!(no_letter_a<char>, none_of!(&b"abc"[..]));
-/// assert_eq!(no_letter_a(b"123"), Ok((&b"23"[..], '1')));
-///
-/// named!(err_on_single_quote<char>, none_of!(&b"'"[..]));
-/// assert_eq!(err_on_single_quote(b"'jiosfe"), Err(Err::Error(error_position!(&b"'jiosfe"[..], ErrorKind::NoneOf))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! none_of (
-  ($i:expr, $inp: expr) => ( $crate::character::streaming::none_of($inp)($i) );
-);
-
-/// matches one character: `char!(char) => &[u8] -> IResult<&[u8], char>
-///
-/// # Example
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,error::ErrorKind};
-/// # fn main() {
-/// named!(match_letter_a<char>, char!('a'));
-/// assert_eq!(match_letter_a(b"abc"), Ok((&b"bc"[..],'a')));
-///
-/// assert_eq!(match_letter_a(b"123cdef"), Err(Err::Error(error_position!(&b"123cdef"[..], ErrorKind::Char))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! char (
-  ($i:expr, $c: expr) => ( $crate::character::streaming::char($c)($i) );
-);
-
-#[cfg(test)]
-mod tests {
-  use crate::internal::Err;
-  use crate::error::ErrorKind;
-
-  #[test]
-  fn one_of() {
-    named!(f<char>, one_of!("ab"));
-
-    let a = &b"abcd"[..];
-    assert_eq!(f(a), Ok((&b"bcd"[..], 'a')));
-
-    let b = &b"cde"[..];
-    assert_eq!(f(b), Err(Err::Error(error_position!(b, ErrorKind::OneOf))));
-
-    named!(utf8(&str) -> char,
-      one_of!("+\u{FF0B}"));
-
-    assert!(utf8("+").is_ok());
-    assert!(utf8("\u{FF0B}").is_ok());
-  }
-
-  #[test]
-  fn none_of() {
-    named!(f<char>, none_of!("ab"));
-
-    let a = &b"abcd"[..];
-    assert_eq!(f(a), Err(Err::Error(error_position!(a, ErrorKind::NoneOf))));
-
-    let b = &b"cde"[..];
-    assert_eq!(f(b), Ok((&b"de"[..], 'c')));
-  }
-
-  #[test]
-  fn char() {
-    named!(f<char>, char!('c'));
-
-    let a = &b"abcd"[..];
-    assert_eq!(f(a), Err(Err::Error(error_position!(a, ErrorKind::Char))));
-
-    let b = &b"cde"[..];
-    assert_eq!(f(b), Ok((&b"de"[..], 'c')));
-  }
-
-  #[test]
-  fn char_str() {
-    named!(f<&str, char>, char!('c'));
-
-    let a = &"abcd"[..];
-    assert_eq!(f(a), Err(Err::Error(error_position!(a, ErrorKind::Char))));
-
-    let b = &"cde"[..];
-    assert_eq!(f(b), Ok((&"de"[..], 'c')));
-  }
-}
diff --git a/src/character/mod.rs b/src/character/mod.rs
index 3f0899a..2c5d3bc 100644
--- a/src/character/mod.rs
+++ b/src/character/mod.rs
@@ -1,12 +1,12 @@
-//! character specific parsers and combinators
+//! Character specific parsers and combinators
 //!
-//! functions recognizing specific characters
+//! Functions recognizing specific characters
 
-#[macro_use]
-mod macros;
+#[cfg(test)]
+mod tests;
 
-pub mod streaming;
 pub mod complete;
+pub mod streaming;
 
 /// Tests if byte is ASCII alphabetic: A-Z, a-z
 ///
@@ -99,3 +99,18 @@
   chr == b' ' || chr == b'\t'
 }
 
+/// Tests if byte is ASCII newline: \n
+///
+/// # Example
+///
+/// ```
+/// # use nom::character::is_newline;
+/// assert_eq!(is_newline(b'\n'), true);
+/// assert_eq!(is_newline(b'\r'), false);
+/// assert_eq!(is_newline(b' '), false);
+/// assert_eq!(is_newline(b'\t'), false);
+/// ```
+#[inline]
+pub fn is_newline(chr: u8) -> bool {
+  chr == b'\n'
+}
diff --git a/src/character/streaming.rs b/src/character/streaming.rs
index f62dace..88aabba 100644
--- a/src/character/streaming.rs
+++ b/src/character/streaming.rs
@@ -1,61 +1,91 @@
-//! character specific parsers and combinators, streaming version
+//! Character specific parsers and combinators, streaming version
 //!
-//! functions recognizing specific characters
+//! Functions recognizing specific characters
 
-use crate::internal::{Err, IResult, Needed};
-use crate::error::ParseError;
-use crate::lib::std::ops::{Range, RangeFrom, RangeTo};
-use crate::traits::{AsChar, FindToken, InputIter, InputLength, InputTakeAtPosition, Slice};
-use crate::traits::{Compare, CompareResult};
-
+use crate::branch::alt;
+use crate::combinator::opt;
 use crate::error::ErrorKind;
+use crate::error::ParseError;
+use crate::internal::{Err, IResult, Needed};
+use crate::lib::std::ops::{Range, RangeFrom, RangeTo};
+use crate::traits::{
+  AsChar, FindToken, InputIter, InputLength, InputTake, InputTakeAtPosition, Slice,
+};
+use crate::traits::{Compare, CompareResult};
 
 /// Recognizes one character.
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
-///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::{Err, error::{ErrorKind, Error}, Needed, IResult};
 /// # use nom::character::streaming::char;
-/// # fn main() {
-/// assert_eq!(char::<_, (_, ErrorKind)>('a')(&b"abc"[..]), Ok((&b"bc"[..], 'a')));
-/// assert_eq!(char::<_, (_, ErrorKind)>('a')(&b"bc"[..]), Err(Err::Error((&b"bc"[..], ErrorKind::Char))));
-/// assert_eq!(char::<_, (_, ErrorKind)>('a')(&b""[..]), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// fn parser(i: &str) -> IResult<&str, char> {
+///     char('a')(i)
+/// }
+/// assert_eq!(parser("abc"), Ok(("bc", 'a')));
+/// assert_eq!(parser("bc"), Err(Err::Error(Error::new("bc", ErrorKind::Char))));
+/// assert_eq!(parser(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn char<I, Error: ParseError<I>>(c: char) -> impl Fn(I) -> IResult<I, char, Error>
 where
-  I: Slice<RangeFrom<usize>> + InputIter,
+  I: Slice<RangeFrom<usize>> + InputIter + InputLength,
   <I as InputIter>::Item: AsChar,
 {
   move |i: I| match (i).iter_elements().next().map(|t| {
     let b = t.as_char() == c;
     (&c, b)
   }) {
-    None => Err(Err::Incomplete(Needed::Size(1))),
-    Some((_, false)) => {
-      Err(Err::Error(Error::from_char(i, c)))
-    }
+    None => Err(Err::Incomplete(Needed::new(c.len() - i.input_len()))),
+    Some((_, false)) => Err(Err::Error(Error::from_char(i, c))),
     Some((c, true)) => Ok((i.slice(c.len()..), c.as_char())),
   }
 }
 
+/// Recognizes one character and checks that it satisfies a predicate
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
+/// # Example
+///
+/// ```
+/// # use nom::{Err, error::{ErrorKind, Error}, Needed, IResult};
+/// # use nom::character::streaming::satisfy;
+/// fn parser(i: &str) -> IResult<&str, char> {
+///     satisfy(|c| c == 'a' || c == 'b')(i)
+/// }
+/// assert_eq!(parser("abc"), Ok(("bc", 'a')));
+/// assert_eq!(parser("cd"), Err(Err::Error(Error::new("cd", ErrorKind::Satisfy))));
+/// assert_eq!(parser(""), Err(Err::Incomplete(Needed::Unknown)));
+/// ```
+pub fn satisfy<F, I, Error: ParseError<I>>(cond: F) -> impl Fn(I) -> IResult<I, char, Error>
+where
+  I: Slice<RangeFrom<usize>> + InputIter,
+  <I as InputIter>::Item: AsChar,
+  F: Fn(char) -> bool,
+{
+  move |i: I| match (i).iter_elements().next().map(|t| {
+    let c = t.as_char();
+    let b = cond(c);
+    (c, b)
+  }) {
+    None => Err(Err::Incomplete(Needed::Unknown)),
+    Some((_, false)) => Err(Err::Error(Error::from_error_kind(i, ErrorKind::Satisfy))),
+    Some((c, true)) => Ok((i.slice(c.len()..), c)),
+  }
+}
+
 /// Recognizes one of the provided characters.
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
-///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::character::streaming::one_of;
-/// # fn main() {
 /// assert_eq!(one_of::<_, _, (_, ErrorKind)>("abc")("b"), Ok(("", 'b')));
 /// assert_eq!(one_of::<_, _, (_, ErrorKind)>("a")("bc"), Err(Err::Error(("bc", ErrorKind::OneOf))));
-/// assert_eq!(one_of::<_, _, (_, ErrorKind)>("a")(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(one_of::<_, _, (_, ErrorKind)>("a")(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn one_of<I, T, Error: ParseError<I>>(list: T) -> impl Fn(I) -> IResult<I, char, Error>
 where
@@ -64,7 +94,7 @@
   T: FindToken<<I as InputIter>::Item>,
 {
   move |i: I| match (i).iter_elements().next().map(|c| (c, list.find_token(c))) {
-    None => Err(Err::Incomplete(Needed::Size(1))),
+    None => Err(Err::Incomplete(Needed::new(1))),
     Some((_, false)) => Err(Err::Error(Error::from_error_kind(i, ErrorKind::OneOf))),
     Some((c, true)) => Ok((i.slice(c.len()..), c.as_char())),
   }
@@ -72,18 +102,15 @@
 
 /// Recognizes a character that is not in the provided characters.
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
-///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::character::streaming::none_of;
-/// # fn main() {
 /// assert_eq!(none_of::<_, _, (_, ErrorKind)>("abc")("z"), Ok(("", 'z')));
 /// assert_eq!(none_of::<_, _, (_, ErrorKind)>("ab")("a"), Err(Err::Error(("a", ErrorKind::NoneOf))));
-/// assert_eq!(none_of::<_, _, (_, ErrorKind)>("a")(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(none_of::<_, _, (_, ErrorKind)>("a")(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn none_of<I, T, Error: ParseError<I>>(list: T) -> impl Fn(I) -> IResult<I, char, Error>
 where
@@ -92,7 +119,7 @@
   T: FindToken<<I as InputIter>::Item>,
 {
   move |i: I| match (i).iter_elements().next().map(|c| (c, !list.find_token(c))) {
-    None => Err(Err::Incomplete(Needed::Size(1))),
+    None => Err(Err::Incomplete(Needed::new(1))),
     Some((_, false)) => Err(Err::Error(Error::from_error_kind(i, ErrorKind::NoneOf))),
     Some((c, true)) => Ok((i.slice(c.len()..), c.as_char())),
   }
@@ -100,18 +127,15 @@
 
 /// Recognizes the string "\r\n".
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
-///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::crlf;
-/// # fn main() {
 /// assert_eq!(crlf::<_, (_, ErrorKind)>("\r\nc"), Ok(("c", "\r\n")));
 /// assert_eq!(crlf::<_, (_, ErrorKind)>("ab\r\nc"), Err(Err::Error(("ab\r\nc", ErrorKind::CrLf))));
-/// assert_eq!(crlf::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(2))));
-/// # }
+/// assert_eq!(crlf::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(2))));
 /// ```
 pub fn crlf<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -122,7 +146,7 @@
   match input.compare("\r\n") {
     //FIXME: is this the right index?
     CompareResult::Ok => Ok((input.slice(2..), input.slice(0..2))),
-    CompareResult::Incomplete => Err(Err::Incomplete(Needed::Size(2))),
+    CompareResult::Incomplete => Err(Err::Incomplete(Needed::new(2))),
     CompareResult::Error => {
       let e: ErrorKind = ErrorKind::CrLf;
       Err(Err::Error(E::from_error_kind(input, e)))
@@ -130,20 +154,19 @@
   }
 }
 
-/// Recognizes a string of any char except '\r' or '\n'.
+/// Recognizes a string of any char except '\r\n' or '\n'.
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
-///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
 /// # Example
 ///
 /// ```
-/// # use nom::{Err, error::ErrorKind, IResult, Needed};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult, Needed};
 /// # use nom::character::streaming::not_line_ending;
-/// # fn main() {
 /// assert_eq!(not_line_ending::<_, (_, ErrorKind)>("ab\r\nc"), Ok(("\r\nc", "ab")));
 /// assert_eq!(not_line_ending::<_, (_, ErrorKind)>("abc"), Err(Err::Incomplete(Needed::Unknown)));
 /// assert_eq!(not_line_ending::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Unknown)));
-/// # }
+/// assert_eq!(not_line_ending::<_, (_, ErrorKind)>("a\rb\nc"), Err(Err::Error(("a\rb\nc", ErrorKind::Tag ))));
+/// assert_eq!(not_line_ending::<_, (_, ErrorKind)>("a\rbc"), Err(Err::Error(("a\rbc", ErrorKind::Tag ))));
 /// ```
 pub fn not_line_ending<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -157,9 +180,7 @@
     let c = item.as_char();
     c == '\r' || c == '\n'
   }) {
-    None => {
-      Err(Err::Incomplete(Needed::Unknown))
-    }
+    None => Err(Err::Incomplete(Needed::Unknown)),
     Some(index) => {
       let mut it = input.slice(index..).iter_elements();
       let nth = it.next().unwrap().as_char();
@@ -184,18 +205,15 @@
 
 /// Recognizes an end of line (both '\n' and '\r\n').
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
-///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::line_ending;
-/// # fn main() {
 /// assert_eq!(line_ending::<_, (_, ErrorKind)>("\r\nc"), Ok(("c", "\r\n")));
 /// assert_eq!(line_ending::<_, (_, ErrorKind)>("ab\r\nc"), Err(Err::Error(("ab\r\nc", ErrorKind::CrLf))));
-/// assert_eq!(line_ending::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(line_ending::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn line_ending<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -205,12 +223,12 @@
 {
   match input.compare("\n") {
     CompareResult::Ok => Ok((input.slice(1..), input.slice(0..1))),
-    CompareResult::Incomplete => Err(Err::Incomplete(Needed::Size(1))),
+    CompareResult::Incomplete => Err(Err::Incomplete(Needed::new(1))),
     CompareResult::Error => {
       match input.compare("\r\n") {
         //FIXME: is this the right index?
         CompareResult::Ok => Ok((input.slice(2..), input.slice(0..2))),
-        CompareResult::Incomplete => Err(Err::Incomplete(Needed::Size(2))),
+        CompareResult::Incomplete => Err(Err::Incomplete(Needed::new(2))),
         CompareResult::Error => Err(Err::Error(E::from_error_kind(input, ErrorKind::CrLf))),
       }
     }
@@ -219,22 +237,19 @@
 
 /// Matches a newline character '\\n'.
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
-///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::newline;
-/// # fn main() {
 /// assert_eq!(newline::<_, (_, ErrorKind)>("\nc"), Ok(("c", '\n')));
 /// assert_eq!(newline::<_, (_, ErrorKind)>("\r\nc"), Err(Err::Error(("\r\nc", ErrorKind::Char))));
-/// assert_eq!(newline::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(newline::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn newline<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>
 where
-  I: Slice<RangeFrom<usize>> + InputIter,
+  I: Slice<RangeFrom<usize>> + InputIter + InputLength,
   <I as InputIter>::Item: AsChar,
 {
   char('\n')(input)
@@ -242,22 +257,19 @@
 
 /// Matches a tab character '\t'.
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
-///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::tab;
-/// # fn main() {
 /// assert_eq!(tab::<_, (_, ErrorKind)>("\tc"), Ok(("c", '\t')));
 /// assert_eq!(tab::<_, (_, ErrorKind)>("\r\nc"), Err(Err::Error(("\r\nc", ErrorKind::Char))));
-/// assert_eq!(tab::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(tab::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn tab<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>
 where
-  I: Slice<RangeFrom<usize>> + InputIter,
+  I: Slice<RangeFrom<usize>> + InputIter + InputLength,
   <I as InputIter>::Item: AsChar,
 {
   char('\t')(input)
@@ -266,16 +278,13 @@
 /// Matches one byte as a character. Note that the input type will
 /// accept a `str`, but not a `&[u8]`, unlike many other nom parsers.
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
-///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data.
 /// # Example
 ///
 /// ```
 /// # use nom::{character::streaming::anychar, Err, error::ErrorKind, IResult, Needed};
-/// # fn main() {
 /// assert_eq!(anychar::<_, (_, ErrorKind)>("abc"), Ok(("bc",'a')));
-/// assert_eq!(anychar::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(anychar::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn anychar<T, E: ParseError<T>>(input: T) -> IResult<T, char, E>
 where
@@ -284,7 +293,7 @@
 {
   let mut it = input.iter_indices();
   match it.next() {
-    None => Err(Err::Incomplete(Needed::Size(1))),
+    None => Err(Err::Incomplete(Needed::new(1))),
     Some((_, c)) => match it.next() {
       None => Ok((input.slice(input.input_len()..), c.as_char())),
       Some((idx, _)) => Ok((input.slice(idx..), c.as_char())),
@@ -294,19 +303,16 @@
 
 /// Recognizes zero or more lowercase and uppercase ASCII alphabetic characters: a-z, A-Z
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non alphabetic character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::alpha0;
-/// # fn main() {
 /// assert_eq!(alpha0::<_, (_, ErrorKind)>("ab1c"), Ok(("1c", "ab")));
 /// assert_eq!(alpha0::<_, (_, ErrorKind)>("1c"), Ok(("1c", "")));
-/// assert_eq!(alpha0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(alpha0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn alpha0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -318,19 +324,16 @@
 
 /// Recognizes one or more lowercase and uppercase ASCII alphabetic characters: a-z, A-Z
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non alphabetic character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::alpha1;
-/// # fn main() {
 /// assert_eq!(alpha1::<_, (_, ErrorKind)>("aB1c"), Ok(("1c", "aB")));
 /// assert_eq!(alpha1::<_, (_, ErrorKind)>("1c"), Err(Err::Error(("1c", ErrorKind::Alpha))));
-/// assert_eq!(alpha1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(alpha1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn alpha1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -342,19 +345,16 @@
 
 /// Recognizes zero or more ASCII numerical characters: 0-9
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non digit character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::digit0;
-/// # fn main() {
 /// assert_eq!(digit0::<_, (_, ErrorKind)>("21c"), Ok(("c", "21")));
 /// assert_eq!(digit0::<_, (_, ErrorKind)>("a21c"), Ok(("a21c", "")));
-/// assert_eq!(digit0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(digit0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn digit0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -366,19 +366,16 @@
 
 /// Recognizes one or more ASCII numerical characters: 0-9
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non digit character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::digit1;
-/// # fn main() {
 /// assert_eq!(digit1::<_, (_, ErrorKind)>("21c"), Ok(("c", "21")));
 /// assert_eq!(digit1::<_, (_, ErrorKind)>("c1"), Err(Err::Error(("c1", ErrorKind::Digit))));
-/// assert_eq!(digit1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(digit1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn digit1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -390,19 +387,16 @@
 
 /// Recognizes zero or more ASCII hexadecimal numerical characters: 0-9, A-F, a-f
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non hexadecimal digit character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::hex_digit0;
-/// # fn main() {
 /// assert_eq!(hex_digit0::<_, (_, ErrorKind)>("21cZ"), Ok(("Z", "21c")));
 /// assert_eq!(hex_digit0::<_, (_, ErrorKind)>("Z21c"), Ok(("Z21c", "")));
-/// assert_eq!(hex_digit0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(hex_digit0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn hex_digit0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -414,19 +408,16 @@
 
 /// Recognizes one or more ASCII hexadecimal numerical characters: 0-9, A-F, a-f
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non hexadecimal digit character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::hex_digit1;
-/// # fn main() {
 /// assert_eq!(hex_digit1::<_, (_, ErrorKind)>("21cZ"), Ok(("Z", "21c")));
 /// assert_eq!(hex_digit1::<_, (_, ErrorKind)>("H2"), Err(Err::Error(("H2", ErrorKind::HexDigit))));
-/// assert_eq!(hex_digit1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(hex_digit1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn hex_digit1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -438,19 +429,16 @@
 
 /// Recognizes zero or more octal characters: 0-7
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non octal digit character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::oct_digit0;
-/// # fn main() {
 /// assert_eq!(oct_digit0::<_, (_, ErrorKind)>("21cZ"), Ok(("cZ", "21")));
 /// assert_eq!(oct_digit0::<_, (_, ErrorKind)>("Z21c"), Ok(("Z21c", "")));
-/// assert_eq!(oct_digit0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(oct_digit0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn oct_digit0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -462,19 +450,16 @@
 
 /// Recognizes one or more octal characters: 0-7
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non octal digit character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::oct_digit1;
-/// # fn main() {
 /// assert_eq!(oct_digit1::<_, (_, ErrorKind)>("21cZ"), Ok(("cZ", "21")));
 /// assert_eq!(oct_digit1::<_, (_, ErrorKind)>("H2"), Err(Err::Error(("H2", ErrorKind::OctDigit))));
-/// assert_eq!(oct_digit1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(oct_digit1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn oct_digit1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -486,19 +471,16 @@
 
 /// Recognizes zero or more ASCII numerical and alphabetic characters: 0-9, a-z, A-Z
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non alphanumerical character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::alphanumeric0;
-/// # fn main() {
 /// assert_eq!(alphanumeric0::<_, (_, ErrorKind)>("21cZ%1"), Ok(("%1", "21cZ")));
 /// assert_eq!(alphanumeric0::<_, (_, ErrorKind)>("&Z21c"), Ok(("&Z21c", "")));
-/// assert_eq!(alphanumeric0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(alphanumeric0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn alphanumeric0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -510,19 +492,16 @@
 
 /// Recognizes one or more ASCII numerical and alphabetic characters: 0-9, a-z, A-Z
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non alphanumerical character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::alphanumeric1;
-/// # fn main() {
 /// assert_eq!(alphanumeric1::<_, (_, ErrorKind)>("21cZ%1"), Ok(("%1", "21cZ")));
 /// assert_eq!(alphanumeric1::<_, (_, ErrorKind)>("&H2"), Err(Err::Error(("&H2", ErrorKind::AlphaNumeric))));
-/// assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn alphanumeric1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -534,19 +513,16 @@
 
 /// Recognizes zero or more spaces and tabs.
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non space character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::space0;
-/// # fn main() {
 /// assert_eq!(space0::<_, (_, ErrorKind)>(" \t21c"), Ok(("21c", " \t")));
 /// assert_eq!(space0::<_, (_, ErrorKind)>("Z21c"), Ok(("Z21c", "")));
-/// assert_eq!(space0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(space0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn space0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -554,25 +530,22 @@
   <T as InputTakeAtPosition>::Item: AsChar + Clone,
 {
   input.split_at_position(|item| {
-    let c = item.clone().as_char();
+    let c = item.as_char();
     !(c == ' ' || c == '\t')
   })
 }
 /// Recognizes one or more spaces and tabs.
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non space character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::space1;
-/// # fn main() {
 /// assert_eq!(space1::<_, (_, ErrorKind)>(" \t21c"), Ok(("21c", " \t")));
 /// assert_eq!(space1::<_, (_, ErrorKind)>("H2"), Err(Err::Error(("H2", ErrorKind::Space))));
-/// assert_eq!(space1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(space1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn space1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -581,7 +554,7 @@
 {
   input.split_at_position1(
     |item| {
-      let c = item.clone().as_char();
+      let c = item.as_char();
       !(c == ' ' || c == '\t')
     },
     ErrorKind::Space,
@@ -590,19 +563,16 @@
 
 /// Recognizes zero or more spaces, tabs, carriage returns and line feeds.
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non space character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::multispace0;
-/// # fn main() {
 /// assert_eq!(multispace0::<_, (_, ErrorKind)>(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
 /// assert_eq!(multispace0::<_, (_, ErrorKind)>("Z21c"), Ok(("Z21c", "")));
-/// assert_eq!(multispace0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(multispace0::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn multispace0<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -610,26 +580,23 @@
   <T as InputTakeAtPosition>::Item: AsChar + Clone,
 {
   input.split_at_position(|item| {
-    let c = item.clone().as_char();
+    let c = item.as_char();
     !(c == ' ' || c == '\t' || c == '\r' || c == '\n')
   })
 }
 
 /// Recognizes one or more spaces, tabs, carriage returns and line feeds.
 ///
-/// *streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there's not enough input data,
 /// or if no terminating token is found (a non space character).
-///
 /// # Example
 ///
 /// ```
 /// # use nom::{Err, error::ErrorKind, IResult, Needed};
 /// # use nom::character::streaming::multispace1;
-/// # fn main() {
 /// assert_eq!(multispace1::<_, (_, ErrorKind)>(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
 /// assert_eq!(multispace1::<_, (_, ErrorKind)>("H2"), Err(Err::Error(("H2", ErrorKind::MultiSpace))));
-/// assert_eq!(multispace1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::Size(1))));
-/// # }
+/// assert_eq!(multispace1::<_, (_, ErrorKind)>(""), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 pub fn multispace1<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
@@ -638,18 +605,143 @@
 {
   input.split_at_position1(
     |item| {
-      let c = item.clone().as_char();
+      let c = item.as_char();
       !(c == ' ' || c == '\t' || c == '\r' || c == '\n')
     },
     ErrorKind::MultiSpace,
   )
 }
 
+pub(crate) fn sign<T, E: ParseError<T>>(input: T) -> IResult<T, bool, E>
+where
+  T: Clone + InputTake + InputLength,
+  T: for<'a> Compare<&'a [u8]>,
+{
+  use crate::bytes::streaming::tag;
+  use crate::combinator::value;
+
+  let (i, opt_sign) = opt(alt((
+    value(false, tag(&b"-"[..])),
+    value(true, tag(&b"+"[..])),
+  )))(input)?;
+  let sign = opt_sign.unwrap_or(true);
+
+  Ok((i, sign))
+}
+
+#[doc(hidden)]
+macro_rules! ints {
+    ($($t:tt)+) => {
+        $(
+        /// will parse a number in text form to a number
+        ///
+        /// *Complete version*: can parse until the end of input.
+        pub fn $t<T, E: ParseError<T>>(input: T) -> IResult<T, $t, E>
+            where
+            T: InputIter + Slice<RangeFrom<usize>> + InputLength + InputTake + Clone,
+            <T as InputIter>::Item: AsChar,
+            T: for <'a> Compare<&'a[u8]>,
+            {
+              let (i, sign) = sign(input.clone())?;
+
+                if i.input_len() == 0 {
+                    return Err(Err::Incomplete(Needed::new(1)));
+                }
+
+                let mut value: $t = 0;
+                if sign {
+                    for (pos, c) in i.iter_indices() {
+                        match c.as_char().to_digit(10) {
+                            None => {
+                                if pos == 0 {
+                                    return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit)));
+                                } else {
+                                    return Ok((i.slice(pos..), value));
+                                }
+                            },
+                            Some(d) => match value.checked_mul(10).and_then(|v| v.checked_add(d as $t)) {
+                                None => return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit))),
+                                Some(v) => value = v,
+                            }
+                        }
+                    }
+                } else {
+                    for (pos, c) in i.iter_indices() {
+                        match c.as_char().to_digit(10) {
+                            None => {
+                                if pos == 0 {
+                                    return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit)));
+                                } else {
+                                    return Ok((i.slice(pos..), value));
+                                }
+                            },
+                            Some(d) => match value.checked_mul(10).and_then(|v| v.checked_sub(d as $t)) {
+                                None => return Err(Err::Error(E::from_error_kind(input, ErrorKind::Digit))),
+                                Some(v) => value = v,
+                            }
+                        }
+                    }
+                }
+
+                Err(Err::Incomplete(Needed::new(1)))
+            }
+        )+
+    }
+}
+
+ints! { i8 i16 i32 i64 i128 }
+
+#[doc(hidden)]
+macro_rules! uints {
+    ($($t:tt)+) => {
+        $(
+        /// will parse a number in text form to a number
+        ///
+        /// *Complete version*: can parse until the end of input.
+        pub fn $t<T, E: ParseError<T>>(input: T) -> IResult<T, $t, E>
+            where
+            T: InputIter + Slice<RangeFrom<usize>> + InputLength,
+            <T as InputIter>::Item: AsChar,
+            {
+                let i = input;
+
+                if i.input_len() == 0 {
+                    return Err(Err::Incomplete(Needed::new(1)));
+                }
+
+                let mut value: $t = 0;
+                for (pos, c) in i.iter_indices() {
+                    match c.as_char().to_digit(10) {
+                        None => {
+                            if pos == 0 {
+                                return Err(Err::Error(E::from_error_kind(i, ErrorKind::Digit)));
+                            } else {
+                                return Ok((i.slice(pos..), value));
+                            }
+                        },
+                        Some(d) => match value.checked_mul(10).and_then(|v| v.checked_add(d as $t)) {
+                            None => return Err(Err::Error(E::from_error_kind(i, ErrorKind::Digit))),
+                            Some(v) => value = v,
+                        }
+                    }
+                }
+
+                Err(Err::Incomplete(Needed::new(1)))
+            }
+        )+
+    }
+}
+
+uints! { u8 u16 u32 u64 u128 }
+
 #[cfg(test)]
 mod tests {
   use super::*;
-  use crate::internal::{Err, Needed};
   use crate::error::ErrorKind;
+  use crate::internal::{Err, Needed};
+  use crate::sequence::pair;
+  use crate::traits::ParseTo;
+  use proptest::prelude::*;
 
   macro_rules! assert_parse(
     ($left: expr, $right: expr) => {
@@ -672,53 +764,62 @@
     let d: &[u8] = "azé12".as_bytes();
     let e: &[u8] = b" ";
     let f: &[u8] = b" ;";
-    //assert_eq!(alpha1::<_, (_, ErrorKind)>(a), Err(Err::Incomplete(Needed::Size(1))));
-    assert_parse!(alpha1(a), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(
-      alpha1(b),
-      Err(Err::Error((b, ErrorKind::Alpha)))
-    );
+    //assert_eq!(alpha1::<_, (_, ErrorKind)>(a), Err(Err::Incomplete(Needed::new(1))));
+    assert_parse!(alpha1(a), Err(Err::Incomplete(Needed::new(1))));
+    assert_eq!(alpha1(b), Err(Err::Error((b, ErrorKind::Alpha))));
     assert_eq!(alpha1::<_, (_, ErrorKind)>(c), Ok((&c[1..], &b"a"[..])));
-    assert_eq!(alpha1::<_, (_, ErrorKind)>(d), Ok(("é12".as_bytes(), &b"az"[..])));
     assert_eq!(
-      digit1(a),
-      Err(Err::Error((a, ErrorKind::Digit)))
+      alpha1::<_, (_, ErrorKind)>(d),
+      Ok(("é12".as_bytes(), &b"az"[..]))
     );
-    assert_eq!(digit1::<_, (_, ErrorKind)>(b), Err(Err::Incomplete(Needed::Size(1))));
+    assert_eq!(digit1(a), Err(Err::Error((a, ErrorKind::Digit))));
     assert_eq!(
-      digit1(c),
-      Err(Err::Error((c, ErrorKind::Digit)))
+      digit1::<_, (_, ErrorKind)>(b),
+      Err(Err::Incomplete(Needed::new(1)))
+    );
+    assert_eq!(digit1(c), Err(Err::Error((c, ErrorKind::Digit))));
+    assert_eq!(digit1(d), Err(Err::Error((d, ErrorKind::Digit))));
+    assert_eq!(
+      hex_digit1::<_, (_, ErrorKind)>(a),
+      Err(Err::Incomplete(Needed::new(1)))
     );
     assert_eq!(
-      digit1(d),
-      Err(Err::Error((d, ErrorKind::Digit)))
-    );
-    assert_eq!(hex_digit1::<_, (_, ErrorKind)>(a), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(hex_digit1::<_, (_, ErrorKind)>(b), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(hex_digit1::<_, (_, ErrorKind)>(c), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(hex_digit1::<_, (_, ErrorKind)>(d), Ok(("zé12".as_bytes(), &b"a"[..])));
-    assert_eq!(
-      hex_digit1(e),
-      Err(Err::Error((e, ErrorKind::HexDigit)))
+      hex_digit1::<_, (_, ErrorKind)>(b),
+      Err(Err::Incomplete(Needed::new(1)))
     );
     assert_eq!(
-      oct_digit1(a),
-      Err(Err::Error((a, ErrorKind::OctDigit)))
-    );
-    assert_eq!(oct_digit1::<_, (_, ErrorKind)>(b), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(
-      oct_digit1(c),
-      Err(Err::Error((c, ErrorKind::OctDigit)))
+      hex_digit1::<_, (_, ErrorKind)>(c),
+      Err(Err::Incomplete(Needed::new(1)))
     );
     assert_eq!(
-      oct_digit1(d),
-      Err(Err::Error((d, ErrorKind::OctDigit)))
+      hex_digit1::<_, (_, ErrorKind)>(d),
+      Ok(("zé12".as_bytes(), &b"a"[..]))
     );
-    assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(a), Err(Err::Incomplete(Needed::Size(1))));
+    assert_eq!(hex_digit1(e), Err(Err::Error((e, ErrorKind::HexDigit))));
+    assert_eq!(oct_digit1(a), Err(Err::Error((a, ErrorKind::OctDigit))));
+    assert_eq!(
+      oct_digit1::<_, (_, ErrorKind)>(b),
+      Err(Err::Incomplete(Needed::new(1)))
+    );
+    assert_eq!(oct_digit1(c), Err(Err::Error((c, ErrorKind::OctDigit))));
+    assert_eq!(oct_digit1(d), Err(Err::Error((d, ErrorKind::OctDigit))));
+    assert_eq!(
+      alphanumeric1::<_, (_, ErrorKind)>(a),
+      Err(Err::Incomplete(Needed::new(1)))
+    );
     //assert_eq!(fix_error!(b,(), alphanumeric1), Ok((empty, b)));
-    assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(c), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(d), Ok(("é12".as_bytes(), &b"az"[..])));
-    assert_eq!(space1::<_, (_, ErrorKind)>(e), Err(Err::Incomplete(Needed::Size(1))));
+    assert_eq!(
+      alphanumeric1::<_, (_, ErrorKind)>(c),
+      Err(Err::Incomplete(Needed::new(1)))
+    );
+    assert_eq!(
+      alphanumeric1::<_, (_, ErrorKind)>(d),
+      Ok(("é12".as_bytes(), &b"az"[..]))
+    );
+    assert_eq!(
+      space1::<_, (_, ErrorKind)>(e),
+      Err(Err::Incomplete(Needed::new(1)))
+    );
     assert_eq!(space1::<_, (_, ErrorKind)>(f), Ok((&b";"[..], &b" "[..])));
   }
 
@@ -730,52 +831,55 @@
     let c = "a123";
     let d = "azé12";
     let e = " ";
-    assert_eq!(alpha1::<_, (_, ErrorKind)>(a), Err(Err::Incomplete(Needed::Size(1))));
     assert_eq!(
-      alpha1(b),
-      Err(Err::Error((b, ErrorKind::Alpha)))
+      alpha1::<_, (_, ErrorKind)>(a),
+      Err(Err::Incomplete(Needed::new(1)))
     );
+    assert_eq!(alpha1(b), Err(Err::Error((b, ErrorKind::Alpha))));
     assert_eq!(alpha1::<_, (_, ErrorKind)>(c), Ok((&c[1..], &"a"[..])));
     assert_eq!(alpha1::<_, (_, ErrorKind)>(d), Ok(("é12", &"az"[..])));
+    assert_eq!(digit1(a), Err(Err::Error((a, ErrorKind::Digit))));
     assert_eq!(
-      digit1(a),
-      Err(Err::Error((a, ErrorKind::Digit)))
+      digit1::<_, (_, ErrorKind)>(b),
+      Err(Err::Incomplete(Needed::new(1)))
     );
-    assert_eq!(digit1::<_, (_, ErrorKind)>(b), Err(Err::Incomplete(Needed::Size(1))));
+    assert_eq!(digit1(c), Err(Err::Error((c, ErrorKind::Digit))));
+    assert_eq!(digit1(d), Err(Err::Error((d, ErrorKind::Digit))));
     assert_eq!(
-      digit1(c),
-      Err(Err::Error((c, ErrorKind::Digit)))
+      hex_digit1::<_, (_, ErrorKind)>(a),
+      Err(Err::Incomplete(Needed::new(1)))
     );
     assert_eq!(
-      digit1(d),
-      Err(Err::Error((d, ErrorKind::Digit)))
+      hex_digit1::<_, (_, ErrorKind)>(b),
+      Err(Err::Incomplete(Needed::new(1)))
     );
-    assert_eq!(hex_digit1::<_, (_, ErrorKind)>(a), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(hex_digit1::<_, (_, ErrorKind)>(b), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(hex_digit1::<_, (_, ErrorKind)>(c), Err(Err::Incomplete(Needed::Size(1))));
+    assert_eq!(
+      hex_digit1::<_, (_, ErrorKind)>(c),
+      Err(Err::Incomplete(Needed::new(1)))
+    );
     assert_eq!(hex_digit1::<_, (_, ErrorKind)>(d), Ok(("zé12", &"a"[..])));
+    assert_eq!(hex_digit1(e), Err(Err::Error((e, ErrorKind::HexDigit))));
+    assert_eq!(oct_digit1(a), Err(Err::Error((a, ErrorKind::OctDigit))));
     assert_eq!(
-      hex_digit1(e),
-      Err(Err::Error((e, ErrorKind::HexDigit)))
+      oct_digit1::<_, (_, ErrorKind)>(b),
+      Err(Err::Incomplete(Needed::new(1)))
     );
+    assert_eq!(oct_digit1(c), Err(Err::Error((c, ErrorKind::OctDigit))));
+    assert_eq!(oct_digit1(d), Err(Err::Error((d, ErrorKind::OctDigit))));
     assert_eq!(
-      oct_digit1(a),
-      Err(Err::Error((a, ErrorKind::OctDigit)))
+      alphanumeric1::<_, (_, ErrorKind)>(a),
+      Err(Err::Incomplete(Needed::new(1)))
     );
-    assert_eq!(oct_digit1::<_, (_, ErrorKind)>(b), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(
-      oct_digit1(c),
-      Err(Err::Error((c, ErrorKind::OctDigit)))
-    );
-    assert_eq!(
-      oct_digit1(d),
-      Err(Err::Error((d, ErrorKind::OctDigit)))
-    );
-    assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(a), Err(Err::Incomplete(Needed::Size(1))));
     //assert_eq!(fix_error!(b,(), alphanumeric1), Ok((empty, b)));
-    assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(c), Err(Err::Incomplete(Needed::Size(1))));
+    assert_eq!(
+      alphanumeric1::<_, (_, ErrorKind)>(c),
+      Err(Err::Incomplete(Needed::new(1)))
+    );
     assert_eq!(alphanumeric1::<_, (_, ErrorKind)>(d), Ok(("é12", "az")));
-    assert_eq!(space1::<_, (_, ErrorKind)>(e), Err(Err::Incomplete(Needed::Size(1))));
+    assert_eq!(
+      space1::<_, (_, ErrorKind)>(e),
+      Err(Err::Incomplete(Needed::new(1)))
+    );
   }
 
   use crate::traits::Offset;
@@ -835,7 +939,10 @@
   #[test]
   fn is_not_line_ending_bytes() {
     let a: &[u8] = b"ab12cd\nefgh";
-    assert_eq!(not_line_ending::<_, (_, ErrorKind)>(a), Ok((&b"\nefgh"[..], &b"ab12cd"[..])));
+    assert_eq!(
+      not_line_ending::<_, (_, ErrorKind)>(a),
+      Ok((&b"\nefgh"[..], &b"ab12cd"[..]))
+    );
 
     let b: &[u8] = b"ab12cd\nefgh\nijkl";
     assert_eq!(
@@ -850,7 +957,10 @@
     );
 
     let d: &[u8] = b"ab12cd";
-    assert_eq!(not_line_ending::<_, (_, ErrorKind)>(d), Err(Err::Incomplete(Needed::Unknown)));
+    assert_eq!(
+      not_line_ending::<_, (_, ErrorKind)>(d),
+      Err(Err::Incomplete(Needed::Unknown))
+    );
   }
 
   #[test]
@@ -873,13 +983,13 @@
     */
 
     let f = "βèƒôřè\rÂßÇáƒƭèř";
-    assert_eq!(
-      not_line_ending(f),
-      Err(Err::Error((f, ErrorKind::Tag)))
-    );
+    assert_eq!(not_line_ending(f), Err(Err::Error((f, ErrorKind::Tag))));
 
     let g2: &str = "ab12cd";
-    assert_eq!(not_line_ending::<_, (_, ErrorKind)>(g2), Err(Err::Incomplete(Needed::Unknown)));
+    assert_eq!(
+      not_line_ending::<_, (_, ErrorKind)>(g2),
+      Err(Err::Incomplete(Needed::Unknown))
+    );
   }
 
   #[test]
@@ -938,10 +1048,9 @@
 
   #[test]
   fn full_line_windows() {
-    named!(
-      take_full_line<(&[u8], &[u8])>,
-      tuple!(not_line_ending, line_ending)
-    );
+    fn take_full_line(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
+      pair(not_line_ending, line_ending)(i)
+    }
     let input = b"abc\r\n";
     let output = take_full_line(input);
     assert_eq!(output, Ok((&b""[..], (&b"abc"[..], &b"\r\n"[..]))));
@@ -949,10 +1058,9 @@
 
   #[test]
   fn full_line_unix() {
-    named!(
-      take_full_line<(&[u8], &[u8])>,
-      tuple!(not_line_ending, line_ending)
-    );
+    fn take_full_line(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
+      pair(not_line_ending, line_ending)(i)
+    }
     let input = b"abc\n";
     let output = take_full_line(input);
     assert_eq!(output, Ok((&b""[..], (&b"abc"[..], &b"\n"[..]))));
@@ -975,14 +1083,14 @@
   #[test]
   fn cr_lf() {
     assert_parse!(crlf(&b"\r\na"[..]), Ok((&b"a"[..], &b"\r\n"[..])));
-    assert_parse!(crlf(&b"\r"[..]), Err(Err::Incomplete(Needed::Size(2))));
+    assert_parse!(crlf(&b"\r"[..]), Err(Err::Incomplete(Needed::new(2))));
     assert_parse!(
       crlf(&b"\ra"[..]),
       Err(Err::Error(error_position!(&b"\ra"[..], ErrorKind::CrLf)))
     );
 
     assert_parse!(crlf("\r\na"), Ok(("a", "\r\n")));
-    assert_parse!(crlf("\r"), Err(Err::Incomplete(Needed::Size(2))));
+    assert_parse!(crlf("\r"), Err(Err::Incomplete(Needed::new(2))));
     assert_parse!(
       crlf("\ra"),
       Err(Err::Error(error_position!("\ra", ErrorKind::CrLf)))
@@ -993,7 +1101,10 @@
   fn end_of_line() {
     assert_parse!(line_ending(&b"\na"[..]), Ok((&b"a"[..], &b"\n"[..])));
     assert_parse!(line_ending(&b"\r\na"[..]), Ok((&b"a"[..], &b"\r\n"[..])));
-    assert_parse!(line_ending(&b"\r"[..]), Err(Err::Incomplete(Needed::Size(2))));
+    assert_parse!(
+      line_ending(&b"\r"[..]),
+      Err(Err::Incomplete(Needed::new(2)))
+    );
     assert_parse!(
       line_ending(&b"\ra"[..]),
       Err(Err::Error(error_position!(&b"\ra"[..], ErrorKind::CrLf)))
@@ -1001,10 +1112,71 @@
 
     assert_parse!(line_ending("\na"), Ok(("a", "\n")));
     assert_parse!(line_ending("\r\na"), Ok(("a", "\r\n")));
-    assert_parse!(line_ending("\r"), Err(Err::Incomplete(Needed::Size(2))));
+    assert_parse!(line_ending("\r"), Err(Err::Incomplete(Needed::new(2))));
     assert_parse!(
       line_ending("\ra"),
       Err(Err::Error(error_position!("\ra", ErrorKind::CrLf)))
     );
   }
+
+  fn digit_to_i16(input: &str) -> IResult<&str, i16> {
+    let i = input;
+    let (i, opt_sign) = opt(alt((char('+'), char('-'))))(i)?;
+    let sign = match opt_sign {
+      Some('+') => true,
+      Some('-') => false,
+      _ => true,
+    };
+
+    let (i, s) = match digit1::<_, crate::error::Error<_>>(i) {
+      Ok((i, s)) => (i, s),
+      Err(Err::Incomplete(i)) => return Err(Err::Incomplete(i)),
+      Err(_) => {
+        return Err(Err::Error(crate::error::Error::from_error_kind(
+          input,
+          ErrorKind::Digit,
+        )))
+      }
+    };
+    match s.parse_to() {
+      Some(n) => {
+        if sign {
+          Ok((i, n))
+        } else {
+          Ok((i, -n))
+        }
+      }
+      None => Err(Err::Error(crate::error::Error::from_error_kind(
+        i,
+        ErrorKind::Digit,
+      ))),
+    }
+  }
+
+  fn digit_to_u32(i: &str) -> IResult<&str, u32> {
+    let (i, s) = digit1(i)?;
+    match s.parse_to() {
+      Some(n) => Ok((i, n)),
+      None => Err(Err::Error(crate::error::Error::from_error_kind(
+        i,
+        ErrorKind::Digit,
+      ))),
+    }
+  }
+
+  proptest! {
+    #[test]
+    fn ints(s in "\\PC*") {
+        let res1 = digit_to_i16(&s);
+        let res2 = i16(s.as_str());
+        assert_eq!(res1, res2);
+    }
+
+    #[test]
+    fn uints(s in "\\PC*") {
+        let res1 = digit_to_u32(&s);
+        let res2 = u32(s.as_str());
+        assert_eq!(res1, res2);
+    }
+  }
 }
diff --git a/src/character/tests.rs b/src/character/tests.rs
new file mode 100644
index 0000000..64c2a1c
--- /dev/null
+++ b/src/character/tests.rs
@@ -0,0 +1,62 @@
+use super::streaming::*;
+use crate::error::ErrorKind;
+use crate::internal::{Err, IResult};
+
+#[test]
+fn one_of_test() {
+  fn f(i: &[u8]) -> IResult<&[u8], char> {
+    one_of("ab")(i)
+  }
+
+  let a = &b"abcd"[..];
+  assert_eq!(f(a), Ok((&b"bcd"[..], 'a')));
+
+  let b = &b"cde"[..];
+  assert_eq!(f(b), Err(Err::Error(error_position!(b, ErrorKind::OneOf))));
+
+  fn utf8(i: &str) -> IResult<&str, char> {
+    one_of("+\u{FF0B}")(i)
+  }
+
+  assert!(utf8("+").is_ok());
+  assert!(utf8("\u{FF0B}").is_ok());
+}
+
+#[test]
+fn none_of_test() {
+  fn f(i: &[u8]) -> IResult<&[u8], char> {
+    none_of("ab")(i)
+  }
+
+  let a = &b"abcd"[..];
+  assert_eq!(f(a), Err(Err::Error(error_position!(a, ErrorKind::NoneOf))));
+
+  let b = &b"cde"[..];
+  assert_eq!(f(b), Ok((&b"de"[..], 'c')));
+}
+
+#[test]
+fn char_byteslice() {
+  fn f(i: &[u8]) -> IResult<&[u8], char> {
+    char('c')(i)
+  }
+
+  let a = &b"abcd"[..];
+  assert_eq!(f(a), Err(Err::Error(error_position!(a, ErrorKind::Char))));
+
+  let b = &b"cde"[..];
+  assert_eq!(f(b), Ok((&b"de"[..], 'c')));
+}
+
+#[test]
+fn char_str() {
+  fn f(i: &str) -> IResult<&str, char> {
+    char('c')(i)
+  }
+
+  let a = &"abcd"[..];
+  assert_eq!(f(a), Err(Err::Error(error_position!(a, ErrorKind::Char))));
+
+  let b = &"cde"[..];
+  assert_eq!(f(b), Ok((&"de"[..], 'c')));
+}
diff --git a/src/combinator/macros.rs b/src/combinator/macros.rs
deleted file mode 100644
index 59df06f..0000000
--- a/src/combinator/macros.rs
+++ /dev/null
@@ -1,1201 +0,0 @@
-//! Macro combinators
-//!
-//! Macros are used to make combination easier,
-//! since they often do not depend on the type
-//! of the data they manipulate or return.
-//!
-//! There is a trick to make them easier to assemble,
-//! combinators are defined like this:
-//!
-//! ```ignore
-//! macro_rules! tag (
-//!   ($i:expr, $inp: expr) => (
-//!     {
-//!       ...
-//!     }
-//!   );
-//! );
-//! ```
-//!
-//! But when used in other combinators, are Used
-//! like this:
-//!
-//! ```ignore
-//! named!(my_function, tag!("abcd"));
-//! ```
-//!
-//! Internally, other combinators will rewrite
-//! that call to pass the input as first argument:
-//!
-//! ```ignore
-//! macro_rules! named (
-//!   ($name:ident, $submac:ident!( $($args:tt)* )) => (
-//!     fn $name<'a>( i: &'a [u8] ) -> IResult<'a,&[u8], &[u8]> {
-//!       $submac!(i, $($args)*)
-//!     }
-//!   );
-//! );
-//! ```
-//!
-//! If you want to call a combinator directly, you can
-//! do it like this:
-//!
-//! ```ignore
-//! let res = { tag!(input, "abcd"); }
-//! ```
-//!
-//! Combinators must have a specific variant for
-//! non-macro arguments. Example: passing a function
-//! to take_while! instead of another combinator.
-//!
-//! ```ignore
-//! macro_rules! take_while(
-//!   ($input:expr, $submac:ident!( $($args:tt)* )) => (
-//!     {
-//!       ...
-//!     }
-//!   );
-//!
-//!   // wrap the function in a macro to pass it to the main implementation
-//!   ($input:expr, $f:expr) => (
-//!     take_while!($input, call!($f));
-//!   );
-//! );
-//! ```
-#[allow(unused_variables)]
-
-/// Makes a function from a parser combination
-///
-/// The type can be set up if the compiler needs
-/// more information
-///
-/// Function-like declaration:
-/// ```
-/// # use nom::{named, tag};
-/// named!(my_function( &[u8] ) -> &[u8], tag!("abcd"));
-/// ```
-/// Alternative declaration. First type parameter is input, second is output:
-/// ```
-/// # use nom::{named, tag};
-/// named!(my_function<&[u8], &[u8]>, tag!("abcd"));
-/// ```
-/// This one will have `&[u8]` as input type, `&[u8]` as output type:
-/// ```
-/// # use nom::{named, tag};
-/// named!(my_function, tag!("abcd"));
-/// ```
-/// Will use `&[u8]` as output type:
-/// ```
-/// # use nom::{named, tag};
-/// named!(my_function<&[u8]>, tag!("abcd"));
-/// ```
-/// Prefix them with 'pub' to make the functions public:
-/// ```
-/// # use nom::{named, tag};
-/// named!(pub my_function, tag!("abcd"));
-/// ```
-/// Prefix them with 'pub(crate)' to make the functions public within the crate:
-/// ```
-/// # use nom::{named, tag};
-/// named!(pub(crate) my_function, tag!("abcd"));
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! named (
-    (#$($args:tt)*) => (
-        named_attr!(#$($args)*);
-    );
-    ($vis:vis $name:ident( $i:ty ) -> $o:ty, $submac:ident!( $($args:tt)* )) => (
-        $vis fn $name( i: $i ) -> $crate::IResult<$i, $o, ($i, $crate::error::ErrorKind)> {
-            $submac!(i, $($args)*)
-        }
-    );
-    ($vis:vis $name:ident<$i:ty,$o:ty,$e:ty>, $submac:ident!( $($args:tt)* )) => (
-        $vis fn $name( i: $i ) -> $crate::IResult<$i, $o, $e> {
-            $submac!(i, $($args)*)
-        }
-    );
-    ($vis:vis $name:ident<$i:ty,$o:ty>, $submac:ident!( $($args:tt)* )) => (
-        $vis fn $name( i: $i ) -> $crate::IResult<$i, $o, ($i, $crate::error::ErrorKind)> {
-            $submac!(i, $($args)*)
-        }
-    );
-    ($vis:vis $name:ident<$o:ty>, $submac:ident!( $($args:tt)* )) => (
-        $vis fn $name( i: &[u8] ) -> $crate::IResult<&[u8], $o, (&[u8], $crate::error::ErrorKind)> {
-            $submac!(i, $($args)*)
-        }
-    );
-    ($vis:vis $name:ident, $submac:ident!( $($args:tt)* )) => (
-        $vis fn $name( i: &[u8] ) -> $crate::IResult<&[u8], &[u8], (&[u8], $crate::error::ErrorKind)> {
-            $submac!(i, $($args)*)
-        }
-    );
-);
-
-/// Makes a function from a parser combination with arguments.
-///
-/// ```ignore
-/// //takes [`&[u8]`] as input
-/// named_args!(tagged(open_tag: &[u8], close_tag: &[u8])<&str>,
-///   delimited!(tag!(open_tag), map_res!(take!(4), str::from_utf8), tag!(close_tag))
-/// );
-
-/// //takes `&str` as input
-/// named_args!(tagged(open_tag: &str, close_tag: &str)<&str, &str>,
-///   delimited!(tag!(open_tag), take!(4), tag!(close_tag))
-/// );
-/// ```
-///
-/// Note: if using arguments that way gets hard to read, it is always
-/// possible to write the equivalent parser definition manually, like
-/// this:
-///
-/// ```ignore
-/// fn tagged(input: &[u8], open_tag: &[u8], close_tag: &[u8]) -> IResult<&[u8], &str> {
-///   // the first combinator in the tree gets the input as argument. It is then
-///   // passed from one combinator to the next through macro rewriting
-///   delimited!(input,
-///     tag!(open_tag), take!(4), tag!(close_tag)
-///   )
-/// );
-/// ```
-///
-#[macro_export(local_inner_macros)]
-macro_rules! named_args {
-    ($vis:vis $func_name:ident ( $( $arg:ident : $typ:ty ),* ) < $return_type:ty > , $submac:ident!( $($args:tt)* ) ) => {
-        $vis fn $func_name(input: &[u8], $( $arg : $typ ),*) -> $crate::IResult<&[u8], $return_type> {
-            $submac!(input, $($args)*)
-        }
-    };
-
-    ($vis:vis $func_name:ident < 'a > ( $( $arg:ident : $typ:ty ),* ) < $return_type:ty > , $submac:ident!( $($args:tt)* ) ) => {
-        $vis fn $func_name<'this_is_probably_unique_i_hope_please, 'a>(
-          input: &'this_is_probably_unique_i_hope_please [u8], $( $arg : $typ ),*) ->
-          $crate::IResult<&'this_is_probably_unique_i_hope_please [u8], $return_type>
-        {
-          $submac!(input, $($args)*)
-        }
-    };
-
-    ($vis:vis $func_name:ident ( $( $arg:ident : $typ:ty ),* ) < $input_type:ty, $return_type:ty > , $submac:ident!( $($args:tt)* ) ) => {
-        $vis fn $func_name(input: $input_type, $( $arg : $typ ),*) -> $crate::IResult<$input_type, $return_type> {
-            $submac!(input, $($args)*)
-        }
-    };
-
-    ($vis:vis $func_name:ident < 'a > ( $( $arg:ident : $typ:ty ),* ) < $input_type:ty, $return_type:ty > , $submac:ident!( $($args:tt)* ) ) => {
-        $vis fn $func_name<'a>(
-          input: $input_type, $( $arg : $typ ),*)
-          -> $crate::IResult<$input_type, $return_type>
-        {
-            $submac!(input, $($args)*)
-        }
-    };
-}
-
-/// Makes a function from a parser combination, with attributes
-///
-/// The usage of this macro is almost identical to `named!`, except that
-/// you also pass attributes to be attached to the generated function.
-/// This is ideal for adding documentation to your parser.
-///
-/// Create my_function as if you wrote it with the doc comment /// My Func:
-/// ```
-/// # use nom::{named_attr, tag};
-/// named_attr!(#[doc = "My Func"], my_function( &[u8] ) -> &[u8], tag!("abcd"));
-/// ```
-/// Also works for pub functions, and multiple lines:
-/// ```
-/// # use nom::{named_attr, tag};
-/// named_attr!(#[doc = "My Func\nRecognise abcd"], pub my_function, tag!("abcd"));
-/// ```
-/// Multiple attributes can be passed if required:
-/// ```
-/// # use nom::{named_attr, tag};
-/// named_attr!(#[doc = "My Func"] #[inline(always)], pub my_function, tag!("abcd"));
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! named_attr (
-    ($(#[$attr:meta])*, $vis:vis $name:ident( $i:ty ) -> $o:ty, $submac:ident!( $($args:tt)* )) => (
-        $(#[$attr])*
-        $vis fn $name( i: $i ) -> $crate::IResult<$i,$o, ($i, $crate::error::ErrorKind)> {
-            $submac!(i, $($args)*)
-        }
-    );
-    ($(#[$attr:meta])*, $vis:vis $name:ident<$i:ty,$o:ty,$e:ty>, $submac:ident!( $($args:tt)* )) => (
-        $(#[$attr])*
-        $vis fn $name( i: $i ) -> $crate::IResult<$i, $o, $e> {
-            $submac!(i, $($args)*)
-        }
-    );
-    ($(#[$attr:meta])*, $vis:vis $name:ident<$i:ty,$o:ty>, $submac:ident!( $($args:tt)* )) => (
-        $(#[$attr])*
-        $vis fn $name( i: $i ) -> $crate::IResult<$i, $o, ($i, $crate::error::ErrorKind)> {
-            $submac!(i, $($args)*)
-        }
-    );
-    ($(#[$attr:meta])*, $vis:vis $name:ident<$o:ty>, $submac:ident!( $($args:tt)* )) => (
-        $(#[$attr])*
-        $vis fn $name( i: &[u8] ) -> $crate::IResult<&[u8], $o, (&[u8], $crate::error::ErrorKind)> {
-            $submac!(i, $($args)*)
-        }
-    );
-    ($(#[$attr:meta])*, $vis:vis $name:ident, $submac:ident!( $($args:tt)* )) => (
-        $(#[$attr])*
-        $vis fn $name<'a>( i: &'a [u8] ) -> $crate::IResult<&[u8], &[u8], (&[u8], $crate::error::ErrorKind)> {
-            $submac!(i, $($args)*)
-        }
-    );
-);
-
-/// Used to wrap common expressions and function as macros
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::IResult;
-/// # fn main() {
-///   fn take_wrapper(input: &[u8], i: u8) -> IResult<&[u8], &[u8]> { take!(input, i * 10) }
-///
-///   // will make a parser taking 20 bytes
-///   named!(parser, call!(take_wrapper, 2));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! call (
-  ($i:expr, $fun:expr) => ( $fun( $i ) );
-  ($i:expr, $fun:expr, $($args:expr),* ) => ( $fun( $i, $($args),* ) );
-);
-
-//FIXME: error rewrite
-/// Prevents backtracking if the child parser fails
-///
-/// This parser will do an early return instead of sending
-/// its result to the parent parser.
-///
-/// If another `return_error!` combinator is present in the parent
-/// chain, the error will be wrapped and another early
-/// return will be made.
-///
-/// This makes it easy to build report on which parser failed,
-/// where it failed in the input, and the chain of parsers
-/// that led it there.
-///
-/// Additionally, the error chain contains number identifiers
-/// that can be matched to provide useful error messages.
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-///     named!(err_test<&[u8], &[u8]>, alt!(
-///       tag!("abcd") |
-///       preceded!(tag!("efgh"), return_error!(ErrorKind::Eof,
-///           do_parse!(
-///                  tag!("ijkl")                                        >>
-///             res: return_error!(ErrorKind::Tag, tag!("mnop")) >>
-///             (res)
-///           )
-///         )
-///       )
-///     ));
-///     let a = &b"efghblah"[..];
-///     let b = &b"efghijklblah"[..];
-///     let c = &b"efghijklmnop"[..];
-///
-///     let blah = &b"blah"[..];
-///
-///     let res_a = err_test(a);
-///     let res_b = err_test(b);
-///     let res_c = err_test(c);
-///     assert_eq!(res_a, Err(Err::Failure(error_node_position!(blah, ErrorKind::Eof, error_position!(blah, ErrorKind::Tag)))));
-///     assert_eq!(res_b, Err(Err::Failure(error_node_position!(&b"ijklblah"[..], ErrorKind::Eof,
-///       error_node_position!(blah, ErrorKind::Tag, error_position!(blah, ErrorKind::Tag))))
-///     ));
-/// # }
-/// ```
-///
-#[macro_export(local_inner_macros)]
-macro_rules! return_error (
-  ($i:expr, $code:expr, $submac:ident!( $($args:tt)* )) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::Err;
-
-      let i_ = $i.clone();
-      let cl = || {
-        $submac!(i_, $($args)*)
-      };
-
-      match cl() {
-        Err(Err::Incomplete(x)) => Err(Err::Incomplete(x)),
-        Ok((i, o))              => Ok((i, o)),
-        Err(Err::Error(e)) | Err(Err::Failure(e)) => {
-          return Err(Err::Failure($crate::error::append_error($i, $code, e)))
-        }
-      }
-    }
-  );
-  ($i:expr, $code:expr, $f:expr) => (
-    return_error!($i, $code, call!($f));
-  );
-  ($i:expr, $submac:ident!( $($args:tt)* )) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::Err;
-
-      let i_ = $i.clone();
-      let cl = || {
-        $submac!(i_, $($args)*)
-      };
-
-      match cl() {
-        Err(Err::Incomplete(x)) => Err(Err::Incomplete(x)),
-        Ok((i, o))              => Ok((i, o)),
-        Err(Err::Error(e)) | Err(Err::Failure(e)) => {
-          return Err(Err::Failure(e))
-        }
-      }
-    }
-  );
-  ($i:expr, $f:expr) => (
-    return_error!($i, call!($f));
-  );
-);
-
-//FIXME: error rewrite
-/// Add an error if the child parser fails
-///
-/// While `return_error!` does an early return and avoids backtracking,
-/// add_return_error! backtracks normally. It just provides more context
-/// for an error
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use std::collections;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-///     named!(err_test, add_return_error!(ErrorKind::Tag, tag!("abcd")));
-///
-///     let a = &b"efghblah"[..];
-///     let res_a = err_test(a);
-///     assert_eq!(res_a, Err(Err::Error(error_node_position!(a, ErrorKind::Tag, error_position!(a, ErrorKind::Tag)))));
-/// # }
-/// ```
-///
-#[macro_export(local_inner_macros)]
-macro_rules! add_return_error (
-  ($i:expr, $code:expr, $submac:ident!( $($args:tt)* )) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind};
-
-      match $submac!($i, $($args)*) {
-        Ok((i, o)) => Ok((i, o)),
-        Err(Err::Error(e)) => {
-          Err(Err::Error(error_node_position!($i, $code, e)))
-        },
-        Err(Err::Failure(e)) => {
-          Err(Err::Failure(error_node_position!($i, $code, e)))
-        },
-        Err(e) => Err(e),
-      }
-    }
-  );
-  ($i:expr, $code:expr, $f:expr) => (
-    add_return_error!($i, $code, call!($f));
-  );
-);
-
-/// replaces a `Incomplete` returned by the child parser
-/// with an `Error`
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use std::collections;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-///     named!(take_5, complete!(take!(5)));
-///
-///     let a = &b"abcd"[..];
-///     let res_a = take_5(a);
-///     assert_eq!(res_a, Err(Err::Error(error_position!(a, ErrorKind::Complete))));
-/// # }
-/// ```
-///
-#[macro_export(local_inner_macros)]
-macro_rules! complete (
-  ($i:expr, $submac:ident!( $($args:tt)* )) => (
-    $crate::combinator::completec($i, move |i| { $submac!(i, $($args)*) })
-  );
-  ($i:expr, $f:expr) => (
-    complete!($i, call!($f));
-  );
-);
-
-/// A bit like `std::try!`, this macro will return the remaining input and
-/// parsed value if the child parser returned `Ok`, and will do an early
-/// return for the `Err` side.
-///
-/// this can provide more flexibility than `do_parse!` if needed
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # use nom::IResult;
-///
-///  fn take_add(input:&[u8], size: u8) -> IResult<&[u8], &[u8]> {
-///    let (i1, length)     = try_parse!(input, map_opt!(nom::number::streaming::be_u8, |sz| size.checked_add(sz)));
-///    let (i2, data)   = try_parse!(i1, take!(length));
-///    return Ok((i2, data));
-///  }
-/// # fn main() {
-/// let arr1 = [1, 2, 3, 4, 5];
-/// let r1 = take_add(&arr1[..], 1);
-/// assert_eq!(r1, Ok((&[4,5][..], &[2,3][..])));
-///
-/// let arr2 = [0xFE, 2, 3, 4, 5];
-/// // size is overflowing
-/// let r1 = take_add(&arr2[..], 42);
-/// assert_eq!(r1, Err(Err::Error(error_position!(&[254, 2,3,4,5][..], ErrorKind::MapOpt))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! try_parse (
-  ($i:expr, $submac:ident!( $($args:tt)* )) => ({
-    use $crate::lib::std::result::Result::*;
-
-    match $submac!($i, $($args)*) {
-      Ok((i,o)) => (i,o),
-      Err(e)    => return Err(e),
-    }
-    });
-  ($i:expr, $f:expr) => (
-    try_parse!($i, call!($f))
-  );
-);
-
-/// `map!(I -> IResult<I, O>, O -> P) => I -> IResult<I, P>`
-///
-/// maps a function on the result of a parser
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,error::ErrorKind, IResult};
-/// use nom::character::complete::digit1;
-/// # fn main() {
-///
-/// named!(parse<&str, usize>, map!(digit1, |s| s.len()));
-///
-/// // the parser will count how many characters were returned by digit1
-/// assert_eq!(parse("123456"), Ok(("", 6)));
-///
-/// // this will fail if digit1 fails
-/// assert_eq!(parse("abc"), Err(Err::Error(error_position!("abc", ErrorKind::Digit))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! map(
-  // Internal parser, do not use directly
-  (__impl $i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    $crate::combinator::mapc($i, move |i| {$submac!(i, $($args)*)}, $g)
-  );
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    map!(__impl $i, $submac!($($args)*), $g);
-  );
-  ($i:expr, $f:expr, $g:expr) => (
-    map!(__impl $i, call!($f), $g);
-  );
-);
-
-/// `map_res!(I -> IResult<I, O>, O -> Result<P>) => I -> IResult<I, P>`
-/// maps a function returning a Result on the output of a parser
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,error::ErrorKind, IResult};
-/// use nom::character::complete::digit1;
-/// # fn main() {
-///
-/// named!(parse<&str, u8>, map_res!(digit1, |s: &str| s.parse::<u8>()));
-///
-/// // the parser will convert the result of digit1 to a number
-/// assert_eq!(parse("123"), Ok(("", 123)));
-///
-/// // this will fail if digit1 fails
-/// assert_eq!(parse("abc"), Err(Err::Error(error_position!("abc", ErrorKind::Digit))));
-///
-/// // this will fail if the mapped function fails (a `u8` is too small to hold `123456`)
-/// assert_eq!(parse("123456"), Err(Err::Error(error_position!("123456", ErrorKind::MapRes))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! map_res (
-  // Internal parser, do not use directly
-  (__impl $i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    $crate::combinator::map_resc($i, move |i| {$submac!(i, $($args)*)}, move |i| {$submac2!(i, $($args2)*)})
-  );
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    map_res!(__impl $i, $submac!($($args)*), call!($g));
-  );
-  ($i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    map_res!(__impl $i, $submac!($($args)*), $submac2!($($args2)*));
-  );
-  ($i:expr, $f:expr, $g:expr) => (
-    map_res!(__impl $i, call!($f), call!($g));
-  );
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    map_res!(__impl $i, call!($f), $submac!($($args)*));
-  );
-);
-
-/// `map_opt!(I -> IResult<I, O>, O -> Option<P>) => I -> IResult<I, P>`
-/// maps a function returning an Option on the output of a parser
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,error::ErrorKind, IResult};
-/// use nom::character::complete::digit1;
-/// # fn main() {
-///
-/// named!(parser<&str, u8>, map_opt!(digit1, |s: &str| s.parse::<u8>().ok()));
-///
-/// // the parser will convert the result of digit1 to a number
-/// assert_eq!(parser("123"), Ok(("", 123)));
-///
-/// // this will fail if digit1 fails
-/// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Digit))));
-///
-/// // this will fail if the mapped function fails (a `u8` is too small to hold `123456`)
-/// assert_eq!(parser("123456"), Err(Err::Error(("123456", ErrorKind::MapOpt))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! map_opt (
-  // Internal parser, do not use directly
-  (__impl $i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    $crate::combinator::map_optc($i, move |i| {$submac!(i, $($args)*)}, move |i| {$submac2!(i, $($args2)*)})
-  );
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    map_opt!(__impl $i, $submac!($($args)*), call!($g));
-  );
-  ($i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    map_opt!(__impl $i, $submac!($($args)*), $submac2!($($args2)*));
-  );
-  ($i:expr, $f:expr, $g:expr) => (
-    map_opt!(__impl $i, call!($f), call!($g));
-  );
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    map_opt!(__impl $i, call!($f), $submac!($($args)*));
-  );
-);
-
-/// `parse_to!(O) => I -> IResult<I, O>`
-/// uses the `parse` method from `std::str::FromStr` to convert the current
-/// input to the specified type
-///
-/// this will completely consume the input
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,error::ErrorKind, IResult};
-/// use nom::character::complete::digit1;
-/// # fn main() {
-///
-/// named!(parser<&str, u8>, parse_to!(u8));
-///
-/// assert_eq!(parser("123"), Ok(("", 123)));
-///
-/// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::ParseTo))));
-///
-/// // this will fail if the mapped function fails (a `u8` is too small to hold `123456`)
-/// assert_eq!(parser("123456"), Err(Err::Error(("123456", ErrorKind::ParseTo))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! parse_to (
-  ($i:expr, $t:ty ) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::lib::std::option::Option;
-      use $crate::lib::std::option::Option::*;
-      use $crate::{Err,error::ErrorKind};
-
-      use $crate::ParseTo;
-      use $crate::Slice;
-      use $crate::InputLength;
-
-      let res: Option<$t> = ($i).parse_to();
-      match res {
-        Some(output) => Ok(($i.slice($i.input_len()..), output)),
-        None         => Err(Err::Error($crate::error::make_error($i, ErrorKind::ParseTo)))
-      }
-    }
-  );
-);
-
-/// `verify!(I -> IResult<I, O>, O -> bool) => I -> IResult<I, O>`
-/// returns the result of the child parser if it satisfies a verification function
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(check<u32>, verify!(nom::number::streaming::be_u32, |val: &u32| *val < 3));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! verify (
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    $crate::combinator::verifyc($i, |i| $submac!(i, $($args)*), $g)
-  );
-  ($i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    $crate::combinator::verifyc($i, |i| $submac!(i, $($args)*), |&o| $submac2!(o, $($args2)*))
-  );
-  ($i:expr, $f:expr, $g:expr) => (
-    $crate::combinator::verify($f, $g)($i)
-  );
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    $crate::combinator::verify($f, |&o| $submac!(o, $($args)*))($i)
-  );
-);
-
-/// `value!(T, R -> IResult<R, S> ) => R -> IResult<R, T>`
-///
-/// or `value!(T) => R -> IResult<R, T>`
-///
-/// If the child parser was successful, return the value.
-/// If no child parser is provided, always return the value
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(x<u8>, value!(42, delimited!(tag!("<!--"), take!(5), tag!("-->"))));
-///  named!(y<u8>, delimited!(tag!("<!--"), value!(42), tag!("-->")));
-///  let r = x(&b"<!-- abc --> aaa"[..]);
-///  assert_eq!(r, Ok((&b" aaa"[..], 42)));
-///
-///  let r2 = y(&b"<!----> aaa"[..]);
-///  assert_eq!(r2, Ok((&b" aaa"[..], 42)));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! value (
-  ($i:expr, $res:expr, $submac:ident!( $($args:tt)* )) => (
-    $crate::combinator::valuec($i, $res, |i| $submac!(i, $($args)*))
-  );
-  ($i:expr, $res:expr, $f:expr) => (
-    $crate::combinator::valuec($i, $res, $f)
-  );
-  ($i:expr, $res:expr) => (
-    Ok(($i, $res))
-  );
-);
-
-/// `opt!(I -> IResult<I,O>) => I -> IResult<I, Option<O>>`
-/// make the underlying parser optional
-///
-/// returns an Option of the returned type. This parser returns `Some(result)` if the child parser
-/// succeeds,`None` if it fails, and `Incomplete` if it did not have enough data to decide
-///
-/// *Warning*: if you are using `opt` for some kind of optional ending token (like an end of line),
-/// you should combine it with `complete` to make sure it works.
-///
-/// As an example, `opt!(tag!("\r\n"))` will return `Incomplete` if it receives an empty input,
-/// because `tag` does not have enough input to decide.
-/// On the contrary, `opt!(complete!(tag!("\r\n")))` would return `None` as produced value,
-/// since `complete!` transforms an `Incomplete` in an `Error`.
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!( o<&[u8], Option<&[u8]> >, opt!( tag!( "abcd" ) ) );
-///
-///  let a = b"abcdef";
-///  let b = b"bcdefg";
-///  assert_eq!(o(&a[..]), Ok((&b"ef"[..], Some(&b"abcd"[..]))));
-///  assert_eq!(o(&b[..]), Ok((&b"bcdefg"[..], None)));
-///  # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! opt(
-  ($i:expr, $submac:ident!( $($args:tt)* )) => (
-    {
-      $crate::combinator::optc($i, |i| $submac!(i, $($args)*))
-    }
-  );
-  ($i:expr, $f:expr) => (
-    $crate::combinator::opt($f)($i)
-  );
-);
-
-/// `opt_res!(I -> IResult<I,O>) => I -> IResult<I, Result<nom::Err,O>>`
-/// make the underlying parser optional
-///
-/// returns a Result, with Err containing the parsing error
-///
-/// ```ignore
-/// # #[macro_use] extern crate nom;
-/// # use nom::ErrorKind;
-/// # fn main() {
-///  named!( o<&[u8], Result<&[u8], nom::Err<&[u8]> > >, opt_res!( tag!( "abcd" ) ) );
-///
-///  let a = b"abcdef";
-///  let b = b"bcdefg";
-///  assert_eq!(o(&a[..]), Ok((&b"ef"[..], Ok(&b"abcd"[..])));
-///  assert_eq!(o(&b[..]), Ok((&b"bcdefg"[..], Err(error_position!(&b[..], ErrorKind::Tag))));
-///  # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! opt_res (
-  ($i:expr, $submac:ident!( $($args:tt)* )) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::Err;
-
-      let i_ = $i.clone();
-      match $submac!(i_, $($args)*) {
-        Ok((i,o))          => Ok((i,  Ok(o))),
-        Err(Err::Error(e)) => Ok(($i, Err(Err::Error(e)))),
-        // in case of failure, we return a real error
-        Err(e)             => Err(e)
-      }
-    }
-  );
-  ($i:expr, $f:expr) => (
-    opt_res!($i, call!($f));
-  );
-);
-
-/// `cond!(bool, I -> IResult<I,O>) => I -> IResult<I, Option<O>>`
-/// Conditional combinator
-///
-/// Wraps another parser and calls it if the
-/// condition is met. This combinator returns
-/// an Option of the return type of the child
-/// parser.
-///
-/// This is especially useful if a parser depends
-/// on the value returned by a preceding parser in
-/// a `do_parse!`.
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::IResult;
-/// # fn main() {
-///  fn f_true(i: &[u8]) -> IResult<&[u8], Option<&[u8]>> {
-///    cond!(i, true, tag!("abcd"))
-///  }
-///
-///  fn f_false(i: &[u8]) -> IResult<&[u8], Option<&[u8]>> {
-///    cond!(i, false, tag!("abcd"))
-///  }
-///
-///  let a = b"abcdef";
-///  assert_eq!(f_true(&a[..]), Ok((&b"ef"[..], Some(&b"abcd"[..]))));
-///
-///  assert_eq!(f_false(&a[..]), Ok((&b"abcdef"[..], None)));
-///  # }
-/// ```
-///
-#[macro_export(local_inner_macros)]
-macro_rules! cond(
-  ($i:expr, $cond:expr, $submac:ident!( $($args:tt)* )) => (
-    $crate::combinator::condc($i, $cond, |i|  $submac!(i, $($args)*) )
-  );
-  ($i:expr, $cond:expr, $f:expr) => (
-    $crate::combinator::cond($cond, $f)($i)
-  );
-);
-
-/// `peek!(I -> IResult<I,O>) => I -> IResult<I, O>`
-/// returns a result without consuming the input
-///
-/// the embedded parser may return Err(Err::Incomplete
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(ptag, peek!( tag!( "abcd" ) ) );
-///
-///  let r = ptag(&b"abcdefgh"[..]);
-///  assert_eq!(r, Ok((&b"abcdefgh"[..], &b"abcd"[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! peek(
-  ($i:expr, $submac:ident!( $($args:tt)* )) => (
-    $crate::combinator::peekc($i, |i| $submac!(i, $($args)*))
-  );
-  ($i:expr, $f:expr) => (
-    $crate::combinator::peek($f)($i)
-  );
-);
-
-/// `not!(I -> IResult<I,O>) => I -> IResult<I, ()>`
-/// returns a result only if the embedded parser returns Error or Err(Err::Incomplete)
-/// does not consume the input
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-/// named!(not_e, do_parse!(
-///     res: tag!("abc")      >>
-///          not!(char!('e')) >>
-///     (res)
-/// ));
-///
-/// let r = not_e(&b"abcd"[..]);
-/// assert_eq!(r, Ok((&b"d"[..], &b"abc"[..])));
-///
-/// let r2 = not_e(&b"abce"[..]);
-/// assert_eq!(r2, Err(Err::Error(error_position!(&b"e"[..], ErrorKind::Not))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! not(
-  ($i:expr, $submac:ident!( $($args:tt)* )) => (
-    $crate::combinator::notc($i, |i| $submac!(i, $($args)*))
-  );
-  ($i:expr, $f:expr) => (
-    $crate::combinator::not($f)($i)
-  );
-);
-
-/// `tap!(name: I -> IResult<I,O> => { block }) => I -> IResult<I, O>`
-/// allows access to the parser's result without affecting it
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use std::str;
-/// # fn main() {
-///  named!(ptag, tap!(res: tag!( "abcd" ) => { println!("recognized {}", str::from_utf8(res).unwrap()) } ) );
-///
-///  let r = ptag(&b"abcdefgh"[..]);
-///  assert_eq!(r, Ok((&b"efgh"[..], &b"abcd"[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! tap (
-  ($i:expr, $name:ident : $submac:ident!( $($args:tt)* ) => $e:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,Needed,IResult};
-
-      match $submac!($i, $($args)*) {
-        Ok((i,o)) => {
-          let $name = o;
-          $e;
-          Ok((i, $name))
-        },
-        Err(e)    => Err(Err::convert(e)),
-      }
-    }
-  );
-  ($i:expr, $name: ident: $f:expr => $e:expr) => (
-    tap!($i, $name: call!($f) => $e);
-  );
-);
-
-/// `eof!()` returns its input if it is at the end of input data
-///
-/// When we're at the end of the data, this combinator
-/// will succeed
-///
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use std::str;
-/// # use nom::{Err, error::ErrorKind};
-/// # fn main() {
-///  named!(parser, eof!());
-///
-///  assert_eq!(parser(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
-///  assert_eq!(parser(&b""[..]), Ok((&b""[..], &b""[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! eof (
-  ($i:expr,) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind};
-
-      use $crate::InputLength;
-      if ($i).input_len() == 0 {
-        Ok(($i, $i))
-      } else {
-        Err(Err::Error(error_position!($i, ErrorKind::Eof)))
-      }
-    }
-  );
-);
-
-/// `exact!()` will fail if the child parser does not consume the whole data
-///
-/// TODO: example
-#[macro_export(local_inner_macros)]
-macro_rules! exact (
-  ($i:expr, $submac:ident!( $($args:tt)* )) => ({
-      terminated!($i, $submac!( $($args)*), eof!())
-  });
-  ($i:expr, $f:expr) => (
-    exact!($i, call!($f));
-  );
-);
-
-/// `recognize!(I -> IResult<I, O> ) => I -> IResult<I, I>`
-/// if the child parser was successful, return the consumed input as produced value
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(x, recognize!(delimited!(tag!("<!--"), take!(5), tag!("-->"))));
-///  let r = x(&b"<!-- abc --> aaa"[..]);
-///  assert_eq!(r, Ok((&b" aaa"[..], &b"<!-- abc -->"[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! recognize (
-  ($i:expr, $submac:ident!( $($args:tt)* )) => (
-    $crate::combinator::recognizec($i, |i| $submac!(i, $($args)*))
-  );
-  ($i:expr, $f:expr) => (
-    $crate::combinator::recognize($f)($i)
-  );
-);
-
-#[cfg(test)]
-mod tests {
-  use crate::internal::{Err, IResult, Needed};
-  use crate::error::ParseError;
-  use crate::error::ErrorKind;
-  #[cfg(feature = "alloc")]
-  use crate::lib::std::boxed::Box;
-
-  // reproduce the tag and take macros, because of module import order
-  macro_rules! tag (
-    ($i:expr, $tag: expr) => ({
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,Needed,IResult,error::ErrorKind};
-      use $crate::{Compare,CompareResult,InputLength,Slice};
-
-      let res: IResult<_,_> = match ($i).compare($tag) {
-        CompareResult::Ok => {
-          let blen = $tag.input_len();
-          Ok(($i.slice(blen..), $i.slice(..blen)))
-        },
-        CompareResult::Incomplete => {
-          Err(Err::Incomplete(Needed::Size($tag.input_len())))
-        },
-        CompareResult::Error => {
-          let e:ErrorKind = ErrorKind::Tag;
-          Err(Err::Error($crate::error::make_error($i, e)))
-        }
-      };
-      res
-      });
-  );
-
-  macro_rules! take(
-    ($i:expr, $count:expr) => (
-      {
-        let cnt = $count as usize;
-        let res:IResult<&[u8],&[u8]> = if $i.len() < cnt {
-          Err($crate::Err::Incomplete($crate::Needed::Size(cnt)))
-        } else {
-          Ok((&$i[cnt..],&$i[0..cnt]))
-        };
-        res
-      }
-    );
-  );
-
-  mod pub_named_mod {
-    named!(pub tst, tag!("abcd"));
-  }
-
-  #[test]
-  fn pub_named_test() {
-    let a = &b"abcd"[..];
-    let res = pub_named_mod::tst(a);
-    assert_eq!(res, Ok((&b""[..], a)));
-  }
-
-  mod pub_crate_named_mod {
-    named!(pub(crate) tst, tag!("abcd"));
-  }
-
-  #[test]
-  fn pub_crate_named_test() {
-    let a = &b"abcd"[..];
-    let res = pub_crate_named_mod::tst(a);
-    assert_eq!(res, Ok((&b""[..], a)));
-  }
-
-  #[test]
-  fn apply_test() {
-    fn sum2(a: u8, b: u8) -> u8 {
-      a + b
-    }
-    fn sum3(a: u8, b: u8, c: u8) -> u8 {
-      a + b + c
-    }
-    let a = call!(1, sum2, 2);
-    let b = call!(1, sum3, 2, 3);
-
-    assert_eq!(a, 3);
-    assert_eq!(b, 6);
-  }
-
-  #[test]
-  fn opt() {
-    named!(opt_abcd<&[u8],Option<&[u8]> >, opt!(tag!("abcd")));
-
-    let a = &b"abcdef"[..];
-    let b = &b"bcdefg"[..];
-    let c = &b"ab"[..];
-    assert_eq!(opt_abcd(a), Ok((&b"ef"[..], Some(&b"abcd"[..]))));
-    assert_eq!(opt_abcd(b), Ok((&b"bcdefg"[..], None)));
-    assert_eq!(opt_abcd(c), Err(Err::Incomplete(Needed::Size(4))));
-  }
-
-  #[test]
-  fn opt_res() {
-    named!(opt_res_abcd<&[u8], Result<&[u8], Err<(&[u8], ErrorKind)>> >, opt_res!(tag!("abcd")));
-
-    let a = &b"abcdef"[..];
-    let b = &b"bcdefg"[..];
-    let c = &b"ab"[..];
-    assert_eq!(opt_res_abcd(a), Ok((&b"ef"[..], Ok(&b"abcd"[..]))));
-    assert_eq!(
-      opt_res_abcd(b),
-      Ok((
-        &b"bcdefg"[..],
-        Err(Err::Error(error_position!(b, ErrorKind::Tag)))
-      ))
-    );
-    assert_eq!(opt_res_abcd(c), Err(Err::Incomplete(Needed::Size(4))));
-  }
-
-  use crate::lib::std::convert::From;
-  #[derive(Debug, PartialEq)]
-  pub struct CustomError(&'static str);
-  impl<I> From<(I, ErrorKind)> for CustomError {
-    fn from(_: (I, ErrorKind)) -> Self {
-      CustomError("test")
-    }
-  }
-
-  impl<I> ParseError<I> for CustomError {
-    fn from_error_kind(_: I, _: ErrorKind) -> Self {
-      CustomError("from_error_kind")
-    }
-
-    fn append(_: I, _: ErrorKind, _: CustomError) -> Self {
-      CustomError("append")
-    }
-  }
-
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn cond() {
-    fn f_true(i: &[u8]) -> IResult<&[u8], Option<&[u8]>, CustomError> {
-      fix_error!(i, CustomError, cond!(true, tag!("abcd")))
-    }
-
-    fn f_false(i: &[u8]) -> IResult<&[u8], Option<&[u8]>, CustomError> {
-      fix_error!(i, CustomError, cond!(false, tag!("abcd")))
-    }
-
-    assert_eq!(f_true(&b"abcdef"[..]), Ok((&b"ef"[..], Some(&b"abcd"[..]))));
-    assert_eq!(f_true(&b"ab"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(f_true(&b"xxx"[..]), Err(Err::Error(CustomError("test"))));
-
-    assert_eq!(f_false(&b"abcdef"[..]), Ok((&b"abcdef"[..], None)));
-    assert_eq!(f_false(&b"ab"[..]), Ok((&b"ab"[..], None)));
-    assert_eq!(f_false(&b"xxx"[..]), Ok((&b"xxx"[..], None)));
-  }
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn cond_wrapping() {
-    // Test that cond!() will wrap a given identifier in the call!() macro.
-    named!(tag_abcd, tag!("abcd"));
-    fn f_true(i: &[u8]) -> IResult<&[u8], Option<&[u8]>, CustomError> {
-      fix_error!(i, CustomError, cond!(true, tag_abcd))
-    }
-
-    fn f_false(i: &[u8]) -> IResult<&[u8], Option<&[u8]>, CustomError> {
-      fix_error!(i, CustomError, cond!(false, tag_abcd))
-    }
-
-    assert_eq!(f_true(&b"abcdef"[..]), Ok((&b"ef"[..], Some(&b"abcd"[..]))));
-    assert_eq!(f_true(&b"ab"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(f_true(&b"xxx"[..]), Err(Err::Error(CustomError("test"))));
-
-    assert_eq!(f_false(&b"abcdef"[..]), Ok((&b"abcdef"[..], None)));
-    assert_eq!(f_false(&b"ab"[..]), Ok((&b"ab"[..], None)));
-    assert_eq!(f_false(&b"xxx"[..]), Ok((&b"xxx"[..], None)));
-  }
-
-  #[test]
-  fn peek() {
-    named!(peek_tag<&[u8],&[u8]>, peek!(tag!("abcd")));
-
-    assert_eq!(peek_tag(&b"abcdef"[..]), Ok((&b"abcdef"[..], &b"abcd"[..])));
-    assert_eq!(peek_tag(&b"ab"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(
-      peek_tag(&b"xxx"[..]),
-      Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
-    );
-  }
-
-  #[test]
-  fn not() {
-    named!(not_aaa<()>, not!(tag!("aaa")));
-    assert_eq!(
-      not_aaa(&b"aaa"[..]),
-      Err(Err::Error(error_position!(&b"aaa"[..], ErrorKind::Not)))
-    );
-    assert_eq!(not_aaa(&b"aa"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(not_aaa(&b"abcd"[..]), Ok((&b"abcd"[..], ())));
-  }
-
-  #[test]
-  fn verify() {
-    named!(test, verify!(take!(5), |slice: &[u8]| slice[0] == b'a'));
-    assert_eq!(test(&b"bcd"[..]), Err(Err::Incomplete(Needed::Size(5))));
-    assert_eq!(
-      test(&b"bcdefg"[..]),
-      Err(Err::Error(error_position!(
-        &b"bcdefg"[..],
-        ErrorKind::Verify
-      )))
-    );
-    assert_eq!(test(&b"abcdefg"[..]), Ok((&b"fg"[..], &b"abcde"[..])));
-  }
-
-  #[test]
-  fn parse_to() {
-    let res: IResult<_, _, (&str, ErrorKind)> = parse_to!("ab", usize);
-
-    assert_eq!(
-      res,
-      Err(Err::Error(error_position!(
-        "ab",
-        ErrorKind::ParseTo
-      )))
-    );
-
-    let res: IResult<_, _, (&str, ErrorKind)> = parse_to!("42", usize);
-
-    assert_eq!(res, Ok(("", 42)));
-    //assert_eq!(ErrorKind::convert(ErrorKind::ParseTo), ErrorKind::ParseTo::<u64>);
-  }
-
-}
diff --git a/src/combinator/mod.rs b/src/combinator/mod.rs
index 933bed8..7071cc7 100644
--- a/src/combinator/mod.rs
+++ b/src/combinator/mod.rs
@@ -1,25 +1,25 @@
-//! general purpose combinators
+//! General purpose combinators
 
 #![allow(unused_imports)]
 
 #[cfg(feature = "alloc")]
 use crate::lib::std::boxed::Box;
 
+use crate::error::{ErrorKind, FromExternalError, ParseError};
+use crate::internal::*;
+use crate::lib::std::borrow::Borrow;
+use crate::lib::std::convert::Into;
 #[cfg(feature = "std")]
 use crate::lib::std::fmt::Debug;
-use crate::internal::*;
-use crate::error::ParseError;
-use crate::traits::{AsChar, InputIter, InputLength, InputTakeAtPosition, ParseTo};
-use crate::lib::std::ops::{Range, RangeFrom, RangeTo};
-use crate::lib::std::borrow::Borrow;
-use crate::traits::{Compare, CompareResult, Offset, Slice};
-use crate::error::ErrorKind;
 use crate::lib::std::mem::transmute;
+use crate::lib::std::ops::{Range, RangeFrom, RangeTo};
+use crate::traits::{AsChar, InputIter, InputLength, InputTakeAtPosition, ParseTo};
+use crate::traits::{Compare, CompareResult, Offset, Slice};
 
-#[macro_use]
-mod macros;
+#[cfg(test)]
+mod tests;
 
-/// Return the remaining input
+/// Return the remaining input.
 ///
 /// ```rust
 /// # use nom::error::ErrorKind;
@@ -30,13 +30,13 @@
 #[inline]
 pub fn rest<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
 where
-  T: Slice<Range<usize>> + Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
+  T: Slice<RangeFrom<usize>>,
   T: InputLength,
 {
   Ok((input.slice(input.input_len()..), input))
 }
 
-/// Return the length of the remaining input
+/// Return the length of the remaining input.
 ///
 /// ```rust
 /// # use nom::error::ErrorKind;
@@ -47,61 +47,49 @@
 #[inline]
 pub fn rest_len<T, E: ParseError<T>>(input: T) -> IResult<T, usize, E>
 where
-  T: Slice<Range<usize>> + Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
   T: InputLength,
 {
   let len = input.input_len();
   Ok((input, len))
 }
 
-/// maps a function on the result of a parser
+/// Maps a function on the result of a parser.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,error::ErrorKind, IResult};
+/// use nom::{Err,error::ErrorKind, IResult,Parser};
 /// use nom::character::complete::digit1;
 /// use nom::combinator::map;
 /// # fn main() {
 ///
-/// let parse = map(digit1, |s: &str| s.len());
+/// let mut parser = map(digit1, |s: &str| s.len());
 ///
 /// // the parser will count how many characters were returned by digit1
-/// assert_eq!(parse("123456"), Ok(("", 6)));
+/// assert_eq!(parser.parse("123456"), Ok(("", 6)));
 ///
 /// // this will fail if digit1 fails
-/// assert_eq!(parse("abc"), Err(Err::Error(("abc", ErrorKind::Digit))));
+/// assert_eq!(parser.parse("abc"), Err(Err::Error(("abc", ErrorKind::Digit))));
 /// # }
 /// ```
-pub fn map<I, O1, O2, E: ParseError<I>, F, G>(first: F, second: G) -> impl Fn(I) -> IResult<I, O2, E>
+pub fn map<I, O1, O2, E, F, G>(mut parser: F, mut f: G) -> impl FnMut(I) -> IResult<I, O2, E>
 where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(O1) -> O2,
+  F: Parser<I, O1, E>,
+  G: FnMut(O1) -> O2,
 {
   move |input: I| {
-    let (input, o1) = first(input)?;
-    Ok((input, second(o1)))
+    let (input, o1) = parser.parse(input)?;
+    Ok((input, f(o1)))
   }
 }
 
-#[doc(hidden)]
-pub fn mapc<I, O1, O2, E: ParseError<I>, F, G>(input: I, first: F, second: G) -> IResult<I, O2, E>
-where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(O1) -> O2,
-{
-  map(first, second)(input)
-}
-
-/// applies a function returning a Result over the result of a parser
+/// Applies a function returning a `Result` over the result of a parser.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::character::complete::digit1;
 /// use nom::combinator::map_res;
 /// # fn main() {
 ///
-/// let parse = map_res(digit1, |s: &str| s.parse::<u8>());
+/// let mut parse = map_res(digit1, |s: &str| s.parse::<u8>());
 ///
 /// // the parser will convert the result of digit1 to a number
 /// assert_eq!(parse("123"), Ok(("", 123)));
@@ -113,40 +101,33 @@
 /// assert_eq!(parse("123456"), Err(Err::Error(("123456", ErrorKind::MapRes))));
 /// # }
 /// ```
-pub fn map_res<I: Clone, O1, O2, E: ParseError<I>, E2, F, G>(first: F, second: G) -> impl Fn(I) -> IResult<I, O2, E>
+pub fn map_res<I: Clone, O1, O2, E: FromExternalError<I, E2>, E2, F, G>(
+  mut parser: F,
+  mut f: G,
+) -> impl FnMut(I) -> IResult<I, O2, E>
 where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(O1) -> Result<O2, E2>,
+  F: Parser<I, O1, E>,
+  G: FnMut(O1) -> Result<O2, E2>,
 {
   move |input: I| {
     let i = input.clone();
-    let (input, o1) = first(input)?;
-    match second(o1) {
+    let (input, o1) = parser.parse(input)?;
+    match f(o1) {
       Ok(o2) => Ok((input, o2)),
-      Err(_) => Err(Err::Error(E::from_error_kind(i, ErrorKind::MapRes))),
+      Err(e) => Err(Err::Error(E::from_external_error(i, ErrorKind::MapRes, e))),
     }
   }
 }
 
-#[doc(hidden)]
-pub fn map_resc<I: Clone, O1, O2, E: ParseError<I>, E2, F, G>(input: I, first: F, second: G) -> IResult<I, O2, E>
-where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(O1) -> Result<O2, E2>,
-{
-  map_res(first, second)(input)
-}
-
-/// applies a function returning an Option over the result of a parser
+/// Applies a function returning an `Option` over the result of a parser.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::character::complete::digit1;
 /// use nom::combinator::map_opt;
 /// # fn main() {
 ///
-/// let parse = map_opt(digit1, |s: &str| s.parse::<u8>().ok());
+/// let mut parse = map_opt(digit1, |s: &str| s.parse::<u8>().ok());
 ///
 /// // the parser will convert the result of digit1 to a number
 /// assert_eq!(parse("123"), Ok(("", 123)));
@@ -158,102 +139,88 @@
 /// assert_eq!(parse("123456"), Err(Err::Error(("123456", ErrorKind::MapOpt))));
 /// # }
 /// ```
-pub fn map_opt<I: Clone, O1, O2, E: ParseError<I>, F, G>(first: F, second: G) -> impl Fn(I) -> IResult<I, O2, E>
+pub fn map_opt<I: Clone, O1, O2, E: ParseError<I>, F, G>(
+  mut parser: F,
+  mut f: G,
+) -> impl FnMut(I) -> IResult<I, O2, E>
 where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(O1) -> Option<O2>,
+  F: Parser<I, O1, E>,
+  G: FnMut(O1) -> Option<O2>,
 {
   move |input: I| {
     let i = input.clone();
-    let (input, o1) = first(input)?;
-    match second(o1) {
+    let (input, o1) = parser.parse(input)?;
+    match f(o1) {
       Some(o2) => Ok((input, o2)),
       None => Err(Err::Error(E::from_error_kind(i, ErrorKind::MapOpt))),
     }
   }
 }
 
-#[doc(hidden)]
-pub fn map_optc<I: Clone, O1, O2, E: ParseError<I>, F, G>(input: I, first: F, second: G) -> IResult<I, O2, E>
-where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(O1) -> Option<O2>,
-{
-  map_opt(first, second)(input)
-}
-
-/// applies a parser over the result of another one
+/// Applies a parser over the result of another one.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::character::complete::digit1;
 /// use nom::bytes::complete::take;
 /// use nom::combinator::map_parser;
 /// # fn main() {
 ///
-/// let parse = map_parser(take(5u8), digit1);
+/// let mut parse = map_parser(take(5u8), digit1);
 ///
 /// assert_eq!(parse("12345"), Ok(("", "12345")));
 /// assert_eq!(parse("123ab"), Ok(("", "123")));
 /// assert_eq!(parse("123"), Err(Err::Error(("123", ErrorKind::Eof))));
 /// # }
 /// ```
-pub fn map_parser<I: Clone, O1, O2, E: ParseError<I>, F, G>(first: F, second: G) -> impl Fn(I) -> IResult<I, O2, E>
+pub fn map_parser<I, O1, O2, E: ParseError<I>, F, G>(
+  mut parser: F,
+  mut applied_parser: G,
+) -> impl FnMut(I) -> IResult<I, O2, E>
 where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(O1) -> IResult<O1, O2, E>,
-  O1: InputLength,
+  F: Parser<I, O1, E>,
+  G: Parser<O1, O2, E>,
 {
   move |input: I| {
-    let (input, o1) = first(input)?;
-    let (_, o2) = second(o1)?;
+    let (input, o1) = parser.parse(input)?;
+    let (_, o2) = applied_parser.parse(o1)?;
     Ok((input, o2))
   }
 }
 
-#[doc(hidden)]
-pub fn map_parserc<I: Clone, O1, O2, E: ParseError<I>, F, G>(input: I, first: F, second: G) -> IResult<I, O2, E>
-where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(O1) -> IResult<O1, O2, E>,
-  O1: InputLength,
-{
-  map_parser(first, second)(input)
-}
-
-/// creates a new parser from the output of the first parser, then apply that parser over the rest of the input
+/// Creates a new parser from the output of the first parser, then apply that parser over the rest of the input.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::bytes::complete::take;
-/// use nom::number::complete::be_u8;
+/// use nom::number::complete::u8;
 /// use nom::combinator::flat_map;
 /// # fn main() {
 ///
-/// let parse = flat_map(be_u8, take);
+/// let mut parse = flat_map(u8, take);
 ///
 /// assert_eq!(parse(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..])));
 /// assert_eq!(parse(&[4, 0, 1, 2][..]), Err(Err::Error((&[0, 1, 2][..], ErrorKind::Eof))));
 /// # }
 /// ```
-pub fn flat_map<I, O1, O2, E: ParseError<I>, F, G, H>(first: F, second: G) -> impl Fn(I) -> IResult<I, O2, E>
+pub fn flat_map<I, O1, O2, E: ParseError<I>, F, G, H>(
+  mut parser: F,
+  mut applied_parser: G,
+) -> impl FnMut(I) -> IResult<I, O2, E>
 where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(O1) -> H,
-  H: Fn(I) -> IResult<I, O2, E>
+  F: Parser<I, O1, E>,
+  G: FnMut(O1) -> H,
+  H: Parser<I, O2, E>,
 {
   move |input: I| {
-    let (input, o1) = first(input)?;
-    second(o1)(input)
+    let (input, o1) = parser.parse(input)?;
+    applied_parser(o1).parse(input)
   }
 }
 
-/// optional parser: will return None if not successful
+/// Optional parser: Will return `None` if not successful.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::combinator::opt;
 /// use nom::character::complete::alpha1;
@@ -267,13 +234,13 @@
 /// assert_eq!(parser("123;"), Ok(("123;", None)));
 /// # }
 /// ```
-pub fn opt<I:Clone, O, E: ParseError<I>, F>(f: F) -> impl Fn(I) -> IResult<I, Option<O>, E>
+pub fn opt<I: Clone, O, E: ParseError<I>, F>(mut f: F) -> impl FnMut(I) -> IResult<I, Option<O>, E>
 where
-  F: Fn(I) -> IResult<I, O, E>,
+  F: Parser<I, O, E>,
 {
   move |input: I| {
     let i = input.clone();
-    match f(input) {
+    match f.parse(input) {
       Ok((i, o)) => Ok((i, Some(o))),
       Err(Err::Error(_)) => Ok((i, None)),
       Err(e) => Err(e),
@@ -281,19 +248,10 @@
   }
 }
 
-#[doc(hidden)]
-pub fn optc<I:Clone, O, E: ParseError<I>, F>(input: I, f: F) -> IResult<I, Option<O>, E>
-where
-  F: Fn(I) -> IResult<I, O, E>,
-{
-  opt(f)(input)
-}
-
-/// calls the parser if the condition is met
+/// Calls the parser if the condition is met.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,error::ErrorKind, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, IResult};
 /// use nom::combinator::cond;
 /// use nom::character::complete::alpha1;
 /// # fn main() {
@@ -304,17 +262,20 @@
 ///
 /// assert_eq!(parser(true, "abcd;"), Ok((";", Some("abcd"))));
 /// assert_eq!(parser(false, "abcd;"), Ok(("abcd;", None)));
-/// assert_eq!(parser(true, "123;"), Err(Err::Error(("123;", ErrorKind::Alpha))));
+/// assert_eq!(parser(true, "123;"), Err(Err::Error(Error::new("123;", ErrorKind::Alpha))));
 /// assert_eq!(parser(false, "123;"), Ok(("123;", None)));
 /// # }
 /// ```
-pub fn cond<I:Clone, O, E: ParseError<I>, F>(b: bool, f: F) -> impl Fn(I) -> IResult<I, Option<O>, E>
+pub fn cond<I, O, E: ParseError<I>, F>(
+  b: bool,
+  mut f: F,
+) -> impl FnMut(I) -> IResult<I, Option<O>, E>
 where
-  F: Fn(I) -> IResult<I, O, E>,
+  F: Parser<I, O, E>,
 {
   move |input: I| {
     if b {
-      match f(input) {
+      match f.parse(input) {
         Ok((i, o)) => Ok((i, Some(o))),
         Err(e) => Err(e),
       }
@@ -324,111 +285,107 @@
   }
 }
 
-#[doc(hidden)]
-pub fn condc<I:Clone, O, E: ParseError<I>, F>(input: I, b: bool, f: F) -> IResult<I, Option<O>, E>
-where
-  F: Fn(I) -> IResult<I, O, E>,
-{
-  cond(b, f)(input)
-}
-
-/// tries to apply its parser without consuming the input
+/// Tries to apply its parser without consuming the input.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::combinator::peek;
 /// use nom::character::complete::alpha1;
 /// # fn main() {
 ///
-/// let parser = peek(alpha1);
+/// let mut parser = peek(alpha1);
 ///
 /// assert_eq!(parser("abcd;"), Ok(("abcd;", "abcd")));
 /// assert_eq!(parser("123;"), Err(Err::Error(("123;", ErrorKind::Alpha))));
 /// # }
 /// ```
-pub fn peek<I:Clone, O, E: ParseError<I>, F>(f: F) -> impl Fn(I) -> IResult<I, O, E>
+pub fn peek<I: Clone, O, E: ParseError<I>, F>(mut f: F) -> impl FnMut(I) -> IResult<I, O, E>
 where
-  F: Fn(I) -> IResult<I, O, E>,
+  F: Parser<I, O, E>,
 {
   move |input: I| {
     let i = input.clone();
-    match f(input) {
+    match f.parse(input) {
       Ok((_, o)) => Ok((i, o)),
       Err(e) => Err(e),
     }
   }
 }
 
-#[doc(hidden)]
-pub fn peekc<I:Clone, O, E: ParseError<I>, F>(input: I, f: F) -> IResult<I, O, E>
-where
-  F: Fn(I) -> IResult<I, O, E>,
-{
-  peek(f)(input)
+/// returns its input if it is at the end of input data
+///
+/// When we're at the end of the data, this combinator
+/// will succeed
+///
+/// ```
+/// # use std::str;
+/// # use nom::{Err, error::ErrorKind, IResult};
+/// # use nom::combinator::eof;
+///
+/// # fn main() {
+/// let parser = eof;
+/// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Eof))));
+/// assert_eq!(parser(""), Ok(("", "")));
+/// # }
+/// ```
+pub fn eof<I: InputLength + Clone, E: ParseError<I>>(input: I) -> IResult<I, I, E> {
+  if input.input_len() == 0 {
+    let clone = input.clone();
+    Ok((input, clone))
+  } else {
+    Err(Err::Error(E::from_error_kind(input, ErrorKind::Eof)))
+  }
 }
 
-/// transforms Incomplete into Error
+/// Transforms Incomplete into `Error`.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::bytes::streaming::take;
 /// use nom::combinator::complete;
 /// # fn main() {
 ///
-/// let parser = complete(take(5u8));
+/// let mut parser = complete(take(5u8));
 ///
 /// assert_eq!(parser("abcdefg"), Ok(("fg", "abcde")));
 /// assert_eq!(parser("abcd"), Err(Err::Error(("abcd", ErrorKind::Complete))));
 /// # }
 /// ```
-pub fn complete<I: Clone, O, E: ParseError<I>, F>(f: F) -> impl Fn(I) -> IResult<I, O, E>
+pub fn complete<I: Clone, O, E: ParseError<I>, F>(mut f: F) -> impl FnMut(I) -> IResult<I, O, E>
 where
-  F: Fn(I) -> IResult<I, O, E>,
+  F: Parser<I, O, E>,
 {
   move |input: I| {
     let i = input.clone();
-    match f(input) {
-      Err(Err::Incomplete(_)) => {
-        Err(Err::Error(E::from_error_kind(i, ErrorKind::Complete)))
-      },
-      rest => rest
+    match f.parse(input) {
+      Err(Err::Incomplete(_)) => Err(Err::Error(E::from_error_kind(i, ErrorKind::Complete))),
+      rest => rest,
     }
   }
 }
 
-#[doc(hidden)]
-pub fn completec<I: Clone, O, E: ParseError<I>, F>(input: I, f: F) -> IResult<I, O, E>
-where
-  F: Fn(I) -> IResult<I, O, E>,
-{
-    complete(f)(input)
-}
-
-/// succeeds if all the input has been consumed by its child parser
+/// Succeeds if all the input has been consumed by its child parser.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::combinator::all_consuming;
 /// use nom::character::complete::alpha1;
 /// # fn main() {
 ///
-/// let parser = all_consuming(alpha1);
+/// let mut parser = all_consuming(alpha1);
 ///
 /// assert_eq!(parser("abcd"), Ok(("", "abcd")));
 /// assert_eq!(parser("abcd;"),Err(Err::Error((";", ErrorKind::Eof))));
 /// assert_eq!(parser("123abcd;"),Err(Err::Error(("123abcd;", ErrorKind::Alpha))));
 /// # }
 /// ```
-pub fn all_consuming<I, O, E: ParseError<I>, F>(f: F) -> impl Fn(I) -> IResult<I, O, E>
+pub fn all_consuming<I, O, E: ParseError<I>, F>(mut f: F) -> impl FnMut(I) -> IResult<I, O, E>
 where
   I: InputLength,
-  F: Fn(I) -> IResult<I, O, E>,
+  F: Parser<I, O, E>,
 {
   move |input: I| {
-    let (input, res) = f(input)?;
+    let (input, res) = f.parse(input)?;
     if input.input_len() == 0 {
       Ok((input, res))
     } else {
@@ -437,35 +394,37 @@
   }
 }
 
-/// returns the result of the child parser if it satisfies a verification function
+/// Returns the result of the child parser if it satisfies a verification function.
 ///
-/// the verification function takes as argument a reference to the output of the
-/// parser
+/// The verification function takes as argument a reference to the output of the
+/// parser.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::combinator::verify;
 /// use nom::character::complete::alpha1;
 /// # fn main() {
 ///
-/// let parser = verify(alpha1, |s: &str| s.len() == 4);
+/// let mut parser = verify(alpha1, |s: &str| s.len() == 4);
 ///
 /// assert_eq!(parser("abcd"), Ok(("", "abcd")));
 /// assert_eq!(parser("abcde"), Err(Err::Error(("abcde", ErrorKind::Verify))));
 /// assert_eq!(parser("123abcd;"),Err(Err::Error(("123abcd;", ErrorKind::Alpha))));
 /// # }
 /// ```
-pub fn verify<I: Clone, O1, O2, E: ParseError<I>, F, G>(first: F, second: G) -> impl Fn(I) -> IResult<I, O1, E>
+pub fn verify<I: Clone, O1, O2, E: ParseError<I>, F, G>(
+  mut first: F,
+  second: G,
+) -> impl FnMut(I) -> IResult<I, O1, E>
 where
-  F: Fn(I) -> IResult<I, O1, E>,
+  F: Parser<I, O1, E>,
   G: Fn(&O2) -> bool,
   O1: Borrow<O2>,
   O2: ?Sized,
 {
   move |input: I| {
     let i = input.clone();
-    let (input, o) = first(input)?;
+    let (input, o) = first.parse(input)?;
 
     if second(o.borrow()) {
       Ok((input, o))
@@ -475,71 +434,51 @@
   }
 }
 
-#[doc(hidden)]
-pub fn verifyc<I: Clone, O1, O2, E: ParseError<I>, F, G>(input: I, first: F, second: G) -> IResult<I, O1, E>
-where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(&O2) -> bool,
-  O1: Borrow<O2>,
-  O2: ?Sized,
-{
-  verify(first, second)(input)
-}
-
-/// returns the provided value if the child parser succeeds
+/// Returns the provided value if the child parser succeeds.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::combinator::value;
 /// use nom::character::complete::alpha1;
 /// # fn main() {
 ///
-/// let parser = value(1234, alpha1);
+/// let mut parser = value(1234, alpha1);
 ///
 /// assert_eq!(parser("abcd"), Ok(("", 1234)));
 /// assert_eq!(parser("123abcd;"), Err(Err::Error(("123abcd;", ErrorKind::Alpha))));
 /// # }
 /// ```
-pub fn value<I, O1: Clone, O2, E: ParseError<I>, F>(val: O1, parser: F) -> impl Fn(I) -> IResult<I, O1, E>
+pub fn value<I, O1: Clone, O2, E: ParseError<I>, F>(
+  val: O1,
+  mut parser: F,
+) -> impl FnMut(I) -> IResult<I, O1, E>
 where
-  F: Fn(I) -> IResult<I, O2, E>,
+  F: Parser<I, O2, E>,
 {
-  move |input: I| {
-    parser(input).map(|(i, _)| (i, val.clone()))
-  }
+  move |input: I| parser.parse(input).map(|(i, _)| (i, val.clone()))
 }
 
-#[doc(hidden)]
-pub fn valuec<I, O1: Clone, O2, E: ParseError<I>, F>(input: I, val: O1, parser: F) -> IResult<I, O1, E>
-where
-  F: Fn(I) -> IResult<I, O2, E>,
-{
-  value(val, parser)(input)
-}
-
-/// succeeds if the child parser returns an error
+/// Succeeds if the child parser returns an error.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::combinator::not;
 /// use nom::character::complete::alpha1;
 /// # fn main() {
 ///
-/// let parser = not(alpha1);
+/// let mut parser = not(alpha1);
 ///
 /// assert_eq!(parser("123"), Ok(("123", ())));
 /// assert_eq!(parser("abcd"), Err(Err::Error(("abcd", ErrorKind::Not))));
 /// # }
 /// ```
-pub fn not<I: Clone, O, E: ParseError<I>, F>(parser: F) -> impl Fn(I) -> IResult<I, (), E>
+pub fn not<I: Clone, O, E: ParseError<I>, F>(mut parser: F) -> impl FnMut(I) -> IResult<I, (), E>
 where
-  F: Fn(I) -> IResult<I, O, E>,
+  F: Parser<I, O, E>,
 {
   move |input: I| {
     let i = input.clone();
-    match parser(input) {
+    match parser.parse(input) {
       Ok(_) => Err(Err::Error(E::from_error_kind(i, ErrorKind::Not))),
       Err(Err::Error(_)) => Ok((i, ())),
       Err(e) => Err(e),
@@ -547,94 +486,162 @@
   }
 }
 
-#[doc(hidden)]
-pub fn notc<I: Clone, O, E: ParseError<I>, F>(input: I, parser: F) -> IResult<I, (), E>
-where
-  F: Fn(I) -> IResult<I, O, E>,
-{
-  not(parser)(input)
-}
-
-/// if the child parser was successful, return the consumed input as produced value
+/// If the child parser was successful, return the consumed input as produced value.
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::combinator::recognize;
 /// use nom::character::complete::{char, alpha1};
 /// use nom::sequence::separated_pair;
 /// # fn main() {
 ///
-/// let parser = recognize(separated_pair(alpha1, char(','), alpha1));
+/// let mut parser = recognize(separated_pair(alpha1, char(','), alpha1));
 ///
 /// assert_eq!(parser("abcd,efgh"), Ok(("", "abcd,efgh")));
 /// assert_eq!(parser("abcd;"),Err(Err::Error((";", ErrorKind::Char))));
 /// # }
 /// ```
-pub fn recognize<I: Clone + Offset + Slice<RangeTo<usize>>, O, E: ParseError<I>, F>(parser: F) -> impl Fn(I) -> IResult<I, I, E>
+pub fn recognize<I: Clone + Offset + Slice<RangeTo<usize>>, O, E: ParseError<I>, F>(
+  mut parser: F,
+) -> impl FnMut(I) -> IResult<I, I, E>
 where
-  F: Fn(I) -> IResult<I, O, E>,
+  F: Parser<I, O, E>,
 {
   move |input: I| {
     let i = input.clone();
-    match parser(i) {
+    match parser.parse(i) {
       Ok((i, _)) => {
         let index = input.offset(&i);
         Ok((i, input.slice(..index)))
-      },
+      }
       Err(e) => Err(e),
     }
   }
 }
 
-#[doc(hidden)]
-pub fn recognizec<I: Clone + Offset + Slice<RangeTo<usize>>, O, E: ParseError<I>, F>(input: I, parser: F) -> IResult<I, I, E>
+/// if the child parser was successful, return the consumed input with the output
+/// as a tuple. Functions similarly to [recognize](fn.recognize.html) except it
+/// returns the parser output as well.
+///
+/// This can be useful especially in cases where the output is not the same type
+/// as the input, or the input is a user defined type.
+///
+/// Returned tuple is of the format `(consumed input, produced output)`.
+///
+/// ```rust
+/// # use nom::{Err,error::ErrorKind, IResult};
+/// use nom::combinator::{consumed, value, recognize, map};
+/// use nom::character::complete::{char, alpha1};
+/// use nom::bytes::complete::tag;
+/// use nom::sequence::separated_pair;
+///
+/// fn inner_parser(input: &str) -> IResult<&str, bool> {
+///     value(true, tag("1234"))(input)
+/// }
+///
+/// # fn main() {
+///
+/// let mut consumed_parser = consumed(value(true, separated_pair(alpha1, char(','), alpha1)));
+///
+/// assert_eq!(consumed_parser("abcd,efgh1"), Ok(("1", ("abcd,efgh", true))));
+/// assert_eq!(consumed_parser("abcd;"),Err(Err::Error((";", ErrorKind::Char))));
+///
+///
+/// // the first output (representing the consumed input)
+/// // should be the same as that of the `recognize` parser.
+/// let mut recognize_parser = recognize(inner_parser);
+/// let mut consumed_parser = map(consumed(inner_parser), |(consumed, output)| consumed);
+///
+/// assert_eq!(recognize_parser("1234"), consumed_parser("1234"));
+/// assert_eq!(recognize_parser("abcd"), consumed_parser("abcd"));
+/// # }
+/// ```
+pub fn consumed<I, O, F, E>(mut parser: F) -> impl FnMut(I) -> IResult<I, (I, O), E>
 where
-  F: Fn(I) -> IResult<I, O, E>,
+  I: Clone + Offset + Slice<RangeTo<usize>>,
+  E: ParseError<I>,
+  F: Parser<I, O, E>,
 {
-  recognize(parser)(input)
+  move |input: I| {
+    let i = input.clone();
+    match parser.parse(i) {
+      Ok((remaining, result)) => {
+        let index = input.offset(&remaining);
+        let consumed = input.slice(..index);
+        Ok((remaining, (consumed, result)))
+      }
+      Err(e) => Err(e),
+    }
+  }
 }
 
 /// transforms an error to failure
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err,error::ErrorKind, IResult};
 /// use nom::combinator::cut;
 /// use nom::character::complete::alpha1;
 /// # fn main() {
 ///
-/// let parser = cut(alpha1);
+/// let mut parser = cut(alpha1);
 ///
 /// assert_eq!(parser("abcd;"), Ok((";", "abcd")));
 /// assert_eq!(parser("123;"), Err(Err::Failure(("123;", ErrorKind::Alpha))));
 /// # }
 /// ```
-pub fn cut<I: Clone + Slice<RangeTo<usize>>, O, E: ParseError<I>, F>(parser: F) -> impl Fn(I) -> IResult<I, O, E>
+pub fn cut<I, O, E: ParseError<I>, F>(mut parser: F) -> impl FnMut(I) -> IResult<I, O, E>
 where
-  F: Fn(I) -> IResult<I, O, E>,
+  F: Parser<I, O, E>,
 {
-  move |input: I| {
-    let i = input.clone();
-    match parser(i) {
-      Err(Err::Error(e)) => Err(Err::Failure(e)),
-      rest => rest,
-    }
+  move |input: I| match parser.parse(input) {
+    Err(Err::Error(e)) => Err(Err::Failure(e)),
+    rest => rest,
   }
 }
 
-#[doc(hidden)]
-pub fn cutc<I: Clone + Slice<RangeTo<usize>>, O, E: ParseError<I>, F>(input: I, parser: F) -> IResult<I, O, E>
+/// automatically converts the child parser's result to another type
+///
+/// it will be able to convert the output value and the error value
+/// as long as the `Into` implementations are available
+///
+/// ```rust
+/// # use nom::IResult;
+/// use nom::combinator::into;
+/// use nom::character::complete::alpha1;
+/// # fn main() {
+///
+///  fn parser1(i: &str) -> IResult<&str, &str> {
+///    alpha1(i)
+///  }
+///
+///  let mut parser2 = into(parser1);
+///
+/// // the parser converts the &str output of the child parser into a Vec<u8>
+/// let bytes: IResult<&str, Vec<u8>> = parser2("abcd");
+/// assert_eq!(bytes, Ok(("", vec![97, 98, 99, 100])));
+/// # }
+/// ```
+pub fn into<I, O1, O2, E1, E2, F>(mut parser: F) -> impl FnMut(I) -> IResult<I, O2, E2>
 where
-  F: Fn(I) -> IResult<I, O, E>,
+  O1: Into<O2>,
+  E1: Into<E2>,
+  E1: ParseError<I>,
+  E2: ParseError<I>,
+  F: Parser<I, O1, E1>,
 {
-  cut(parser)(input)
+  //map(parser, Into::into)
+  move |input: I| match parser.parse(input) {
+    Ok((i, o)) => Ok((i, o.into())),
+    Err(Err::Error(e)) => Err(Err::Error(e.into())),
+    Err(Err::Failure(e)) => Err(Err::Failure(e.into())),
+    Err(Err::Incomplete(e)) => Err(Err::Incomplete(e)),
+  }
 }
 
-/// creates an iterator from input data and a parser
+/// Creates an iterator from input data and a parser.
 ///
-/// call the iterator's [finish] method to get the remaining input if successful,
-/// or the error value if we encountered an error
+/// Call the iterator's [ParserIterator::finish] method to get the remaining input if successful,
+/// or the error value if we encountered an error.
 ///
 /// ```rust
 /// use nom::{combinator::iterator, IResult, bytes::complete::tag, character::complete::alpha1, sequence::terminated};
@@ -651,62 +658,63 @@
 /// ```
 pub fn iterator<Input, Output, Error, F>(input: Input, f: F) -> ParserIterator<Input, Error, F>
 where
-  F: Fn(Input) -> IResult<Input, Output, Error>,
-  Error: ParseError<Input> {
-
-    ParserIterator {
-      iterator: f,
-      input,
-      state: State::Running,
-    }
+  F: Parser<Input, Output, Error>,
+  Error: ParseError<Input>,
+{
+  ParserIterator {
+    iterator: f,
+    input,
+    state: Some(State::Running),
+  }
 }
 
-/// main structure associated to the [iterator] function
+/// Main structure associated to the [iterator] function.
 pub struct ParserIterator<I, E, F> {
   iterator: F,
   input: I,
-  state: State<E>,
+  state: Option<State<E>>,
 }
 
-impl<I: Clone, E: Clone, F> ParserIterator<I, E, F> {
-  /// returns the remaining input if parsing was successful, or the error if we encountered an error
-  pub fn finish(self) -> IResult<I, (), E> {
-    match &self.state {
-      State::Running | State::Done => Ok((self.input.clone(), ())),
-      State::Failure(e) => Err(Err::Failure(e.clone())),
-      State::Incomplete(i) => Err(Err::Incomplete(i.clone())),
+impl<I: Clone, E, F> ParserIterator<I, E, F> {
+  /// Returns the remaining input if parsing was successful, or the error if we encountered an error.
+  pub fn finish(mut self) -> IResult<I, (), E> {
+    match self.state.take().unwrap() {
+      State::Running | State::Done => Ok((self.input, ())),
+      State::Failure(e) => Err(Err::Failure(e)),
+      State::Incomplete(i) => Err(Err::Incomplete(i)),
     }
   }
 }
 
-impl<'a, Input ,Output ,Error, F> core::iter::Iterator for &'a mut ParserIterator<Input, Error, F>
-    where
-    F: Fn(Input) -> IResult<Input, Output, Error>,
-    Input: Clone
+impl<'a, Input, Output, Error, F> core::iter::Iterator for &'a mut ParserIterator<Input, Error, F>
+where
+  F: FnMut(Input) -> IResult<Input, Output, Error>,
+  Input: Clone,
 {
   type Item = Output;
 
   fn next(&mut self) -> Option<Self::Item> {
-    if let State::Running = self.state {
+    if let State::Running = self.state.take().unwrap() {
       let input = self.input.clone();
 
       match (self.iterator)(input) {
         Ok((i, o)) => {
           self.input = i;
+          self.state = Some(State::Running);
           Some(o)
-        },
+        }
         Err(Err::Error(_)) => {
-          self.state = State::Done;
+          self.state = Some(State::Done);
           None
-        },
+        }
         Err(Err::Failure(e)) => {
-          self.state = State::Failure(e);
+          self.state = Some(State::Failure(e));
           None
-        },
+        }
         Err(Err::Incomplete(i)) => {
-          self.state = State::Incomplete(i);
+          self.state = Some(State::Incomplete(i));
           None
-        },
+        }
       }
     } else {
       None
@@ -721,139 +729,40 @@
   Incomplete(Needed),
 }
 
+/// a parser which always succeeds with given value without consuming any input.
+///
+/// It can be used for example as the last alternative in `alt` to
+/// specify the default case.
+///
+/// ```rust
+/// # use nom::{Err,error::ErrorKind, IResult};
+/// use nom::branch::alt;
+/// use nom::combinator::{success, value};
+/// use nom::character::complete::char;
+/// # fn main() {
+///
+/// let mut parser = success::<_,_,(_,ErrorKind)>(10);
+/// assert_eq!(parser("xyz"), Ok(("xyz", 10)));
+///
+/// let mut sign = alt((value(-1, char('-')), value(1, char('+')), success::<_,_,(_,ErrorKind)>(1)));
+/// assert_eq!(sign("+10"), Ok(("10", 1)));
+/// assert_eq!(sign("-10"), Ok(("10", -1)));
+/// assert_eq!(sign("10"), Ok(("10", 1)));
+/// # }
+/// ```
+pub fn success<I, O: Clone, E: ParseError<I>>(val: O) -> impl Fn(I) -> IResult<I, O, E> {
+  move |input: I| Ok((input, val.clone()))
+}
 
-#[cfg(test)]
-mod tests {
-  use super::*;
-  use crate::internal::{Err, IResult, Needed};
-  use crate::error::ParseError;
-  use crate::bytes::complete::take;
-  use crate::number::complete::be_u8;
-
-  macro_rules! assert_parse(
-    ($left: expr, $right: expr) => {
-      let res: $crate::IResult<_, _, (_, ErrorKind)> = $left;
-      assert_eq!(res, $right);
-    };
-  );
-
-  /*#[test]
-  fn t1() {
-    let v1:Vec<u8> = vec![1,2,3];
-    let v2:Vec<u8> = vec![4,5,6];
-    let d = Ok((&v1[..], &v2[..]));
-    let res = d.flat_map(print);
-    assert_eq!(res, Ok((&v2[..], ())));
-  }*/
-
-
-  /*
-    #[test]
-    fn end_of_input() {
-        let not_over = &b"Hello, world!"[..];
-        let is_over = &b""[..];
-        named!(eof_test, eof!());
-
-        let res_not_over = eof_test(not_over);
-        assert_eq!(res_not_over, Err(Err::Error(error_position!(not_over, ErrorKind::Eof))));
-
-        let res_over = eof_test(is_over);
-        assert_eq!(res_over, Ok((is_over, is_over)));
-    }
-    */
-
-  #[test]
-  fn rest_on_slices() {
-    let input: &[u8] = &b"Hello, world!"[..];
-    let empty: &[u8] = &b""[..];
-    assert_parse!(rest(input), Ok((empty, input)));
-  }
-
-  #[test]
-  fn rest_on_strs() {
-    let input: &str = "Hello, world!";
-    let empty: &str = "";
-    assert_parse!(rest(input), Ok((empty, input)));
-  }
-
-  #[test]
-  fn rest_len_on_slices() {
-    let input: &[u8] = &b"Hello, world!"[..];
-    assert_parse!(rest_len(input), Ok((input, input.len())));
-  }
-
-  use crate::lib::std::convert::From;
-  impl From<u32> for CustomError {
-    fn from(_: u32) -> Self {
-      CustomError
-    }
-  }
-
-  impl<I> ParseError<I> for CustomError {
-    fn from_error_kind(_: I, _: ErrorKind) -> Self {
-      CustomError
-    }
-
-    fn append(_: I, _: ErrorKind, _: CustomError) -> Self {
-      CustomError
-    }
-  }
-
-  struct CustomError;
-  #[allow(dead_code)]
-  fn custom_error(input: &[u8]) -> IResult<&[u8], &[u8], CustomError> {
-    //fix_error!(input, CustomError, alphanumeric)
-    crate::character::streaming::alphanumeric1(input)
-  }
-
-  #[test]
-  fn test_flat_map() {
-      let input: &[u8] = &[3, 100, 101, 102, 103, 104][..];
-      assert_parse!(flat_map(be_u8, take)(input), Ok((&[103, 104][..], &[100, 101, 102][..])));
-  }
-
-  #[test]
-  fn test_map_opt() {
-      let input: &[u8] = &[50][..];
-      assert_parse!(map_opt(be_u8, |u| if u < 20 {Some(u)} else {None})(input), Err(Err::Error((&[50][..], ErrorKind::MapOpt))));
-      assert_parse!(map_opt(be_u8, |u| if u > 20 {Some(u)} else {None})(input), Ok((&[][..], 50)));
-  }
-
-  #[test]
-  fn test_map_parser() {
-      let input: &[u8] = &[100, 101, 102, 103, 104][..];
-      assert_parse!(map_parser(take(4usize), take(2usize))(input), Ok((&[104][..], &[100, 101][..])));
-  }
-
-  #[test]
-  fn test_all_consuming() {
-      let input: &[u8] = &[100, 101, 102][..];
-      assert_parse!(all_consuming(take(2usize))(input), Err(Err::Error((&[102][..], ErrorKind::Eof))));
-      assert_parse!(all_consuming(take(3usize))(input), Ok((&[][..], &[100, 101, 102][..])));
-  }
-
-  #[test]
-  #[allow(unused)]
-  fn test_verify_ref() {
-    use crate::bytes::complete::take;
-
-    let parser1 = verify(take(3u8), |s: &[u8]| s == &b"abc"[..]);
-
-    assert_eq!(parser1(&b"abcd"[..]), Ok((&b"d"[..], &b"abc"[..])));
-    assert_eq!(parser1(&b"defg"[..]), Err(Err::Error((&b"defg"[..], ErrorKind::Verify))));
-
-    fn parser2(i: &[u8]) -> IResult<&[u8], u32> {
-      verify(crate::number::streaming::be_u32, |val: &u32| *val < 3)(i)
-    }
-  }
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn test_verify_alloc() {
-    use crate::bytes::complete::take;
-    let parser1 = verify(map(take(3u8), |s: &[u8]| s.to_vec()), |s: &[u8]| s == &b"abc"[..]);
-
-    assert_eq!(parser1(&b"abcd"[..]), Ok((&b"d"[..], (&b"abc").to_vec())));
-    assert_eq!(parser1(&b"defg"[..]), Err(Err::Error((&b"defg"[..], ErrorKind::Verify))));
-  }
+/// A parser which always fails.
+///
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, IResult};
+/// use nom::combinator::fail;
+///
+/// let s = "string";
+/// assert_eq!(fail::<_, &str, _>(s), Err(Err::Error((s, ErrorKind::Fail))));
+/// ```
+pub fn fail<I, O, E: ParseError<I>>(i: I) -> IResult<I, O, E> {
+  Err(Err::Error(E::from_error_kind(i, ErrorKind::Fail)))
 }
diff --git a/src/combinator/tests.rs b/src/combinator/tests.rs
new file mode 100644
index 0000000..15d32b8
--- /dev/null
+++ b/src/combinator/tests.rs
@@ -0,0 +1,275 @@
+use super::*;
+use crate::bytes::complete::take;
+use crate::bytes::streaming::tag;
+use crate::error::ErrorKind;
+use crate::error::ParseError;
+use crate::internal::{Err, IResult, Needed};
+#[cfg(feature = "alloc")]
+use crate::lib::std::boxed::Box;
+use crate::number::complete::u8;
+
+macro_rules! assert_parse(
+  ($left: expr, $right: expr) => {
+    let res: $crate::IResult<_, _, (_, ErrorKind)> = $left;
+    assert_eq!(res, $right);
+  };
+);
+
+/*#[test]
+fn t1() {
+  let v1:Vec<u8> = vec![1,2,3];
+  let v2:Vec<u8> = vec![4,5,6];
+  let d = Ok((&v1[..], &v2[..]));
+  let res = d.flat_map(print);
+  assert_eq!(res, Ok((&v2[..], ())));
+}*/
+
+#[test]
+fn eof_on_slices() {
+  let not_over: &[u8] = &b"Hello, world!"[..];
+  let is_over: &[u8] = &b""[..];
+
+  let res_not_over = eof(not_over);
+  assert_parse!(
+    res_not_over,
+    Err(Err::Error(error_position!(not_over, ErrorKind::Eof)))
+  );
+
+  let res_over = eof(is_over);
+  assert_parse!(res_over, Ok((is_over, is_over)));
+}
+
+#[test]
+fn eof_on_strs() {
+  let not_over: &str = "Hello, world!";
+  let is_over: &str = "";
+
+  let res_not_over = eof(not_over);
+  assert_parse!(
+    res_not_over,
+    Err(Err::Error(error_position!(not_over, ErrorKind::Eof)))
+  );
+
+  let res_over = eof(is_over);
+  assert_parse!(res_over, Ok((is_over, is_over)));
+}
+
+/*
+#[test]
+fn end_of_input() {
+    let not_over = &b"Hello, world!"[..];
+    let is_over = &b""[..];
+    named!(eof_test, eof!());
+
+    let res_not_over = eof_test(not_over);
+    assert_eq!(res_not_over, Err(Err::Error(error_position!(not_over, ErrorKind::Eof))));
+
+    let res_over = eof_test(is_over);
+    assert_eq!(res_over, Ok((is_over, is_over)));
+}
+*/
+
+#[test]
+fn rest_on_slices() {
+  let input: &[u8] = &b"Hello, world!"[..];
+  let empty: &[u8] = &b""[..];
+  assert_parse!(rest(input), Ok((empty, input)));
+}
+
+#[test]
+fn rest_on_strs() {
+  let input: &str = "Hello, world!";
+  let empty: &str = "";
+  assert_parse!(rest(input), Ok((empty, input)));
+}
+
+#[test]
+fn rest_len_on_slices() {
+  let input: &[u8] = &b"Hello, world!"[..];
+  assert_parse!(rest_len(input), Ok((input, input.len())));
+}
+
+use crate::lib::std::convert::From;
+impl From<u32> for CustomError {
+  fn from(_: u32) -> Self {
+    CustomError
+  }
+}
+
+impl<I> ParseError<I> for CustomError {
+  fn from_error_kind(_: I, _: ErrorKind) -> Self {
+    CustomError
+  }
+
+  fn append(_: I, _: ErrorKind, _: CustomError) -> Self {
+    CustomError
+  }
+}
+
+struct CustomError;
+#[allow(dead_code)]
+fn custom_error(input: &[u8]) -> IResult<&[u8], &[u8], CustomError> {
+  //fix_error!(input, CustomError, alphanumeric)
+  crate::character::streaming::alphanumeric1(input)
+}
+
+#[test]
+fn test_flat_map() {
+  let input: &[u8] = &[3, 100, 101, 102, 103, 104][..];
+  assert_parse!(
+    flat_map(u8, take)(input),
+    Ok((&[103, 104][..], &[100, 101, 102][..]))
+  );
+}
+
+#[test]
+fn test_map_opt() {
+  let input: &[u8] = &[50][..];
+  assert_parse!(
+    map_opt(u8, |u| if u < 20 { Some(u) } else { None })(input),
+    Err(Err::Error((&[50][..], ErrorKind::MapOpt)))
+  );
+  assert_parse!(
+    map_opt(u8, |u| if u > 20 { Some(u) } else { None })(input),
+    Ok((&[][..], 50))
+  );
+}
+
+#[test]
+fn test_map_parser() {
+  let input: &[u8] = &[100, 101, 102, 103, 104][..];
+  assert_parse!(
+    map_parser(take(4usize), take(2usize))(input),
+    Ok((&[104][..], &[100, 101][..]))
+  );
+}
+
+#[test]
+fn test_all_consuming() {
+  let input: &[u8] = &[100, 101, 102][..];
+  assert_parse!(
+    all_consuming(take(2usize))(input),
+    Err(Err::Error((&[102][..], ErrorKind::Eof)))
+  );
+  assert_parse!(
+    all_consuming(take(3usize))(input),
+    Ok((&[][..], &[100, 101, 102][..]))
+  );
+}
+
+#[test]
+#[allow(unused)]
+fn test_verify_ref() {
+  use crate::bytes::complete::take;
+
+  let mut parser1 = verify(take(3u8), |s: &[u8]| s == &b"abc"[..]);
+
+  assert_eq!(parser1(&b"abcd"[..]), Ok((&b"d"[..], &b"abc"[..])));
+  assert_eq!(
+    parser1(&b"defg"[..]),
+    Err(Err::Error((&b"defg"[..], ErrorKind::Verify)))
+  );
+
+  fn parser2(i: &[u8]) -> IResult<&[u8], u32> {
+    verify(crate::number::streaming::be_u32, |val: &u32| *val < 3)(i)
+  }
+}
+
+#[test]
+#[cfg(feature = "alloc")]
+fn test_verify_alloc() {
+  use crate::bytes::complete::take;
+  let mut parser1 = verify(map(take(3u8), |s: &[u8]| s.to_vec()), |s: &[u8]| {
+    s == &b"abc"[..]
+  });
+
+  assert_eq!(parser1(&b"abcd"[..]), Ok((&b"d"[..], (&b"abc").to_vec())));
+  assert_eq!(
+    parser1(&b"defg"[..]),
+    Err(Err::Error((&b"defg"[..], ErrorKind::Verify)))
+  );
+}
+
+#[test]
+#[cfg(feature = "std")]
+fn test_into() {
+  use crate::bytes::complete::take;
+  use crate::{
+    error::{Error, ParseError},
+    Err,
+  };
+
+  let mut parser = into(take::<_, _, Error<_>>(3u8));
+  let result: IResult<&[u8], Vec<u8>> = parser(&b"abcdefg"[..]);
+
+  assert_eq!(result, Ok((&b"defg"[..], vec![97, 98, 99])));
+}
+
+#[test]
+fn opt_test() {
+  fn opt_abcd(i: &[u8]) -> IResult<&[u8], Option<&[u8]>> {
+    opt(tag("abcd"))(i)
+  }
+
+  let a = &b"abcdef"[..];
+  let b = &b"bcdefg"[..];
+  let c = &b"ab"[..];
+  assert_eq!(opt_abcd(a), Ok((&b"ef"[..], Some(&b"abcd"[..]))));
+  assert_eq!(opt_abcd(b), Ok((&b"bcdefg"[..], None)));
+  assert_eq!(opt_abcd(c), Err(Err::Incomplete(Needed::new(2))));
+}
+
+#[test]
+fn peek_test() {
+  fn peek_tag(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    peek(tag("abcd"))(i)
+  }
+
+  assert_eq!(peek_tag(&b"abcdef"[..]), Ok((&b"abcdef"[..], &b"abcd"[..])));
+  assert_eq!(peek_tag(&b"ab"[..]), Err(Err::Incomplete(Needed::new(2))));
+  assert_eq!(
+    peek_tag(&b"xxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
+  );
+}
+
+#[test]
+fn not_test() {
+  fn not_aaa(i: &[u8]) -> IResult<&[u8], ()> {
+    not(tag("aaa"))(i)
+  }
+
+  assert_eq!(
+    not_aaa(&b"aaa"[..]),
+    Err(Err::Error(error_position!(&b"aaa"[..], ErrorKind::Not)))
+  );
+  assert_eq!(not_aaa(&b"aa"[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(not_aaa(&b"abcd"[..]), Ok((&b"abcd"[..], ())));
+}
+
+#[test]
+fn verify_test() {
+  use crate::bytes::streaming::take;
+
+  fn test(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    verify(take(5u8), |slice: &[u8]| slice[0] == b'a')(i)
+  }
+  assert_eq!(test(&b"bcd"[..]), Err(Err::Incomplete(Needed::new(2))));
+  assert_eq!(
+    test(&b"bcdefg"[..]),
+    Err(Err::Error(error_position!(
+      &b"bcdefg"[..],
+      ErrorKind::Verify
+    )))
+  );
+  assert_eq!(test(&b"abcdefg"[..]), Ok((&b"fg"[..], &b"abcde"[..])));
+}
+
+#[test]
+fn fail_test() {
+  let a = "string";
+  let b = "another string";
+
+  assert_eq!(fail::<_, &str, _>(a), Err(Err::Error((a, ErrorKind::Fail))));
+  assert_eq!(fail::<_, &str, _>(b), Err(Err::Error((b, ErrorKind::Fail))));
+}
diff --git a/src/error.rs b/src/error.rs
index 1505161..498b5e1 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -3,34 +3,41 @@
 //! Parsers are generic over their error type, requiring that it implements
 //! the `error::ParseError<Input>` trait.
 
-/// this trait must be implemented by the error type of a nom parser
+use crate::internal::Parser;
+use crate::lib::std::fmt;
+
+/// This trait must be implemented by the error type of a nom parser.
 ///
 /// There are already implementations of it for `(Input, ErrorKind)`
 /// and `VerboseError<Input>`.
 ///
 /// It provides methods to create an error from some combinators,
-/// and combine existing errors in combinators like `alt`
+/// and combine existing errors in combinators like `alt`.
 pub trait ParseError<I>: Sized {
-  /// creates an error from the input position and an [ErrorKind]
+  /// Creates an error from the input position and an [ErrorKind]
   fn from_error_kind(input: I, kind: ErrorKind) -> Self;
 
-  /// combines an existing error with a new one created from the input
+  /// Combines an existing error with a new one created from the input
   /// position and an [ErrorKind]. This is useful when backtracking
   /// through a parse tree, accumulating error context on the way
   fn append(input: I, kind: ErrorKind, other: Self) -> Self;
 
-  /// creates an error from an input position and an expected character
+  /// Creates an error from an input position and an expected character
   fn from_char(input: I, _: char) -> Self {
     Self::from_error_kind(input, ErrorKind::Char)
   }
 
-  /// combines two existing error. This function is used to compare errors
-  /// generated in various branches of [alt]
+  /// Combines two existing errors. This function is used to compare errors
+  /// generated in various branches of `alt`.
   fn or(self, other: Self) -> Self {
     other
   }
+}
 
-  /// create a new error from an input position, a static string and an existing error.
+/// This trait is required by the `context` combinator to add a static string
+/// to an existing error
+pub trait ContextError<I>: Sized {
+  /// Creates a new error from an input position, a static string and an existing error.
   /// This is used mainly in the [context] combinator, to add user friendly information
   /// to errors when backtracking through a parse tree
   fn add_context(_input: I, _ctx: &'static str, other: Self) -> Self {
@@ -38,6 +45,61 @@
   }
 }
 
+/// This trait is required by the `map_res` combinator to integrate
+/// error types from external functions, like [std::str::FromStr]
+pub trait FromExternalError<I, E> {
+  /// Creates a new error from an input position, an [ErrorKind] indicating the
+  /// wrapping parser, and an external error
+  fn from_external_error(input: I, kind: ErrorKind, e: E) -> Self;
+}
+
+/// default error type, only contains the error' location and code
+#[derive(Debug, PartialEq)]
+pub struct Error<I> {
+  /// position of the error in the input data
+  pub input: I,
+  /// nom error code
+  pub code: ErrorKind,
+}
+
+impl<I> Error<I> {
+  /// creates a new basic error
+  pub fn new(input: I, code: ErrorKind) -> Error<I> {
+    Error { input, code }
+  }
+}
+
+impl<I> ParseError<I> for Error<I> {
+  fn from_error_kind(input: I, kind: ErrorKind) -> Self {
+    Error { input, code: kind }
+  }
+
+  fn append(_: I, _: ErrorKind, other: Self) -> Self {
+    other
+  }
+}
+
+impl<I> ContextError<I> for Error<I> {}
+
+impl<I, E> FromExternalError<I, E> for Error<I> {
+  /// Create a new error from an input position and an external error
+  fn from_external_error(input: I, kind: ErrorKind, _e: E) -> Self {
+    Error { input, code: kind }
+  }
+}
+
+/// The Display implementation allows the std::error::Error implementation
+impl<I: fmt::Display> fmt::Display for Error<I> {
+  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+    write!(f, "error {:?} at: {}", self.code, self.input)
+  }
+}
+
+#[cfg(feature = "std")]
+impl<I: fmt::Debug + fmt::Display> std::error::Error for Error<I> {}
+
+// for backward compatibility, keep those trait implementations
+// for the previously used error type
 impl<I> ParseError<I> for (I, ErrorKind) {
   fn from_error_kind(input: I, kind: ErrorKind) -> Self {
     (input, kind)
@@ -48,48 +110,65 @@
   }
 }
 
+impl<I> ContextError<I> for (I, ErrorKind) {}
+
+impl<I, E> FromExternalError<I, E> for (I, ErrorKind) {
+  fn from_external_error(input: I, kind: ErrorKind, _e: E) -> Self {
+    (input, kind)
+  }
+}
+
 impl<I> ParseError<I> for () {
   fn from_error_kind(_: I, _: ErrorKind) -> Self {}
 
   fn append(_: I, _: ErrorKind, _: Self) -> Self {}
 }
 
-/// creates an error from the input position and an [ErrorKind]
+impl<I> ContextError<I> for () {}
+
+impl<I, E> FromExternalError<I, E> for () {
+  fn from_external_error(_input: I, _kind: ErrorKind, _e: E) -> Self {}
+}
+
+/// Creates an error from the input position and an [ErrorKind]
 pub fn make_error<I, E: ParseError<I>>(input: I, kind: ErrorKind) -> E {
   E::from_error_kind(input, kind)
 }
 
-/// combines an existing error with a new one created from the input
+/// Combines an existing error with a new one created from the input
 /// position and an [ErrorKind]. This is useful when backtracking
 /// through a parse tree, accumulating error context on the way
 pub fn append_error<I, E: ParseError<I>>(input: I, kind: ErrorKind, other: E) -> E {
   E::append(input, kind, other)
 }
 
-/// this error type accumulates errors and their position when backtracking
+/// This error type accumulates errors and their position when backtracking
 /// through a parse tree. With some post processing (cf `examples/json.rs`),
 /// it can be used to display user friendly error messages
 #[cfg(feature = "alloc")]
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
 #[derive(Clone, Debug, PartialEq)]
 pub struct VerboseError<I> {
-  /// list of errors accumulated by `VerboseError`, containing the affected
+  /// List of errors accumulated by `VerboseError`, containing the affected
   /// part of input data, and some context
   pub errors: crate::lib::std::vec::Vec<(I, VerboseErrorKind)>,
 }
 
 #[cfg(feature = "alloc")]
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
 #[derive(Clone, Debug, PartialEq)]
-/// error context for `VerboseError`
+/// Error context for `VerboseError`
 pub enum VerboseErrorKind {
-  /// static string added by the `context` function
+  /// Static string added by the `context` function
   Context(&'static str),
-  /// indicates which character was expected by the `char` function
+  /// Indicates which character was expected by the `char` function
   Char(char),
-  /// error kind given by various nom parsers
+  /// Error kind given by various nom parsers
   Nom(ErrorKind),
 }
 
 #[cfg(feature = "alloc")]
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
 impl<I> ParseError<I> for VerboseError<I> {
   fn from_error_kind(input: I, kind: ErrorKind) -> Self {
     VerboseError {
@@ -107,23 +186,58 @@
       errors: vec![(input, VerboseErrorKind::Char(c))],
     }
   }
+}
 
+#[cfg(feature = "alloc")]
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+impl<I> ContextError<I> for VerboseError<I> {
   fn add_context(input: I, ctx: &'static str, mut other: Self) -> Self {
     other.errors.push((input, VerboseErrorKind::Context(ctx)));
     other
   }
 }
 
+#[cfg(feature = "alloc")]
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+impl<I, E> FromExternalError<I, E> for VerboseError<I> {
+  /// Create a new error from an input position and an external error
+  fn from_external_error(input: I, kind: ErrorKind, _e: E) -> Self {
+    Self::from_error_kind(input, kind)
+  }
+}
+
+#[cfg(feature = "alloc")]
+impl<I: fmt::Display> fmt::Display for VerboseError<I> {
+  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+    writeln!(f, "Parse error:")?;
+    for (input, error) in &self.errors {
+      match error {
+        VerboseErrorKind::Nom(e) => writeln!(f, "{:?} at: {}", e, input)?,
+        VerboseErrorKind::Char(c) => writeln!(f, "expected '{}' at: {}", c, input)?,
+        VerboseErrorKind::Context(s) => writeln!(f, "in section '{}', at: {}", s, input)?,
+      }
+    }
+
+    Ok(())
+  }
+}
+
+#[cfg(feature = "std")]
+impl<I: fmt::Debug + fmt::Display> std::error::Error for VerboseError<I> {}
+
 use crate::internal::{Err, IResult};
 
-/// create a new error from an input position, a static string and an existing error.
+/// Create a new error from an input position, a static string and an existing error.
 /// This is used mainly in the [context] combinator, to add user friendly information
 /// to errors when backtracking through a parse tree
-pub fn context<I: Clone, E: ParseError<I>, F, O>(context: &'static str, f: F) -> impl Fn(I) -> IResult<I, O, E>
+pub fn context<I: Clone, E: ContextError<I>, F, O>(
+  context: &'static str,
+  mut f: F,
+) -> impl FnMut(I) -> IResult<I, O, E>
 where
-  F: Fn(I) -> IResult<I, O, E>,
+  F: Parser<I, O, E>,
 {
-  move |i: I| match f(i.clone()) {
+  move |i: I| match f.parse(i.clone()) {
     Ok(o) => Ok(o),
     Err(Err::Incomplete(i)) => Err(Err::Incomplete(i)),
     Err(Err::Error(e)) => Err(Err::Error(E::add_context(i, context, e))),
@@ -131,9 +245,13 @@
   }
 }
 
-/// transforms a `VerboseError` into a trace with input position information
+/// Transforms a `VerboseError` into a trace with input position information
 #[cfg(feature = "alloc")]
-pub fn convert_error(input: &str, e: VerboseError<&str>) -> crate::lib::std::string::String {
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+pub fn convert_error<I: core::ops::Deref<Target = str>>(
+  input: I,
+  e: VerboseError<I>,
+) -> crate::lib::std::string::String {
   use crate::lib::std::fmt::Write;
   use crate::traits::Offset;
 
@@ -144,7 +262,9 @@
 
     if input.is_empty() {
       match kind {
-        VerboseErrorKind::Char(c) => write!(&mut result, "{}: expected '{}', got empty input\n\n", i, c),
+        VerboseErrorKind::Char(c) => {
+          write!(&mut result, "{}: expected '{}', got empty input\n\n", i, c)
+        }
         VerboseErrorKind::Context(s) => write!(&mut result, "{}: in {}, got empty input\n\n", i, s),
         VerboseErrorKind::Nom(e) => write!(&mut result, "{}: in {:?}, got empty input\n\n", i, e),
       }
@@ -156,45 +276,56 @@
 
       // Find the line that includes the subslice:
       // Find the *last* newline before the substring starts
-      let line_begin = prefix.iter().rev().position(|&b| b == b'\n').map(|pos| offset - pos).unwrap_or(0);
+      let line_begin = prefix
+        .iter()
+        .rev()
+        .position(|&b| b == b'\n')
+        .map(|pos| offset - pos)
+        .unwrap_or(0);
 
       // Find the full line after that newline
-      let line = input[line_begin..].lines().next().unwrap_or(&input[line_begin..]).trim_end();
+      let line = input[line_begin..]
+        .lines()
+        .next()
+        .unwrap_or(&input[line_begin..])
+        .trim_end();
 
       // The (1-indexed) column number is the offset of our substring into that line
       let column_number = line.offset(substring) + 1;
 
       match kind {
-        VerboseErrorKind::Char(c) => if let Some(actual) = substring.chars().next() {
-          write!(
-            &mut result,
-            "{i}: at line {line_number}:\n\
+        VerboseErrorKind::Char(c) => {
+          if let Some(actual) = substring.chars().next() {
+            write!(
+              &mut result,
+              "{i}: at line {line_number}:\n\
                {line}\n\
                {caret:>column$}\n\
                expected '{expected}', found {actual}\n\n",
-            i = i,
-            line_number = line_number,
-            line = line,
-            caret = '^',
-            column = column_number,
-            expected = c,
-            actual = actual,
-          )
-        } else {
-          write!(
-            &mut result,
-            "{i}: at line {line_number}:\n\
+              i = i,
+              line_number = line_number,
+              line = line,
+              caret = '^',
+              column = column_number,
+              expected = c,
+              actual = actual,
+            )
+          } else {
+            write!(
+              &mut result,
+              "{i}: at line {line_number}:\n\
                {line}\n\
                {caret:>column$}\n\
                expected '{expected}', got end of input\n\n",
-            i = i,
-            line_number = line_number,
-            line = line,
-            caret = '^',
-            column = column_number,
-            expected = c,
-          )
-        },
+              i = i,
+              line_number = line_number,
+              line = line,
+              caret = '^',
+              column = column_number,
+              expected = c,
+            )
+          }
+        }
         VerboseErrorKind::Context(s) => write!(
           &mut result,
           "{i}: at line {line_number}, in {context}:\n\
@@ -228,8 +359,8 @@
   result
 }
 
-/// indicates which parser returned an error
-#[cfg_attr(rustfmt, rustfmt_skip)]
+/// Indicates which parser returned an error
+#[rustfmt::skip]
 #[derive(Debug,PartialEq,Eq,Hash,Clone,Copy)]
 #[allow(deprecated,missing_docs)]
 pub enum ErrorKind {
@@ -280,16 +411,17 @@
   Verify,
   TakeTill1,
   TakeWhileMN,
-  ParseTo,
   TooLarge,
   Many0Count,
   Many1Count,
   Float,
+  Satisfy,
+  Fail,
 }
 
-#[cfg_attr(rustfmt, rustfmt_skip)]
+#[rustfmt::skip]
 #[allow(deprecated)]
-/// converts an ErrorKind to a number
+/// Converts an ErrorKind to a number
 pub fn error_to_u32(e: &ErrorKind) -> u32 {
   match *e {
     ErrorKind::Tag                       => 1,
@@ -339,18 +471,19 @@
     ErrorKind::Verify                    => 66,
     ErrorKind::TakeTill1                 => 67,
     ErrorKind::TakeWhileMN               => 69,
-    ErrorKind::ParseTo                   => 70,
-    ErrorKind::TooLarge                  => 71,
-    ErrorKind::Many0Count                => 72,
-    ErrorKind::Many1Count                => 73,
-    ErrorKind::Float                     => 74,
+    ErrorKind::TooLarge                  => 70,
+    ErrorKind::Many0Count                => 71,
+    ErrorKind::Many1Count                => 72,
+    ErrorKind::Float                     => 73,
+    ErrorKind::Satisfy                   => 74,
+    ErrorKind::Fail                      => 75,
   }
 }
 
 impl ErrorKind {
-  #[cfg_attr(rustfmt, rustfmt_skip)]
+  #[rustfmt::skip]
   #[allow(deprecated)]
-  /// converts an ErrorKind to a text description
+  /// Converts an ErrorKind to a text description
   pub fn description(&self) -> &str {
     match *self {
       ErrorKind::Tag                       => "Tag",
@@ -400,16 +533,17 @@
       ErrorKind::Verify                    => "predicate verification",
       ErrorKind::TakeTill1                 => "TakeTill1",
       ErrorKind::TakeWhileMN               => "TakeWhileMN",
-      ErrorKind::ParseTo                   => "Parse string to the specified type",
       ErrorKind::TooLarge                  => "Needed data size is too large",
       ErrorKind::Many0Count                => "Count occurrence of >=0 patterns",
       ErrorKind::Many1Count                => "Count occurrence of >=1 patterns",
       ErrorKind::Float                     => "Float",
+      ErrorKind::Satisfy                   => "Satisfy",
+      ErrorKind::Fail                      => "Fail",
     }
   }
 }
 
-/// creates a parse error from a `nom::ErrorKind`
+/// Creates a parse error from a `nom::ErrorKind`
 /// and the position in the input
 #[allow(unused_variables)]
 #[macro_export(local_inner_macros)]
@@ -419,9 +553,9 @@
   });
 );
 
-/// creates a parse error from a `nom::ErrorKind`,
+/// Creates a parse error from a `nom::ErrorKind`,
 /// the position in the input and the next error in
-/// the parsing tree.
+/// the parsing tree
 #[allow(unused_variables)]
 #[macro_export(local_inner_macros)]
 macro_rules! error_node_position(
@@ -430,124 +564,45 @@
   });
 );
 
-/*
-
-#[cfg(feature = "std")]
-use $crate::lib::std::any::Any;
-#[cfg(feature = "std")]
-use $crate::lib::std::{error,fmt};
-#[cfg(feature = "std")]
-impl<E: fmt::Debug+Any> error::Error for Err<E> {
-  fn description(&self) -> &str {
-    self.description()
-  }
-}
-
-#[cfg(feature = "std")]
-impl<E: fmt::Debug> fmt::Display for Err<E> {
-  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-    write!(f, "{}", self.description())
-  }
-}
-*/
-
-//FIXME: error rewrite
-/// translate parser result from IResult<I,O,u32> to IResult<I,O,E> with a custom type
+/// Prints a message and the input if the parser fails.
 ///
-/// ```
-/// # //FIXME
-/// # #[macro_use] extern crate nom;
-/// # use nom::IResult;
-/// # use std::convert::From;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-/// #    /*
-/// #    // will add a Custom(42) error to the error chain
-/// #    named!(err_test, add_return_error!(ErrorKind::Custom(42u32), tag!("abcd")));
-/// #
-/// #    #[derive(Debug,Clone,PartialEq)]
-/// #    pub struct ErrorStr(String);
-/// #
-/// #    // Convert to IResult<&[u8], &[u8], ErrorStr>
-/// #    impl From<u32> for ErrorStr {
-/// #      fn from(i: u32) -> Self {
-/// #        ErrorStr(format!("custom error code: {}", i))
-/// #      }
-/// #    }
-/// #
-/// #    named!(parser<&[u8], &[u8], ErrorStr>,
-/// #        fix_error!(ErrorStr, err_test)
-/// #      );
-/// #
-/// #    let a = &b"efghblah"[..];
-/// #    assert_eq!(parser(a), Err(Err::Error(Context::Code(a, ErrorKind::Custom(ErrorStr("custom error code: 42".to_string()))))));
-/// # */
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! fix_error (
-  ($i:expr, $t:ty, $submac:ident!( $($args:tt)* )) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::Err;
-
-      match $submac!($i, $($args)*) {
-        Ok((i,o)) => Ok((i,o)),
-        Err(e) => {
-          let e2 = match e {
-            Err::Error(err) => {
-              Err::Error(err.into())
-            },
-            Err::Failure(err) => {
-              Err::Failure(err.into())
-            },
-            Err::Incomplete(e) => Err::Incomplete(e),
-          };
-          Err(e2)
-        }
-      }
-    }
-  );
-  ($i:expr, $t:ty, $f:expr) => (
-    fix_error!($i, $t, call!($f));
-  );
-);
-
-/// `flat_map!(R -> IResult<R,S>, S -> IResult<S,T>) => R -> IResult<R, T>`
+/// The message prints the `Error` or `Incomplete`
+/// and the parser's calling code.
 ///
-/// combines a parser R -> IResult<R,S> and
-/// a parser S -> IResult<S,T> to return another
-/// parser R -> IResult<R,T>
+/// It also displays the input in hexdump format
 ///
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind};
-/// use nom::number::complete::recognize_float;
+/// use nom::{IResult, error::dbg_dmp, bytes::complete::tag};
 ///
-/// named!(parser<&str, f64>, flat_map!(recognize_float, parse_to!(f64)));
+/// fn f(i: &[u8]) -> IResult<&[u8], &[u8]> {
+///   dbg_dmp(tag("abcd"), "tag")(i)
+/// }
 ///
-/// assert_eq!(parser("123.45;"), Ok((";", 123.45)));
-/// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Char))));
+///   let a = &b"efghijkl"[..];
+///
+/// // Will print the following message:
+/// // Error(Position(0, [101, 102, 103, 104, 105, 106, 107, 108])) at l.5 by ' tag ! ( "abcd" ) '
+/// // 00000000        65 66 67 68 69 6a 6b 6c         efghijkl
+/// f(a);
 /// ```
-#[macro_export(local_inner_macros)]
-macro_rules! flat_map(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    flat_map!(__impl $i, $submac!($($args)*), $submac2!($($args2)*));
-  );
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    flat_map!(__impl $i, $submac!($($args)*), call!($g));
-  );
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    flat_map!(__impl $i, call!($f), $submac!($($args)*));
-  );
-  ($i:expr, $f:expr, $g:expr) => (
-    flat_map!(__impl $i, call!($f), call!($g));
-  );
-  (__impl $i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    $crate::combinator::map_parserc($i, move |i| {$submac!(i, $($args)*)}, move |i| {$submac2!(i, $($args2)*)})
-  );
-);
+#[cfg(feature = "std")]
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "std")))]
+pub fn dbg_dmp<'a, F, O, E: std::fmt::Debug>(
+  f: F,
+  context: &'static str,
+) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], O, E>
+where
+  F: Fn(&'a [u8]) -> IResult<&'a [u8], O, E>,
+{
+  use crate::HexDisplay;
+  move |i: &'a [u8]| match f(i) {
+    Err(e) => {
+      println!("{}: Error({:?}) at:\n{}", context, e, i.to_hex(8));
+      Err(e)
+    }
+    a => a,
+  }
+}
 
 #[cfg(test)]
 #[cfg(feature = "alloc")]
@@ -559,7 +614,7 @@
   fn convert_error_panic() {
     let input = "";
 
-    let result: IResult<_, _, VerboseError<&str>> = char('x')(input);
+    let _result: IResult<_, _, VerboseError<&str>> = char('x')(input);
   }
 }
 
diff --git a/src/internal.rs b/src/internal.rs
index 401f98a..8a3c6a1 100644
--- a/src/internal.rs
+++ b/src/internal.rs
@@ -1,38 +1,79 @@
 //! Basic types to build the parsers
 
 use self::Needed::*;
-use crate::error::ErrorKind;
+use crate::error::{self, ErrorKind};
+use crate::lib::std::fmt;
+use core::num::NonZeroUsize;
 
 /// Holds the result of parsing functions
 ///
-/// It depends on I, the input type, O, the output type, and E, the error type (by default u32)
+/// It depends on the input type `I`, the output type `O`, and the error type `E`
+/// (by default `(I, nom::ErrorKind)`)
 ///
 /// The `Ok` side is a pair containing the remainder of the input (the part of the data that
 /// was not parsed) and the produced value. The `Err` side contains an instance of `nom::Err`.
 ///
-pub type IResult<I, O, E=(I,ErrorKind)> = Result<(I, O), Err<E>>;
+/// Outside of the parsing code, you can use the [Finish::finish] method to convert
+/// it to a more common result type
+pub type IResult<I, O, E = error::Error<I>> = Result<(I, O), Err<E>>;
+
+/// Helper trait to convert a parser's result to a more manageable type
+pub trait Finish<I, O, E> {
+  /// converts the parser's result to a type that is more consumable by error
+  /// management libraries. It keeps the same `Ok` branch, and merges `Err::Error`
+  /// and `Err::Failure` into the `Err` side.
+  ///
+  /// *warning*: if the result is `Err(Err::Incomplete(_))`, this method will panic.
+  /// - "complete" parsers: It will not be an issue, `Incomplete` is never used
+  /// - "streaming" parsers: `Incomplete` will be returned if there's not enough data
+  /// for the parser to decide, and you should gather more data before parsing again.
+  /// Once the parser returns either `Ok(_)`, `Err(Err::Error(_))` or `Err(Err::Failure(_))`,
+  /// you can get out of the parsing loop and call `finish()` on the parser's result
+  fn finish(self) -> Result<(I, O), E>;
+}
+
+impl<I, O, E> Finish<I, O, E> for IResult<I, O, E> {
+  fn finish(self) -> Result<(I, O), E> {
+    match self {
+      Ok(res) => Ok(res),
+      Err(Err::Error(e)) | Err(Err::Failure(e)) => Err(e),
+      Err(Err::Incomplete(_)) => {
+        panic!("Cannot call `finish()` on `Err(Err::Incomplete(_))`: this result means that the parser does not have enough data to decide, you should gather more data and try to reapply  the parser instead")
+      }
+    }
+  }
+}
 
 /// Contains information on needed data if a parser returned `Incomplete`
 #[derive(Debug, PartialEq, Eq, Clone, Copy)]
+#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))]
 pub enum Needed {
-  /// needs more data, but we do not know how much
+  /// Needs more data, but we do not know how much
   Unknown,
-  /// contains the required data size
-  Size(usize),
+  /// Contains the required data size in bytes
+  Size(NonZeroUsize),
 }
 
 impl Needed {
-  /// indicates if we know how many bytes we need
+  /// Creates `Needed` instance, returns `Needed::Unknown` if the argument is zero
+  pub fn new(s: usize) -> Self {
+    match NonZeroUsize::new(s) {
+      Some(sz) => Needed::Size(sz),
+      None => Needed::Unknown,
+    }
+  }
+
+  /// Indicates if we know how many bytes we need
   pub fn is_known(&self) -> bool {
     *self != Unknown
   }
 
   /// Maps a `Needed` to `Needed` by applying a function to a contained `Size` value.
   #[inline]
-  pub fn map<F: Fn(usize) -> usize>(self, f: F) -> Needed {
+  pub fn map<F: Fn(NonZeroUsize) -> usize>(self, f: F) -> Needed {
     match self {
       Unknown => Unknown,
-      Size(n) => Size(f(n)),
+      Size(n) => Needed::new(f(n)),
     }
   }
 }
@@ -52,6 +93,7 @@
 /// to try other parsers, you were already in the right branch, so the data is invalid
 ///
 #[derive(Debug, Clone, PartialEq)]
+#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))]
 pub enum Err<E> {
   /// There was not enough data
   Incomplete(Needed),
@@ -64,7 +106,7 @@
 }
 
 impl<E> Err<E> {
-  /// tests if the result is Incomplete
+  /// Tests if the result is Incomplete
   pub fn is_incomplete(&self) -> bool {
     if let Err::Incomplete(_) = self {
       true
@@ -75,7 +117,8 @@
 
   /// Applies the given function to the inner error
   pub fn map<E2, F>(self, f: F) -> Err<E2>
-    where F: FnOnce(E) -> E2
+  where
+    F: FnOnce(E) -> E2,
   {
     match self {
       Err::Incomplete(n) => Err::Incomplete(n),
@@ -84,18 +127,21 @@
     }
   }
 
-  /// automatically converts between errors if the underlying type supports it
+  /// Automatically converts between errors if the underlying type supports it
   pub fn convert<F>(e: Err<F>) -> Self
-    where E: From<F>
+  where
+    E: From<F>,
   {
-    e.map(Into::into)
+    e.map(crate::lib::std::convert::Into::into)
   }
 }
 
 impl<T> Err<(T, ErrorKind)> {
-  /// maps `Err<(T, ErrorKind)>` to `Err<(U, ErrorKind)>` with the given F: T -> U
+  /// Maps `Err<(T, ErrorKind)>` to `Err<(U, ErrorKind)>` with the given `F: T -> U`
   pub fn map_input<U, F>(self, f: F) -> Err<(U, ErrorKind)>
-    where F: FnOnce(T) -> U {
+  where
+    F: FnOnce(T) -> U,
+  {
     match self {
       Err::Incomplete(n) => Err::Incomplete(n),
       Err::Failure((input, k)) => Err::Failure((f(input), k)),
@@ -104,33 +150,71 @@
   }
 }
 
-#[cfg(feature = "std")]
+impl<T> Err<error::Error<T>> {
+  /// Maps `Err<error::Error<T>>` to `Err<error::Error<U>>` with the given `F: T -> U`
+  pub fn map_input<U, F>(self, f: F) -> Err<error::Error<U>>
+  where
+    F: FnOnce(T) -> U,
+  {
+    match self {
+      Err::Incomplete(n) => Err::Incomplete(n),
+      Err::Failure(error::Error { input, code }) => Err::Failure(error::Error {
+        input: f(input),
+        code,
+      }),
+      Err::Error(error::Error { input, code }) => Err::Error(error::Error {
+        input: f(input),
+        code,
+      }),
+    }
+  }
+}
+
+#[cfg(feature = "alloc")]
+use crate::lib::std::{borrow::ToOwned, string::String, vec::Vec};
+#[cfg(feature = "alloc")]
 impl Err<(&[u8], ErrorKind)> {
   /// Obtaining ownership
+  #[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
   pub fn to_owned(self) -> Err<(Vec<u8>, ErrorKind)> {
     self.map_input(ToOwned::to_owned)
   }
 }
 
-#[cfg(feature = "std")]
+#[cfg(feature = "alloc")]
 impl Err<(&str, ErrorKind)> {
-  /// automatically converts between errors if the underlying type supports it
+  /// Obtaining ownership
+  #[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
   pub fn to_owned(self) -> Err<(String, ErrorKind)> {
     self.map_input(ToOwned::to_owned)
   }
 }
 
+#[cfg(feature = "alloc")]
+impl Err<error::Error<&[u8]>> {
+  /// Obtaining ownership
+  #[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+  pub fn to_owned(self) -> Err<error::Error<Vec<u8>>> {
+    self.map_input(ToOwned::to_owned)
+  }
+}
+
+#[cfg(feature = "alloc")]
+impl Err<error::Error<&str>> {
+  /// Obtaining ownership
+  #[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+  pub fn to_owned(self) -> Err<error::Error<String>> {
+    self.map_input(ToOwned::to_owned)
+  }
+}
+
 impl<E: Eq> Eq for Err<E> {}
 
-#[cfg(feature = "std")]
-use std::fmt;
-
-#[cfg(feature = "std")]
 impl<E> fmt::Display for Err<E>
 where
   E: fmt::Debug,
 {
-  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     match self {
       Err::Incomplete(Needed::Size(u)) => write!(f, "Parsing requires {} bytes/chars", u),
       Err::Incomplete(Needed::Unknown) => write!(f, "Parsing requires more data"),
@@ -153,6 +237,225 @@
   }
 }
 
+/// All nom parsers implement this trait
+pub trait Parser<I, O, E> {
+  /// A parser takes in input type, and returns a `Result` containing
+  /// either the remaining input and the output value, or an error
+  fn parse(&mut self, input: I) -> IResult<I, O, E>;
+
+  /// Maps a function over the result of a parser
+  fn map<G, O2>(self, g: G) -> Map<Self, G, O>
+  where
+    G: Fn(O) -> O2,
+    Self: core::marker::Sized,
+  {
+    Map {
+      f: self,
+      g,
+      phantom: core::marker::PhantomData,
+    }
+  }
+
+  /// Creates a second parser from the output of the first one, then apply over the rest of the input
+  fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>
+  where
+    G: FnMut(O) -> H,
+    H: Parser<I, O2, E>,
+    Self: core::marker::Sized,
+  {
+    FlatMap {
+      f: self,
+      g,
+      phantom: core::marker::PhantomData,
+    }
+  }
+
+  /// Applies a second parser over the output of the first one
+  fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>
+  where
+    G: Parser<O, O2, E>,
+    Self: core::marker::Sized,
+  {
+    AndThen {
+      f: self,
+      g,
+      phantom: core::marker::PhantomData,
+    }
+  }
+
+  /// Applies a second parser after the first one, return their results as a tuple
+  fn and<G, O2>(self, g: G) -> And<Self, G>
+  where
+    G: Parser<I, O2, E>,
+    Self: core::marker::Sized,
+  {
+    And { f: self, g }
+  }
+
+  /// Applies a second parser over the input if the first one failed
+  fn or<G>(self, g: G) -> Or<Self, G>
+  where
+    G: Parser<I, O, E>,
+    Self: core::marker::Sized,
+  {
+    Or { f: self, g }
+  }
+
+  /// automatically converts the parser's output and error values to another type, as long as they
+  /// implement the `From` trait
+  fn into<O2: From<O>, E2: From<E>>(self) -> Into<Self, O, O2, E, E2>
+  where
+    Self: core::marker::Sized,
+  {
+    Into {
+      f: self,
+      phantom_out1: core::marker::PhantomData,
+      phantom_err1: core::marker::PhantomData,
+      phantom_out2: core::marker::PhantomData,
+      phantom_err2: core::marker::PhantomData,
+    }
+  }
+}
+
+impl<'a, I, O, E, F> Parser<I, O, E> for F
+where
+  F: FnMut(I) -> IResult<I, O, E> + 'a,
+{
+  fn parse(&mut self, i: I) -> IResult<I, O, E> {
+    self(i)
+  }
+}
+
+#[cfg(feature = "alloc")]
+use alloc::boxed::Box;
+
+#[cfg(feature = "alloc")]
+impl<'a, I, O, E> Parser<I, O, E> for Box<dyn Parser<I, O, E> + 'a> {
+  fn parse(&mut self, input: I) -> IResult<I, O, E> {
+    (**self).parse(input)
+  }
+}
+
+/// Implementation of `Parser::map`
+#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))]
+pub struct Map<F, G, O1> {
+  f: F,
+  g: G,
+  phantom: core::marker::PhantomData<O1>,
+}
+
+impl<'a, I, O1, O2, E, F: Parser<I, O1, E>, G: Fn(O1) -> O2> Parser<I, O2, E> for Map<F, G, O1> {
+  fn parse(&mut self, i: I) -> IResult<I, O2, E> {
+    match self.f.parse(i) {
+      Err(e) => Err(e),
+      Ok((i, o)) => Ok((i, (self.g)(o))),
+    }
+  }
+}
+
+/// Implementation of `Parser::flat_map`
+#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))]
+pub struct FlatMap<F, G, O1> {
+  f: F,
+  g: G,
+  phantom: core::marker::PhantomData<O1>,
+}
+
+impl<'a, I, O1, O2, E, F: Parser<I, O1, E>, G: Fn(O1) -> H, H: Parser<I, O2, E>> Parser<I, O2, E>
+  for FlatMap<F, G, O1>
+{
+  fn parse(&mut self, i: I) -> IResult<I, O2, E> {
+    let (i, o1) = self.f.parse(i)?;
+    (self.g)(o1).parse(i)
+  }
+}
+
+/// Implementation of `Parser::and_then`
+#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))]
+pub struct AndThen<F, G, O1> {
+  f: F,
+  g: G,
+  phantom: core::marker::PhantomData<O1>,
+}
+
+impl<'a, I, O1, O2, E, F: Parser<I, O1, E>, G: Parser<O1, O2, E>> Parser<I, O2, E>
+  for AndThen<F, G, O1>
+{
+  fn parse(&mut self, i: I) -> IResult<I, O2, E> {
+    let (i, o1) = self.f.parse(i)?;
+    let (_, o2) = self.g.parse(o1)?;
+    Ok((i, o2))
+  }
+}
+
+/// Implementation of `Parser::and`
+#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))]
+pub struct And<F, G> {
+  f: F,
+  g: G,
+}
+
+impl<'a, I, O1, O2, E, F: Parser<I, O1, E>, G: Parser<I, O2, E>> Parser<I, (O1, O2), E>
+  for And<F, G>
+{
+  fn parse(&mut self, i: I) -> IResult<I, (O1, O2), E> {
+    let (i, o1) = self.f.parse(i)?;
+    let (i, o2) = self.g.parse(i)?;
+    Ok((i, (o1, o2)))
+  }
+}
+
+/// Implementation of `Parser::or`
+#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))]
+pub struct Or<F, G> {
+  f: F,
+  g: G,
+}
+
+impl<'a, I: Clone, O, E: crate::error::ParseError<I>, F: Parser<I, O, E>, G: Parser<I, O, E>>
+  Parser<I, O, E> for Or<F, G>
+{
+  fn parse(&mut self, i: I) -> IResult<I, O, E> {
+    match self.f.parse(i.clone()) {
+      Err(Err::Error(e1)) => match self.g.parse(i) {
+        Err(Err::Error(e2)) => Err(Err::Error(e1.or(e2))),
+        res => res,
+      },
+      res => res,
+    }
+  }
+}
+
+/// Implementation of `Parser::into`
+#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))]
+pub struct Into<F, O1, O2: From<O1>, E1, E2: From<E1>> {
+  f: F,
+  phantom_out1: core::marker::PhantomData<O1>,
+  phantom_err1: core::marker::PhantomData<E1>,
+  phantom_out2: core::marker::PhantomData<O2>,
+  phantom_err2: core::marker::PhantomData<E2>,
+}
+
+impl<
+    'a,
+    I: Clone,
+    O1,
+    O2: From<O1>,
+    E1,
+    E2: crate::error::ParseError<I> + From<E1>,
+    F: Parser<I, O1, E1>,
+  > Parser<I, O2, E2> for Into<F, O1, O2, E1, E2>
+{
+  fn parse(&mut self, i: I) -> IResult<I, O2, E2> {
+    match self.f.parse(i) {
+      Ok((i, o)) => Ok((i, o.into())),
+      Err(Err::Error(e)) => Err(Err::Error(e.into())),
+      Err(Err::Failure(e)) => Err(Err::Failure(e.into())),
+      Err(Err::Incomplete(e)) => Err(Err::Incomplete(e)),
+    }
+  }
+}
+
 #[cfg(test)]
 mod tests {
   use super::*;
@@ -171,8 +474,8 @@
   fn size_test() {
     assert_size!(IResult<&[u8], &[u8], (&[u8], u32)>, 40);
     assert_size!(IResult<&str, &str, u32>, 40);
-    assert_size!(Needed, 16);
-    assert_size!(Err<u32>, 24);
+    assert_size!(Needed, 8);
+    assert_size!(Err<u32>, 16);
     assert_size!(ErrorKind, 1);
   }
 
@@ -181,5 +484,4 @@
     let e = Err::Error(1);
     assert_eq!(e.map(|v| v + 1), Err::Error(2));
   }
-
 }
diff --git a/src/lib.rs b/src/lib.rs
index c37410d..1ce115a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,8 +6,6 @@
 //! ## Example
 //!
 //! ```rust
-//! extern crate nom;
-//!
 //! use nom::{
 //!   IResult,
 //!   bytes::complete::{tag, take_while_m_n},
@@ -55,9 +53,9 @@
 //! The code is available on [Github](https://github.com/Geal/nom)
 //!
 //! There are a few [guides](https://github.com/Geal/nom/tree/master/doc) with more details
-//! about [the design of nom macros](https://github.com/Geal/nom/blob/master/doc/how_nom_macros_work.md),
-//! [how to write parsers](https://github.com/Geal/nom/blob/master/doc/making_a_new_parser_from_scratch.md),
+//! about [how to write parsers](https://github.com/Geal/nom/blob/master/doc/making_a_new_parser_from_scratch.md),
 //! or the [error management system](https://github.com/Geal/nom/blob/master/doc/error_management.md).
+//! You can also check out the [recipes] module that contains examples of common patterns.
 //!
 //! **Looking for a specific combinator? Read the
 //! ["choose a combinator" guide](https://github.com/Geal/nom/blob/master/doc/choosing_a_combinator.md)**
@@ -65,8 +63,6 @@
 //! If you are upgrading to nom 5.0, please read the
 //! [migration document](https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_5.md).
 //!
-//! See also the [FAQ](https://github.com/Geal/nom/blob/master/doc/FAQ.md).
-//!
 //! ## Parser combinators
 //!
 //! Parser combinators are an approach to parsers that is very different from
@@ -81,11 +77,11 @@
 //!
 //! This gives us a few advantages:
 //!
-//! - the parsers are small and easy to write
-//! - the parsers components are easy to reuse (if they're general enough, please add them to nom!)
-//! - the parsers components are easy to test separately (unit tests and property-based tests)
-//! - the parser combination code looks close to the grammar you would have written
-//! - you can build partial parsers, specific to the data you need at the moment, and ignore the rest
+//! - The parsers are small and easy to write
+//! - The parsers components are easy to reuse (if they're general enough, please add them to nom!)
+//! - The parsers components are easy to test separately (unit tests and property-based tests)
+//! - The parser combination code looks close to the grammar you would have written
+//! - You can build partial parsers, specific to the data you need at the moment, and ignore the rest
 //!
 //! Here is an example of one such parser, to recognize text between parentheses:
 //!
@@ -110,15 +106,12 @@
 //! Here is another parser, written without using nom's combinators this time:
 //!
 //! ```rust
-//! #[macro_use]
-//! extern crate nom;
-//!
 //! use nom::{IResult, Err, Needed};
 //!
 //! # fn main() {
 //! fn take4(i: &[u8]) -> IResult<&[u8], &[u8]>{
 //!   if i.len() < 4 {
-//!     Err(Err::Incomplete(Needed::Size(4)))
+//!     Err(Err::Incomplete(Needed::new(4)))
 //!   } else {
 //!     Ok((&i[4..], &i[0..4]))
 //!   }
@@ -129,7 +122,7 @@
 //! This function takes a byte array as input, and tries to consume 4 bytes.
 //! Writing all the parsers manually, like this, is dangerous, despite Rust's
 //! safety features. There are still a lot of mistakes one can make. That's why
-//! nom provides a list of function and macros to help in developing parsers.
+//! nom provides a list of functions to help in developing parsers.
 //!
 //! With functions, you would write it like this:
 //!
@@ -140,43 +133,25 @@
 //! }
 //! ```
 //!
-//! With macros, you would write it like this:
-//!
-//! ```rust
-//! #[macro_use]
-//! extern crate nom;
-//!
-//! # fn main() {
-//! named!(take4, take!(4));
-//! # }
-//! ```
-//!
-//! nom has used macros for combinators from versions 1 to 4, and from version
-//! 5, it proposes new combinators as functions, but still allows the macros style
-//! (macros have been rewritten to use the functions under the hood).
-//! For new parsers, we recommend using the functions instead of macros, since
-//! rustc messages will be much easier to understand.
-//!
-//!
 //! A parser in nom is a function which, for an input type `I`, an output type `O`
 //! and an optional error type `E`, will have the following signature:
 //!
-//! ```rust,ignore
+//! ```rust,compile_fail
 //! fn parser(input: I) -> IResult<I, O, E>;
 //! ```
 //!
-//! Or like this, if you don't want to specify a custom error type (it will be `u32` by default):
+//! Or like this, if you don't want to specify a custom error type (it will be `(I, ErrorKind)` by default):
 //!
-//! ```rust,ignore
+//! ```rust,compile_fail
 //! fn parser(input: I) -> IResult<I, O>;
 //! ```
 //!
 //! `IResult` is an alias for the `Result` type:
 //!
 //! ```rust
-//! use nom::{Needed, error::ErrorKind};
+//! use nom::{Needed, error::Error};
 //!
-//! type IResult<I, O, E = (I,ErrorKind)> = Result<(I, O), Err<E>>;
+//! type IResult<I, O, E = Error<I>> = Result<(I, O), Err<E>>;
 //!
 //! enum Err<E> {
 //!   Incomplete(Needed),
@@ -187,14 +162,13 @@
 //!
 //! It can have the following values:
 //!
-//! - a correct result `Ok((I,O))` with the first element being the remaining of the input (not parsed yet), and the second the output value;
-//! - an error `Err(Err::Error(c))` with `c` an error that can be built from the input position and a parser specific error
-//! - an error `Err(Err::Incomplete(Needed))` indicating that more input is necessary. `Needed` can indicate how much data is needed
-//! - an error `Err(Err::Failure(c))`. It works like the `Error` case, except it indicates an unrecoverable error: we cannot backtrack and test another parser
+//! - A correct result `Ok((I,O))` with the first element being the remaining of the input (not parsed yet), and the second the output value;
+//! - An error `Err(Err::Error(c))` with `c` an error that can be built from the input position and a parser specific error
+//! - An error `Err(Err::Incomplete(Needed))` indicating that more input is necessary. `Needed` can indicate how much data is needed
+//! - An error `Err(Err::Failure(c))`. It works like the `Error` case, except it indicates an unrecoverable error: We cannot backtrack and test another parser
 //!
 //! Please refer to the ["choose a combinator" guide](https://github.com/Geal/nom/blob/master/doc/choosing_a_combinator.md) for an exhaustive list of parsers.
 //! See also the rest of the documentation [here](https://github.com/Geal/nom/blob/master/doc).
-//! .
 //!
 //! ## Making new parsers with function combinators
 //!
@@ -230,7 +204,7 @@
 //! use nom::branch::alt;
 //! use nom::bytes::complete::tag;
 //!
-//! let alt_tags = alt((tag("abcd"), tag("efgh")));
+//! let mut alt_tags = alt((tag("abcd"), tag("efgh")));
 //!
 //! assert_eq!(alt_tags(&b"abcdxxx"[..]), Ok((&b"xxx"[..], &b"abcd"[..])));
 //! assert_eq!(alt_tags(&b"efghxxx"[..]), Ok((&b"xxx"[..], &b"efgh"[..])));
@@ -253,7 +227,6 @@
 //! **`many0`** applies a parser 0 or more times, and returns a vector of the aggregated results:
 //!
 //! ```rust
-//! # #[macro_use] extern crate nom;
 //! # #[cfg(feature = "alloc")]
 //! # fn main() {
 //! use nom::{IResult, multi::many0, bytes::complete::tag};
@@ -274,11 +247,11 @@
 //! # fn main() {}
 //! ```
 //!
-//! Here are some basic combining macros available:
+//! Here are some basic combinators available:
 //!
-//! - **`opt`**: will make the parser optional (if it returns the `O` type, the new parser returns `Option<O>`)
-//! - **`many0`**: will apply the parser 0 or more times (if it returns the `O` type, the new parser returns `Vec<O>`)
-//! - **`many1`**: will apply the parser 1 or more times
+//! - **`opt`**: Will make the parser optional (if it returns the `O` type, the new parser returns `Option<O>`)
+//! - **`many0`**: Will apply the parser 0 or more times (if it returns the `O` type, the new parser returns `Vec<O>`)
+//! - **`many1`**: Will apply the parser 1 or more times
 //!
 //! There are more complex (and more useful) parsers like `tuple!`, which is
 //! used to apply a series of parsers then assemble their results.
@@ -286,14 +259,13 @@
 //! Example with `tuple`:
 //!
 //! ```rust
-//! # #[macro_use] extern crate nom;
 //! # fn main() {
 //! use nom::{error::ErrorKind, Needed,
 //! number::streaming::be_u16,
 //! bytes::streaming::{tag, take},
 //! sequence::tuple};
 //!
-//! let tpl = tuple((be_u16, take(3u8), tag("fg")));
+//! let mut tpl = tuple((be_u16, take(3u8), tag("fg")));
 //!
 //! assert_eq!(
 //!   tpl(&b"abcdefgh"[..]),
@@ -302,7 +274,7 @@
 //!     (0x6162u16, &b"cde"[..], &b"fg"[..])
 //!   ))
 //! );
-//! assert_eq!(tpl(&b"abcde"[..]), Err(nom::Err::Incomplete(Needed::Size(2))));
+//! assert_eq!(tpl(&b"abcde"[..]), Err(nom::Err::Incomplete(Needed::new(2))));
 //! let input = &b"abcdejk"[..];
 //! assert_eq!(tpl(input), Err(nom::Err::Error((&input[5..], ErrorKind::Tag))));
 //! # }
@@ -312,7 +284,6 @@
 //! thanks to the `?` operator:
 //!
 //! ```rust
-//! # #[macro_use] extern crate nom;
 //! # fn main() {
 //! use nom::{IResult, bytes::complete::tag};
 //!
@@ -356,7 +327,7 @@
 //! Here is how it works in practice:
 //!
 //! ```rust
-//! use nom::{IResult, Err, Needed, error::ErrorKind, bytes, character};
+//! use nom::{IResult, Err, Needed, error::{Error, ErrorKind}, bytes, character};
 //!
 //! fn take_streaming(i: &[u8]) -> IResult<&[u8], &[u8]> {
 //!   bytes::streaming::take(4u8)(i)
@@ -372,10 +343,10 @@
 //!
 //! // if the input is smaller than 4 bytes, the streaming parser
 //! // will return `Incomplete` to indicate that we need more data
-//! assert_eq!(take_streaming(&b"abc"[..]), Err(Err::Incomplete(Needed::Size(4))));
+//! assert_eq!(take_streaming(&b"abc"[..]), Err(Err::Incomplete(Needed::new(1))));
 //!
 //! // but the complete parser will return an error
-//! assert_eq!(take_complete(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
+//! assert_eq!(take_complete(&b"abc"[..]), Err(Err::Error(Error::new(&b"abc"[..], ErrorKind::Eof))));
 //!
 //! // the alpha0 function recognizes 0 or more alphabetic characters
 //! fn alpha0_streaming(i: &str) -> IResult<&str, &str> {
@@ -393,121 +364,104 @@
 //! // but when there's no limit, the streaming version returns `Incomplete`, because it cannot
 //! // know if more input data should be recognized. The whole input could be "abcd;", or
 //! // "abcde;"
-//! assert_eq!(alpha0_streaming("abcd"), Err(Err::Incomplete(Needed::Size(1))));
+//! assert_eq!(alpha0_streaming("abcd"), Err(Err::Incomplete(Needed::new(1))));
 //!
 //! // while the complete version knows that all of the data is there
 //! assert_eq!(alpha0_complete("abcd"), Ok(("", "abcd")));
 //! ```
-//! **Going further:** read the [guides](https://github.com/Geal/nom/tree/master/doc)!
-#![cfg_attr(all(not(feature = "std"), feature = "alloc"), feature(alloc))]
+//! **Going further:** Read the [guides](https://github.com/Geal/nom/tree/master/doc),
+//! check out the [recipes]!
 #![cfg_attr(not(feature = "std"), no_std)]
-#![cfg_attr(feature = "cargo-clippy", allow(doc_markdown))]
+#![cfg_attr(feature = "cargo-clippy", allow(clippy::doc_markdown))]
 #![cfg_attr(nightly, feature(test))]
+#![cfg_attr(feature = "docsrs", feature(doc_cfg))]
+#![cfg_attr(feature = "docsrs", feature(extended_key_value_attributes))]
 #![deny(missing_docs)]
-#![warn(missing_doc_code_examples)]
-
-#[cfg(all(not(feature = "std"), feature = "alloc"))]
+#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))]
+#[cfg(feature = "alloc")]
 #[macro_use]
 extern crate alloc;
-#[cfg(feature = "regexp_macros")]
-#[macro_use]
-extern crate lazy_static;
-extern crate memchr;
-#[cfg(feature = "regexp")]
-pub extern crate regex;
-#[cfg(feature = "lexical")]
-extern crate lexical_core;
-#[cfg(nightly)]
-extern crate test;
-#[cfg(test)]
+#[cfg(doctest)]
 extern crate doc_comment;
 
-//FIXME: reactivate doctest once https://github.com/rust-lang/rust/issues/62210 is done
-//#[cfg(doctest)]
-//doc_comment::doctest!("../README.md");
+#[cfg(nightly)]
+extern crate test;
+
+#[cfg(doctest)]
+doc_comment::doctest!("../README.md");
 
 /// Lib module to re-export everything needed from `std` or `core`/`alloc`. This is how `serde` does
 /// it, albeit there it is not public.
+#[cfg_attr(nightly, allow(rustdoc::missing_doc_code_examples))]
 pub mod lib {
   /// `std` facade allowing `std`/`core` to be interchangeable. Reexports `alloc` crate optionally,
   /// as well as `core` or `std`
   #[cfg(not(feature = "std"))]
+  #[cfg_attr(nightly, allow(rustdoc::missing_doc_code_examples))]
   /// internal std exports for no_std compatibility
   pub mod std {
-    #[cfg(feature = "alloc")]
-    #[cfg_attr(feature = "alloc", macro_use)]
-    pub use alloc::{boxed, string, vec};
+    #[doc(hidden)]
+    #[cfg(not(feature = "alloc"))]
+    pub use core::borrow;
 
-    pub use core::{cmp, convert, fmt, iter, mem, ops, option, result, slice, str, borrow};
+    #[cfg(feature = "alloc")]
+    #[doc(hidden)]
+    pub use alloc::{borrow, boxed, string, vec};
+
+    #[doc(hidden)]
+    pub use core::{cmp, convert, fmt, iter, mem, ops, option, result, slice, str};
 
     /// internal reproduction of std prelude
+    #[doc(hidden)]
     pub mod prelude {
       pub use core::prelude as v1;
     }
   }
 
   #[cfg(feature = "std")]
+  #[cfg_attr(nightly, allow(rustdoc::missing_doc_code_examples))]
   /// internal std exports for no_std compatibility
   pub mod std {
-    pub use std::{alloc, boxed, cmp, collections, convert, fmt, hash, iter, mem, ops, option, result, slice, str, string, vec, borrow};
+    #[doc(hidden)]
+    pub use std::{
+      alloc, borrow, boxed, cmp, collections, convert, fmt, hash, iter, mem, ops, option, result,
+      slice, str, string, vec,
+    };
 
     /// internal reproduction of std prelude
+    #[doc(hidden)]
     pub mod prelude {
       pub use std::prelude as v1;
     }
   }
-
-  #[cfg(feature = "regexp")]
-  pub use regex;
 }
 
-pub use self::traits::*;
-pub use self::util::*;
-pub use self::internal::*;
-pub use self::methods::*;
 pub use self::bits::*;
-pub use self::whitespace::*;
+pub use self::internal::*;
+pub use self::traits::*;
 
-#[cfg(feature = "regexp")]
-pub use self::regexp::*;
 pub use self::str::*;
 
 #[macro_use]
-mod util;
-
-#[macro_use]
 pub mod error;
 
-#[macro_use]
+pub mod combinator;
 mod internal;
 mod traits;
 #[macro_use]
-pub mod combinator;
-#[macro_use]
 pub mod branch;
-#[macro_use]
-pub mod sequence;
-#[macro_use]
 pub mod multi;
-#[macro_use]
-pub mod methods;
+pub mod sequence;
 
-#[macro_use]
-pub mod bytes;
-#[macro_use]
 pub mod bits;
+pub mod bytes;
 
-#[macro_use]
 pub mod character;
 
-#[macro_use]
-pub mod whitespace;
-
-#[cfg(feature = "regexp")]
-#[macro_use]
-mod regexp;
-
 mod str;
 
-#[macro_use]
 pub mod number;
+
+#[cfg(feature = "docsrs")]
+#[cfg_attr(feature = "docsrs", cfg_attr(feature = "docsrs", doc = include_str!("../doc/nom_recipes.md")))]
+pub mod recipes {}
diff --git a/src/methods.rs b/src/methods.rs
deleted file mode 100644
index 520f1e8..0000000
--- a/src/methods.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-//! method combinators
-
-/// do not use: method combinators moved to the nom-methods crate
-#[macro_export]
-macro_rules! method (
-  ($($args:tt)*) => (compile_error!("method combinators moved to the nom-methods crate"););
-);
-
-/// do not use: method combinators moved to the nom-methods crate
-#[macro_export]
-macro_rules! call_m (
-  ($($args:tt)*) => (compile_error!("method combinators moved to the nom-methods crate"););
-);
-
-/// do not use: method combinators moved to the nom-methods crate
-#[macro_export]
-macro_rules! apply_m (
-  ($($args:tt)*) => (compile_error!("method combinators moved to the nom-methods crate"););
-);
-
diff --git a/src/multi/macros.rs b/src/multi/macros.rs
deleted file mode 100644
index 10b66b8..0000000
--- a/src/multi/macros.rs
+++ /dev/null
@@ -1,988 +0,0 @@
-//! Parsers for applying parsers multiple times
-
-/// `separated_list!(I -> IResult<I,T>, I -> IResult<I,O>) => I -> IResult<I, Vec<O>>`
-/// separated_list(sep, X) returns a Vec<X>
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
-/// use nom::multi::separated_list;
-/// use nom::bytes::complete::tag;
-///
-/// # fn main() {
-/// named!(parser<&str, Vec<&str>>, separated_list!(tag("|"), tag("abc")));
-///
-/// assert_eq!(parser("abc|abc|abc"), Ok(("", vec!["abc", "abc", "abc"])));
-/// assert_eq!(parser("abc123abc"), Ok(("123abc", vec!["abc"])));
-/// assert_eq!(parser("abc|def"), Ok(("|def", vec!["abc"])));
-/// assert_eq!(parser(""), Ok(("", vec![])));
-/// assert_eq!(parser("def|abc"), Ok(("def|abc", vec![])));
-/// # }
-/// ```
-#[cfg(feature = "alloc")]
-#[macro_export(local_inner_macros)]
-macro_rules! separated_list(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    separated_list!($i, |i| $submac!(i, $($args)*), |i| $submac2!(i, $($args2)*))
-  );
-
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    separated_list!($i, |i| $submac!(i, $($args)*), $g);
-  );
-
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    separated_list!($i, $f, |i| $submac!(i, $($args)*));
-  );
-
-  ($i:expr, $f:expr, $g:expr) => (
-    $crate::multi::separated_listc($i, $f, $g)
-  );
-);
-
-/// `separated_nonempty_list!(I -> IResult<I,T>, I -> IResult<I,O>) => I -> IResult<I, Vec<O>>`
-/// separated_nonempty_list(sep, X) returns a Vec<X>
-///
-/// it will return an error if there is no element in the list
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
-/// use nom::multi::separated_nonempty_list;
-/// use nom::bytes::complete::tag;
-///
-/// # fn main() {
-/// named!(parser<&str, Vec<&str>>, separated_nonempty_list!(tag("|"), tag("abc")));
-///
-/// assert_eq!(parser("abc|abc|abc"), Ok(("", vec!["abc", "abc", "abc"])));
-/// assert_eq!(parser("abc123abc"), Ok(("123abc", vec!["abc"])));
-/// assert_eq!(parser("abc|def"), Ok(("|def", vec!["abc"])));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
-/// assert_eq!(parser("def|abc"), Err(Err::Error(("def|abc", ErrorKind::Tag))));
-/// # }
-/// ```
-#[cfg(feature = "alloc")]
-#[macro_export(local_inner_macros)]
-macro_rules! separated_nonempty_list(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    separated_nonempty_list!($i, |i| $submac!(i, $($args)*), |i| $submac2!(i, $($args2)*))
-  );
-
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    separated_nonempty_list!($i, |i| $submac!(i, $($args)*), $g);
-  );
-
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    separated_nonempty_list!($i, $f, |i| $submac!(i, $($args)*));
-  );
-
-  ($i:expr, $f:expr, $g:expr) => (
-    $crate::multi::separated_nonempty_listc($i, $f, $g)
-  );
-);
-
-/// `many0!(I -> IResult<I,O>) => I -> IResult<I, Vec<O>>`
-/// Applies the parser 0 or more times and returns the list of results in a Vec.
-///
-/// The embedded parser may return Incomplete.
-///
-/// `many0` will only return `Error` if the embedded parser does not consume any input
-/// (to avoid infinite loops).
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(multi<&[u8], Vec<&[u8]> >, many0!( tag!( "abcd" ) ) );
-///
-///  let a = b"abcdabcdefgh";
-///  let b = b"azerty";
-///
-///  let res = vec![&b"abcd"[..], &b"abcd"[..]];
-///  assert_eq!(multi(&a[..]),Ok((&b"efgh"[..], res)));
-///  assert_eq!(multi(&b[..]),Ok((&b"azerty"[..], Vec::new())));
-/// # }
-/// ```
-///
-#[cfg(feature = "alloc")]
-#[macro_export(local_inner_macros)]
-macro_rules! many0(
-  ($i:expr, $submac:ident!( $($args:tt)* )) => (
-    many0!($i, |i| $submac!(i, $($args)*))
-  );
-  ($i:expr, $f:expr) => (
-    $crate::multi::many0c($i, $f)
-  );
-);
-
-/// `many1!(I -> IResult<I,O>) => I -> IResult<I, Vec<O>>`
-/// Applies the parser 1 or more times and returns the list of results in a Vec
-///
-/// the embedded parser may return Incomplete
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-///  named!(multi<&[u8], Vec<&[u8]> >, many1!( tag!( "abcd" ) ) );
-///
-///  let a = b"abcdabcdefgh";
-///  let b = b"azerty";
-///
-///  let res = vec![&b"abcd"[..], &b"abcd"[..]];
-///  assert_eq!(multi(&a[..]), Ok((&b"efgh"[..], res)));
-///  assert_eq!(multi(&b[..]), Err(Err::Error(error_position!(&b[..], ErrorKind::Tag))));
-/// # }
-/// ```
-#[cfg(feature = "alloc")]
-#[macro_export(local_inner_macros)]
-macro_rules! many1(
-  ($i:expr, $submac:ident!( $($args:tt)* )) => (
-    many1!($i, |i| $submac!(i, $($args)*))
-  );
-  ($i:expr, $f:expr) => (
-    $crate::multi::many1c($i, $f)
-  );
-);
-
-/// `many_till!(I -> IResult<I,O>, I -> IResult<I,P>) => I -> IResult<I, (Vec<O>, P)>`
-/// Applies the first parser until the second applies. Returns a tuple containing the list
-/// of results from the first in a Vec and the result of the second.
-///
-/// The first embedded parser may return Incomplete
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-///    named!(multi<&[u8], (Vec<&[u8]>, &[u8]) >, many_till!( tag!( "abcd" ), tag!( "efgh" ) ) );
-///
-///    let a = b"abcdabcdefghabcd";
-///    let b = b"efghabcd";
-///    let c = b"azerty";
-///
-///    let res_a = (vec![&b"abcd"[..], &b"abcd"[..]], &b"efgh"[..]);
-///    let res_b: (Vec<&[u8]>, &[u8]) = (Vec::new(), &b"efgh"[..]);
-///    assert_eq!(multi(&a[..]),Ok((&b"abcd"[..], res_a)));
-///    assert_eq!(multi(&b[..]),Ok((&b"abcd"[..], res_b)));
-///    assert_eq!(multi(&c[..]), Err(Err::Error(error_node_position!(&c[..], ErrorKind::ManyTill,
-///      error_position!(&c[..], ErrorKind::Tag)))));
-/// # }
-/// ```
-#[cfg(feature = "alloc")]
-#[macro_export(local_inner_macros)]
-macro_rules! many_till(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    many_till!($i, |i| $submac!(i, $($args)*), |i| $submac2!(i, $($args2)*))
-  );
-
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    many_till!($i, |i| $submac!(i, $($args)*), $g);
-  );
-
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    many_till!($i, $f, |i| $submac!(i, $($args)*));
-  );
-
-  ($i:expr, $f:expr, $g:expr) => (
-    $crate::multi::many_tillc($i, $f, $g)
-  );
-);
-
-/// `many_m_n!(usize, usize, I -> IResult<I,O>) => I -> IResult<I, Vec<O>>`
-/// Applies the parser between m and n times (n included) and returns the list of
-/// results in a Vec
-///
-/// the embedded parser may return Incomplete
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-///  named!(multi<&[u8], Vec<&[u8]> >, many_m_n!(2, 4, tag!( "abcd" ) ) );
-///
-///  let a = b"abcdefgh";
-///  let b = b"abcdabcdefgh";
-///  let c = b"abcdabcdabcdabcdabcdefgh";
-///
-///  assert_eq!(multi(&a[..]), Err(Err::Error(error_position!(&b"efgh"[..], ErrorKind::Tag))));
-///  let res = vec![&b"abcd"[..], &b"abcd"[..]];
-///  assert_eq!(multi(&b[..]),Ok((&b"efgh"[..], res)));
-///  let res2 = vec![&b"abcd"[..], &b"abcd"[..], &b"abcd"[..], &b"abcd"[..]];
-///  assert_eq!(multi(&c[..]),Ok((&b"abcdefgh"[..], res2)));
-/// # }
-/// ```
-#[cfg(feature = "alloc")]
-#[macro_export(local_inner_macros)]
-macro_rules! many_m_n(
-  ($i:expr, $m:expr, $n: expr, $submac:ident!( $($args:tt)* )) => (
-    many_m_n!($i, $m, $n, |i| $submac!(i, $($args)*))
-  );
-  ($i:expr, $m:expr, $n: expr, $f:expr) => (
-    $crate::multi::many_m_nc($i, $m, $n, $f)
-  );
-);
-
-/// `many0_count!(I -> IResult<I,O>) => I -> IResult<I, usize>`
-/// Applies the parser 0 or more times and returns the number of times the parser was applied.
-///
-/// `many0_count` will only return `Error` if the embedded parser does not consume any input
-/// (to avoid infinite loops).
-///
-/// ```
-/// #[macro_use] extern crate nom;
-/// use nom::character::streaming::digit1;
-///
-/// named!(number<&[u8], usize>, many0_count!(pair!(digit1, tag!(","))));
-///
-/// fn main() {
-///     assert_eq!(number(&b"123,45,abc"[..]), Ok((&b"abc"[..], 2)));
-/// }
-/// ```
-///
-#[macro_export]
-macro_rules! many0_count {
-  ($i:expr, $submac:ident!( $($args:tt)* )) => (
-    $crate::multi::many0_countc($i, |i| $submac!(i, $($args)*))
-  );
-
-  ($i:expr, $f:expr) => (
-    $crate::multi::many0_countc($i, $f)
-  );
-}
-
-/// `many1_count!(I -> IResult<I,O>) => I -> IResult<I, usize>`
-/// Applies the parser 1 or more times and returns the number of times the parser was applied.
-///
-/// ```
-/// #[macro_use] extern crate nom;
-/// use nom::character::streaming::digit1;
-///
-/// named!(number<&[u8], usize>, many1_count!(pair!(digit1, tag!(","))));
-///
-/// fn main() {
-///     assert_eq!(number(&b"123,45,abc"[..]), Ok((&b"abc"[..], 2)));
-/// }
-/// ```
-///
-#[macro_export]
-macro_rules! many1_count {
-  ($i:expr, $submac:ident!( $($args:tt)* )) => (
-    $crate::multi::many1_countc($i, |i| $submac!(i, $($args)*))
-  );
-
-  ($i:expr, $f:expr) => (
-    $crate::multi::many1_countc($i, $f)
-  );
-}
-
-/// `count!(I -> IResult<I,O>, nb) => I -> IResult<I, Vec<O>>`
-/// Applies the child parser a specified number of times
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-///  named!(counter< Vec<&[u8]> >, count!( tag!( "abcd" ), 2 ) );
-///
-///  let a = b"abcdabcdabcdef";
-///  let b = b"abcdefgh";
-///  let res = vec![&b"abcd"[..], &b"abcd"[..]];
-///
-///  assert_eq!(counter(&a[..]),Ok((&b"abcdef"[..], res)));
-///  assert_eq!(counter(&b[..]), Err(Err::Error(error_position!(&b"efgh"[..], ErrorKind::Tag))));
-/// # }
-/// ```
-///
-#[cfg(feature = "alloc")]
-#[macro_export(local_inner_macros)]
-macro_rules! count(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $count: expr) => (
-    count!($i, |i| $submac!(i, $($args)*), $count)
-  );
-  ($i:expr, $f:expr, $count: expr) => (
-    $crate::multi::count($f, $count)($i)
-  );
-);
-
-/// `length_count!(I -> IResult<I, nb>, I -> IResult<I,O>) => I -> IResult<I, Vec<O>>`
-/// gets a number from the first parser, then applies the second parser that many times
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, Needed};
-/// # use nom::error::ErrorKind;
-/// use nom::number::complete::be_u8;
-/// # fn main() {
-/// named!(parser<Vec<&[u8]>>, length_count!(be_u8, tag!("abc")));
-///
-/// assert_eq!(parser(&b"\x02abcabcabc"[..]), Ok(((&b"abc"[..], vec![&b"abc"[..], &b"abc"[..]]))));
-/// assert_eq!(parser(&b"\x04abcabcabc"[..]), Err(Err::Incomplete(Needed::Size(3))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-#[cfg(feature = "alloc")]
-macro_rules! length_count(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::Err;
-
-      match $submac!($i, $($args)*) {
-        Err(e)     => Err(Err::convert(e)),
-        Ok((i, o)) => {
-          match count!(i, $submac2!($($args2)*), o as usize) {
-            Err(e)       => Err(Err::convert(e)),
-            Ok((i2, o2)) => Ok((i2, o2))
-          }
-        }
-      }
-    }
-  );
-
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    length_count!($i, $submac!($($args)*), call!($g));
-  );
-
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    length_count!($i, call!($f), $submac!($($args)*));
-  );
-
-  ($i:expr, $f:expr, $g:expr) => (
-    length_count!($i, call!($f), call!($g));
-  );
-);
-
-/// `length_data!(I -> IResult<I, nb>) => O`
-///
-/// `length_data` gets a number from the first parser, then takes a subslice of the input
-/// of that size and returns that subslice
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, Needed};
-/// # use nom::error::ErrorKind;
-/// use nom::number::complete::be_u8;
-/// # fn main() {
-/// named!(parser, length_data!(be_u8));
-///
-/// assert_eq!(parser(&b"\x06abcabcabc"[..]), Ok((&b"abc"[..], &b"abcabc"[..])));
-/// assert_eq!(parser(&b"\x06abc"[..]), Err(Err::Incomplete(Needed::Size(6))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! length_data(
-  ($i:expr, $submac:ident!( $($args:tt)* )) => ({
-    $crate::multi::length_data(|i| $submac!(i, $($args)*))($i)
-  });
-
-  ($i:expr, $f:expr) => (
-    $crate::multi::length_data($f)($i)
-  );
-);
-
-/// `length_value!(I -> IResult<I, nb>, I -> IResult<I,O>) => I -> IResult<I, O>`
-///
-/// Gets a number from the first parser, takes a subslice of the input of that size,
-/// then applies the second parser on that subslice. If the second parser returns
-/// `Incomplete`, `length_value` will return an error
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, Needed};
-/// # use nom::error::ErrorKind;
-/// use nom::number::complete::be_u8;
-/// use nom::character::complete::alpha0;
-/// use nom::bytes::complete::tag;
-/// # fn main() {
-/// named!(parser, length_value!(be_u8, alpha0));
-///
-/// assert_eq!(parser(&b"\x06abcabcabc"[..]), Ok((&b"abc"[..], &b"abcabc"[..])));
-/// assert_eq!(parser(&b"\x06abc"[..]), Err(Err::Incomplete(Needed::Size(6))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! length_value(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    length_value!($i, |i| $submac!(i, $($args)*), |i| $submac2!(i, $($args2)*))
-  );
-
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    length_value!($i, |i| $submac!(i, $($args)*), $g);
-  );
-
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    length_value!($i, $f, |i| $submac!(i, $($args)*));
-  );
-
-  ($i:expr, $f:expr, $g:expr) => (
-    $crate::multi::length_valuec($i, $f, $g);
-  );
-);
-
-/// `fold_many0!(I -> IResult<I,O>, R, Fn(R, O) -> R) => I -> IResult<I, R>`
-/// Applies the parser 0 or more times and folds the list of return values
-///
-/// the embedded parser may return Incomplete
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///  named!(multi<&[u8], Vec<&[u8]> >,
-///    fold_many0!( tag!( "abcd" ), Vec::new(), |mut acc: Vec<_>, item| {
-///      acc.push(item);
-///      acc
-///  }));
-///
-///  let a = b"abcdabcdefgh";
-///  let b = b"azerty";
-///
-///  let res = vec![&b"abcd"[..], &b"abcd"[..]];
-///  assert_eq!(multi(&a[..]),Ok((&b"efgh"[..], res)));
-///  assert_eq!(multi(&b[..]),Ok((&b"azerty"[..], Vec::new())));
-/// # }
-/// ```
-/// 0 or more
-#[macro_export(local_inner_macros)]
-macro_rules! fold_many0(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $init:expr, $fold_f:expr) => (
-    fold_many0!($i, |i| $submac!(i, $($args)*), $init, $fold_f)
-  );
-  ($i:expr, $f:expr, $init:expr, $fold_f:expr) => (
-    $crate::multi::fold_many0($f, $init, $fold_f)($i)
-  );
-);
-
-/// `fold_many1!(I -> IResult<I,O>, R, Fn(R, O) -> R) => I -> IResult<I, R>`
-/// Applies the parser 1 or more times and folds the list of return values
-///
-/// the embedded parser may return Incomplete
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-///  named!(multi<&[u8], Vec<&[u8]> >,
-///    fold_many1!( tag!( "abcd" ), Vec::new(), |mut acc: Vec<_>, item| {
-///      acc.push(item);
-///      acc
-///  }));
-///
-///  let a = b"abcdabcdefgh";
-///  let b = b"azerty";
-///
-///  let res = vec![&b"abcd"[..], &b"abcd"[..]];
-///  assert_eq!(multi(&a[..]),Ok((&b"efgh"[..], res)));
-///  assert_eq!(multi(&b[..]), Err(Err::Error(error_position!(&b[..], ErrorKind::Many1))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! fold_many1(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $init:expr, $fold_f:expr) => (
-    fold_many1!($i, |i| $submac!(i, $($args)*), $init, $fold_f)
-  );
-  ($i:expr, $f:expr, $init:expr, $fold_f:expr) => (
-    $crate::multi::fold_many1c($i, $f, $init, $fold_f)
-  );
-  ($i:expr, $f:expr, $init:expr, $fold_f:expr) => (
-    fold_many1!($i, call!($f), $init, $fold_f);
-  );
-);
-
-/// `fold_many_m_n!(usize, usize, I -> IResult<I,O>, R, Fn(R, O) -> R) => I -> IResult<I, R>`
-/// Applies the parser between m and n times (n included) and folds the list of return value
-///
-/// the embedded parser may return Incomplete
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # fn main() {
-///  named!(multi<&[u8], Vec<&[u8]> >,
-///    fold_many_m_n!(2, 4, tag!( "abcd" ), Vec::new(), |mut acc: Vec<_>, item| {
-///      acc.push(item);
-///      acc
-///  }));
-///
-///  let a = b"abcdefgh";
-///  let b = b"abcdabcdefgh";
-///  let c = b"abcdabcdabcdabcdabcdefgh";
-///
-///  assert_eq!(multi(&a[..]), Err(Err::Error(error_position!(&a[..], ErrorKind::ManyMN))));
-///  let res = vec![&b"abcd"[..], &b"abcd"[..]];
-///  assert_eq!(multi(&b[..]),Ok((&b"efgh"[..], res)));
-///  let res2 = vec![&b"abcd"[..], &b"abcd"[..], &b"abcd"[..], &b"abcd"[..]];
-///  assert_eq!(multi(&c[..]),Ok((&b"abcdefgh"[..], res2)));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! fold_many_m_n(
-  ($i:expr, $m:expr, $n:expr, $submac:ident!( $($args:tt)* ), $init:expr, $fold_f:expr) => (
-    fold_many_m_n!($i, $m, $n, |i| $submac!(i, $($args)*), $init, $fold_f)
-  );
-  ($i:expr, $m:expr, $n:expr, $f:expr, $init:expr, $fold_f:expr) => (
-    $crate::multi::fold_many_m_nc($i, $m, $n, $f, $init, $fold_f)
-  );
-);
-
-#[cfg(test)]
-mod tests {
-  use crate::internal::{Err, IResult, Needed};
-  use crate::error::ParseError;
-  use crate::lib::std::str::{self, FromStr};
-  #[cfg(feature = "alloc")]
-  use crate::lib::std::vec::Vec;
-  use crate::character::streaming::digit1 as digit;
-  use crate::number::streaming::{be_u16, be_u8};
-  use crate::error::ErrorKind;
-
-  // reproduce the tag and take macros, because of module import order
-  macro_rules! tag (
-    ($i:expr, $inp: expr) => (
-      {
-        #[inline(always)]
-        fn as_bytes<T: $crate::AsBytes>(b: &T) -> &[u8] {
-          b.as_bytes()
-        }
-
-        let expected = $inp;
-        let bytes    = as_bytes(&expected);
-
-        tag_bytes!($i,bytes)
-      }
-    );
-  );
-
-  macro_rules! tag_bytes (
-    ($i:expr, $bytes: expr) => (
-      {
-        use $crate::lib::std::cmp::min;
-        let len = $i.len();
-        let blen = $bytes.len();
-        let m   = min(len, blen);
-        let reduced = &$i[..m];
-        let b       = &$bytes[..m];
-
-        let res: IResult<_,_,_> = if reduced != b {
-          Err($crate::Err::Error($crate::error::make_error($i, $crate::error::ErrorKind::Tag)))
-        } else if m < blen {
-          Err($crate::Err::Incomplete(Needed::Size(blen)))
-        } else {
-          Ok((&$i[blen..], reduced))
-        };
-        res
-      }
-    );
-  );
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn separated_list() {
-    named!(multi<&[u8],Vec<&[u8]> >, separated_list!(tag!(","), tag!("abcd")));
-    named!(multi_empty<&[u8],Vec<&[u8]> >, separated_list!(tag!(","), tag!("")));
-    named!(multi_longsep<&[u8],Vec<&[u8]> >, separated_list!(tag!(".."), tag!("abcd")));
-
-    let a = &b"abcdef"[..];
-    let b = &b"abcd,abcdef"[..];
-    let c = &b"azerty"[..];
-    let d = &b",,abc"[..];
-    let e = &b"abcd,abcd,ef"[..];
-    let f = &b"abc"[..];
-    let g = &b"abcd."[..];
-    let h = &b"abcd,abc"[..];
-
-    let res1 = vec![&b"abcd"[..]];
-    assert_eq!(multi(a), Ok((&b"ef"[..], res1)));
-    let res2 = vec![&b"abcd"[..], &b"abcd"[..]];
-    assert_eq!(multi(b), Ok((&b"ef"[..], res2)));
-    assert_eq!(multi(c), Ok((&b"azerty"[..], Vec::new())));
-    assert_eq!(multi_empty(d), Err(Err::Error(error_position!(d, ErrorKind::SeparatedList))));
-    //let res3 = vec![&b""[..], &b""[..], &b""[..]];
-    //assert_eq!(multi_empty(d),Ok((&b"abc"[..], res3)));
-    let res4 = vec![&b"abcd"[..], &b"abcd"[..]];
-    assert_eq!(multi(e), Ok((&b",ef"[..], res4)));
-
-    assert_eq!(multi(f), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(multi_longsep(g), Err(Err::Incomplete(Needed::Size(2))));
-    assert_eq!(multi(h), Err(Err::Incomplete(Needed::Size(4))));
-  }
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn separated_nonempty_list() {
-    named!(multi<&[u8],Vec<&[u8]> >, separated_nonempty_list!(tag!(","), tag!("abcd")));
-    named!(multi_longsep<&[u8],Vec<&[u8]> >, separated_nonempty_list!(tag!(".."), tag!("abcd")));
-
-    let a = &b"abcdef"[..];
-    let b = &b"abcd,abcdef"[..];
-    let c = &b"azerty"[..];
-    let d = &b"abcd,abcd,ef"[..];
-
-    let f = &b"abc"[..];
-    let g = &b"abcd."[..];
-    let h = &b"abcd,abc"[..];
-
-    let res1 = vec![&b"abcd"[..]];
-    assert_eq!(multi(a), Ok((&b"ef"[..], res1)));
-    let res2 = vec![&b"abcd"[..], &b"abcd"[..]];
-    assert_eq!(multi(b), Ok((&b"ef"[..], res2)));
-    assert_eq!(multi(c), Err(Err::Error(error_position!(c, ErrorKind::Tag))));
-    let res3 = vec![&b"abcd"[..], &b"abcd"[..]];
-    assert_eq!(multi(d), Ok((&b",ef"[..], res3)));
-
-    assert_eq!(multi(f), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(multi_longsep(g), Err(Err::Incomplete(Needed::Size(2))));
-    assert_eq!(multi(h), Err(Err::Incomplete(Needed::Size(4))));
-  }
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn many0() {
-    named!(tag_abcd, tag!("abcd"));
-    named!(tag_empty, tag!(""));
-    named!( multi<&[u8],Vec<&[u8]> >, many0!(tag_abcd) );
-    named!( multi_empty<&[u8],Vec<&[u8]> >, many0!(tag_empty) );
-
-    assert_eq!(multi(&b"abcdef"[..]), Ok((&b"ef"[..], vec![&b"abcd"[..]])));
-    assert_eq!(multi(&b"abcdabcdefgh"[..]), Ok((&b"efgh"[..], vec![&b"abcd"[..], &b"abcd"[..]])));
-    assert_eq!(multi(&b"azerty"[..]), Ok((&b"azerty"[..], Vec::new())));
-    assert_eq!(multi(&b"abcdab"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(multi(&b"abcd"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(multi(&b""[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(
-      multi_empty(&b"abcdef"[..]),
-      Err(Err::Error(error_position!(&b"abcdef"[..], ErrorKind::Many0)))
-    );
-  }
-
-  #[cfg(nightly)]
-  use test::Bencher;
-
-  #[cfg(nightly)]
-  #[bench]
-  fn many0_bench(b: &mut Bencher) {
-    named!(multi<&[u8],Vec<&[u8]> >, many0!(tag!("abcd")));
-    b.iter(|| multi(&b"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd"[..]));
-  }
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn many1() {
-    named!(multi<&[u8],Vec<&[u8]> >, many1!(tag!("abcd")));
-
-    let a = &b"abcdef"[..];
-    let b = &b"abcdabcdefgh"[..];
-    let c = &b"azerty"[..];
-    let d = &b"abcdab"[..];
-
-    let res1 = vec![&b"abcd"[..]];
-    assert_eq!(multi(a), Ok((&b"ef"[..], res1)));
-    let res2 = vec![&b"abcd"[..], &b"abcd"[..]];
-    assert_eq!(multi(b), Ok((&b"efgh"[..], res2)));
-    assert_eq!(multi(c), Err(Err::Error(error_position!(c, ErrorKind::Tag))));
-    assert_eq!(multi(d), Err(Err::Incomplete(Needed::Size(4))));
-  }
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn many_till() {
-    named!(multi<&[u8], (Vec<&[u8]>, &[u8]) >, many_till!( tag!( "abcd" ), tag!( "efgh" ) ) );
-
-    let a = b"abcdabcdefghabcd";
-    let b = b"efghabcd";
-    let c = b"azerty";
-
-    let res_a = (vec![&b"abcd"[..], &b"abcd"[..]], &b"efgh"[..]);
-    let res_b: (Vec<&[u8]>, &[u8]) = (Vec::new(), &b"efgh"[..]);
-    assert_eq!(multi(&a[..]), Ok((&b"abcd"[..], res_a)));
-    assert_eq!(multi(&b[..]), Ok((&b"abcd"[..], res_b)));
-    assert_eq!(
-      multi(&c[..]),
-      Err(Err::Error(error_node_position!(
-        &c[..],
-        ErrorKind::ManyTill,
-        error_position!(&c[..], ErrorKind::Tag)
-      )))
-    );
-  }
-
-  #[test]
-  #[cfg(feature = "std")]
-  fn infinite_many() {
-    fn tst(input: &[u8]) -> IResult<&[u8], &[u8]> {
-      println!("input: {:?}", input);
-      Err(Err::Error(error_position!(input, ErrorKind::Tag)))
-    }
-
-    // should not go into an infinite loop
-    named!(multi0<&[u8],Vec<&[u8]> >, many0!(tst));
-    let a = &b"abcdef"[..];
-    assert_eq!(multi0(a), Ok((a, Vec::new())));
-
-    named!(multi1<&[u8],Vec<&[u8]> >, many1!(tst));
-    let a = &b"abcdef"[..];
-    assert_eq!(multi1(a), Err(Err::Error(error_position!(a, ErrorKind::Tag))));
-  }
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn many_m_n() {
-    named!(multi<&[u8],Vec<&[u8]> >, many_m_n!(2, 4, tag!("Abcd")));
-
-    let a = &b"Abcdef"[..];
-    let b = &b"AbcdAbcdefgh"[..];
-    let c = &b"AbcdAbcdAbcdAbcdefgh"[..];
-    let d = &b"AbcdAbcdAbcdAbcdAbcdefgh"[..];
-    let e = &b"AbcdAb"[..];
-
-    assert_eq!(multi(a), Err(Err::Error(error_position!(&b"ef"[..], ErrorKind::Tag))));
-    let res1 = vec![&b"Abcd"[..], &b"Abcd"[..]];
-    assert_eq!(multi(b), Ok((&b"efgh"[..], res1)));
-    let res2 = vec![&b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..]];
-    assert_eq!(multi(c), Ok((&b"efgh"[..], res2)));
-    let res3 = vec![&b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..]];
-    assert_eq!(multi(d), Ok((&b"Abcdefgh"[..], res3)));
-    assert_eq!(multi(e), Err(Err::Incomplete(Needed::Size(4))));
-  }
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn count() {
-    const TIMES: usize = 2;
-    named!(tag_abc, tag!("abc"));
-    named!( cnt_2<&[u8], Vec<&[u8]> >, count!(tag_abc, TIMES ) );
-
-    assert_eq!(cnt_2(&b"abcabcabcdef"[..]), Ok((&b"abcdef"[..], vec![&b"abc"[..], &b"abc"[..]])));
-    assert_eq!(cnt_2(&b"ab"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(cnt_2(&b"abcab"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(cnt_2(&b"xxx"[..]), Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag))));
-    assert_eq!(
-      cnt_2(&b"xxxabcabcdef"[..]),
-      Err(Err::Error(error_position!(&b"xxxabcabcdef"[..], ErrorKind::Tag)))
-    );
-    assert_eq!(
-      cnt_2(&b"abcxxxabcdef"[..]),
-      Err(Err::Error(error_position!(&b"xxxabcdef"[..], ErrorKind::Tag)))
-    );
-  }
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn count_zero() {
-    const TIMES: usize = 0;
-    named!(tag_abc, tag!("abc"));
-    named!( counter_2<&[u8], Vec<&[u8]> >, count!(tag_abc, TIMES ) );
-
-    let done = &b"abcabcabcdef"[..];
-    let parsed_done = Vec::new();
-    let rest = done;
-    let incomplete_1 = &b"ab"[..];
-    let parsed_incompl_1 = Vec::new();
-    let incomplete_2 = &b"abcab"[..];
-    let parsed_incompl_2 = Vec::new();
-    let error = &b"xxx"[..];
-    let error_remain = &b"xxx"[..];
-    let parsed_err = Vec::new();
-    let error_1 = &b"xxxabcabcdef"[..];
-    let parsed_err_1 = Vec::new();
-    let error_1_remain = &b"xxxabcabcdef"[..];
-    let error_2 = &b"abcxxxabcdef"[..];
-    let parsed_err_2 = Vec::new();
-    let error_2_remain = &b"abcxxxabcdef"[..];
-
-    assert_eq!(counter_2(done), Ok((rest, parsed_done)));
-    assert_eq!(counter_2(incomplete_1), Ok((incomplete_1, parsed_incompl_1)));
-    assert_eq!(counter_2(incomplete_2), Ok((incomplete_2, parsed_incompl_2)));
-    assert_eq!(counter_2(error), Ok((error_remain, parsed_err)));
-    assert_eq!(counter_2(error_1), Ok((error_1_remain, parsed_err_1)));
-    assert_eq!(counter_2(error_2), Ok((error_2_remain, parsed_err_2)));
-  }
-
-  #[derive(Debug, Clone, PartialEq)]
-  pub struct NilError;
-
-  impl<I> From<(I,ErrorKind)> for NilError {
-    fn from(_: (I, ErrorKind)) -> Self {
-      NilError
-    }
-  }
-
-  impl<I> ParseError<I> for NilError {
-    fn from_error_kind(_: I, _: ErrorKind) -> NilError {
-      NilError
-    }
-    fn append(_: I, _: ErrorKind, _: NilError) -> NilError {
-      NilError
-    }
-  }
-
-  named!(pub number<u32>, map_res!(
-    map_res!(
-      digit,
-      str::from_utf8
-    ),
-    FromStr::from_str
-  ));
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn length_count() {
-    named!(tag_abc, tag!(&b"abc"[..]));
-    named!( cnt<&[u8], Vec<&[u8]> >, length_count!(number, tag_abc) );
-
-    assert_eq!(cnt(&b"2abcabcabcdef"[..]), Ok((&b"abcdef"[..], vec![&b"abc"[..], &b"abc"[..]])));
-    assert_eq!(cnt(&b"2ab"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(cnt(&b"3abcab"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(cnt(&b"xxx"[..]), Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Digit))));
-    assert_eq!(
-      cnt(&b"2abcxxx"[..]),
-      Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
-    );
-  }
-
-  #[test]
-  fn length_data() {
-    named!( take<&[u8], &[u8]>, length_data!(number) );
-
-    assert_eq!(take(&b"6abcabcabcdef"[..]), Ok((&b"abcdef"[..], &b"abcabc"[..])));
-    assert_eq!(take(&b"3ab"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(take(&b"xxx"[..]), Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Digit))));
-    assert_eq!(take(&b"2abcxxx"[..]), Ok((&b"cxxx"[..], &b"ab"[..])));
-  }
-
-  #[test]
-  fn length_value_test() {
-    named!(length_value_1<&[u8], u16 >, length_value!(be_u8, be_u16));
-    named!(length_value_2<&[u8], (u8, u8) >, length_value!(be_u8, tuple!(be_u8, be_u8)));
-
-    let i1 = [0, 5, 6];
-    assert_eq!(length_value_1(&i1), Err(Err::Error(error_position!(&b""[..], ErrorKind::Complete))));
-    assert_eq!(length_value_2(&i1), Err(Err::Error(error_position!(&b""[..], ErrorKind::Complete))));
-
-    let i2 = [1, 5, 6, 3];
-    assert_eq!(
-      length_value_1(&i2),
-      Err(Err::Error(error_position!(&i2[1..2], ErrorKind::Complete)))
-    );
-    assert_eq!(
-      length_value_2(&i2),
-      Err(Err::Error(error_position!(&i2[1..2], ErrorKind::Complete)))
-    );
-
-    let i3 = [2, 5, 6, 3, 4, 5, 7];
-    assert_eq!(length_value_1(&i3), Ok((&i3[3..], 1286)));
-    assert_eq!(length_value_2(&i3), Ok((&i3[3..], (5, 6))));
-
-    let i4 = [3, 5, 6, 3, 4, 5];
-    assert_eq!(length_value_1(&i4), Ok((&i4[4..], 1286)));
-    assert_eq!(length_value_2(&i4), Ok((&i4[4..], (5, 6))));
-  }
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn fold_many0() {
-    fn fold_into_vec<T>(mut acc: Vec<T>, item: T) -> Vec<T> {
-      acc.push(item);
-      acc
-    };
-    named!(tag_abcd, tag!("abcd"));
-    named!(tag_empty, tag!(""));
-    named!( multi<&[u8],Vec<&[u8]> >, fold_many0!(tag_abcd, Vec::new(), fold_into_vec) );
-    named!( multi_empty<&[u8],Vec<&[u8]> >, fold_many0!(tag_empty, Vec::new(), fold_into_vec) );
-
-    assert_eq!(multi(&b"abcdef"[..]), Ok((&b"ef"[..], vec![&b"abcd"[..]])));
-    assert_eq!(multi(&b"abcdabcdefgh"[..]), Ok((&b"efgh"[..], vec![&b"abcd"[..], &b"abcd"[..]])));
-    assert_eq!(multi(&b"azerty"[..]), Ok((&b"azerty"[..], Vec::new())));
-    assert_eq!(multi(&b"abcdab"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(multi(&b"abcd"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(multi(&b""[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(
-      multi_empty(&b"abcdef"[..]),
-      Err(Err::Error(error_position!(&b"abcdef"[..], ErrorKind::Many0)))
-    );
-  }
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn fold_many1() {
-    fn fold_into_vec<T>(mut acc: Vec<T>, item: T) -> Vec<T> {
-      acc.push(item);
-      acc
-    };
-    named!(multi<&[u8],Vec<&[u8]> >, fold_many1!(tag!("abcd"), Vec::new(), fold_into_vec));
-
-    let a = &b"abcdef"[..];
-    let b = &b"abcdabcdefgh"[..];
-    let c = &b"azerty"[..];
-    let d = &b"abcdab"[..];
-
-    let res1 = vec![&b"abcd"[..]];
-    assert_eq!(multi(a), Ok((&b"ef"[..], res1)));
-    let res2 = vec![&b"abcd"[..], &b"abcd"[..]];
-    assert_eq!(multi(b), Ok((&b"efgh"[..], res2)));
-    assert_eq!(multi(c), Err(Err::Error(error_position!(c, ErrorKind::Many1))));
-    assert_eq!(multi(d), Err(Err::Incomplete(Needed::Size(4))));
-  }
-
-  #[test]
-  #[cfg(feature = "alloc")]
-  fn fold_many_m_n() {
-    fn fold_into_vec<T>(mut acc: Vec<T>, item: T) -> Vec<T> {
-      acc.push(item);
-      acc
-    };
-    named!(multi<&[u8],Vec<&[u8]> >, fold_many_m_n!(2, 4, tag!("Abcd"), Vec::new(), fold_into_vec));
-
-    let a = &b"Abcdef"[..];
-    let b = &b"AbcdAbcdefgh"[..];
-    let c = &b"AbcdAbcdAbcdAbcdefgh"[..];
-    let d = &b"AbcdAbcdAbcdAbcdAbcdefgh"[..];
-    let e = &b"AbcdAb"[..];
-
-    assert_eq!(multi(a), Err(Err::Error(error_position!(a, ErrorKind::ManyMN))));
-    let res1 = vec![&b"Abcd"[..], &b"Abcd"[..]];
-    assert_eq!(multi(b), Ok((&b"efgh"[..], res1)));
-    let res2 = vec![&b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..]];
-    assert_eq!(multi(c), Ok((&b"efgh"[..], res2)));
-    let res3 = vec![&b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..]];
-    assert_eq!(multi(d), Ok((&b"Abcdefgh"[..], res3)));
-    assert_eq!(multi(e), Err(Err::Incomplete(Needed::Size(4))));
-  }
-
-  #[test]
-  fn many0_count() {
-    named!(
-      count0_nums(&[u8]) -> usize,
-      many0_count!(pair!(digit, tag!(",")))
-    );
-
-    assert_eq!(count0_nums(&b"123,junk"[..]), Ok((&b"junk"[..], 1)));
-
-    assert_eq!(count0_nums(&b"123,45,junk"[..]), Ok((&b"junk"[..], 2)));
-
-    assert_eq!(count0_nums(&b"1,2,3,4,5,6,7,8,9,0,junk"[..]), Ok((&b"junk"[..], 10)));
-
-    assert_eq!(count0_nums(&b"hello"[..]), Ok((&b"hello"[..], 0)));
-  }
-
-  #[test]
-  fn many1_count() {
-    named!(
-      count1_nums(&[u8]) -> usize,
-      many1_count!(pair!(digit, tag!(",")))
-    );
-
-    assert_eq!(count1_nums(&b"123,45,junk"[..]), Ok((&b"junk"[..], 2)));
-
-    assert_eq!(count1_nums(&b"1,2,3,4,5,6,7,8,9,0,junk"[..]), Ok((&b"junk"[..], 10)));
-
-    assert_eq!(
-      count1_nums(&b"hello"[..]),
-      Err(Err::Error(error_position!(&b"hello"[..], ErrorKind::Many1Count)))
-    );
-  }
-
-}
diff --git a/src/multi/mod.rs b/src/multi/mod.rs
index e8f26dd..a119134 100644
--- a/src/multi/mod.rs
+++ b/src/multi/mod.rs
@@ -1,14 +1,15 @@
-//! combinators applying their child parser multiple times
+//! Combinators applying their child parser multiple times
 
-#[macro_use]
-mod macros;
+#[cfg(test)]
+mod tests;
 
-use crate::internal::{Err, IResult, Needed};
+use crate::error::ErrorKind;
 use crate::error::ParseError;
-use crate::traits::{InputLength, InputTake, ToUsize};
+use crate::internal::{Err, IResult, Needed, Parser};
 #[cfg(feature = "alloc")]
 use crate::lib::std::vec::Vec;
-use crate::error::ErrorKind;
+use crate::traits::{InputLength, InputTake, ToUsize};
+use core::num::NonZeroUsize;
 
 /// Repeats the embedded parser until it fails
 /// and returns the results in a `Vec`.
@@ -35,21 +36,23 @@
 /// assert_eq!(parser(""), Ok(("", vec![])));
 /// ```
 #[cfg(feature = "alloc")]
-pub fn many0<I, O, E, F>(f: F) -> impl Fn(I) -> IResult<I, Vec<O>, E>
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+pub fn many0<I, O, E, F>(mut f: F) -> impl FnMut(I) -> IResult<I, Vec<O>, E>
 where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
+  I: Clone + InputLength,
+  F: Parser<I, O, E>,
   E: ParseError<I>,
 {
-  move |i: I| {
+  move |mut i: I| {
     let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
-    let mut i = i.clone();
     loop {
-      match f(i.clone()) {
+      let len = i.input_len();
+      match f.parse(i.clone()) {
         Err(Err::Error(_)) => return Ok((i, acc)),
         Err(e) => return Err(e),
         Ok((i1, o)) => {
-          if i1 == i {
+          // infinite loop check: the parser must always consume
+          if i1.input_len() == len {
             return Err(Err::Error(E::from_error_kind(i, ErrorKind::Many0)));
           }
 
@@ -60,17 +63,6 @@
     }
   }
 }
-// this implementation is used for type inference issues in macros
-#[doc(hidden)]
-#[cfg(feature = "alloc")]
-pub fn many0c<I, O, E, F>(input: I, f: F) -> IResult<I, Vec<O>, E>
-where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  E: ParseError<I>,
-{
-  many0(f)(input)
-}
 
 /// Runs the embedded parser until it fails and
 /// returns the results in a `Vec`. Fails if
@@ -80,12 +72,12 @@
 /// # Arguments
 /// * `f` The parser to apply.
 ///
-/// *Note*: if the parser passed to `many1` accepts empty inputs
+/// *Note*: If the parser passed to `many1` accepts empty inputs
 /// (like `alpha0` or `digit0`), `many1` will return an error,
-/// to prevent going into an infinite loop
+/// to prevent going into an infinite loop.
 ///
 /// ```rust
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::multi::many1;
 /// use nom::bytes::complete::tag;
 ///
@@ -95,38 +87,38 @@
 ///
 /// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
 /// assert_eq!(parser("abc123"), Ok(("123", vec!["abc"])));
-/// assert_eq!(parser("123123"), Err(Err::Error(("123123", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
+/// assert_eq!(parser("123123"), Err(Err::Error(Error::new("123123", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
 /// ```
 #[cfg(feature = "alloc")]
-pub fn many1<I, O, E, F>(f: F) -> impl Fn(I) -> IResult<I, Vec<O>, E>
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+pub fn many1<I, O, E, F>(mut f: F) -> impl FnMut(I) -> IResult<I, Vec<O>, E>
 where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
+  I: Clone + InputLength,
+  F: Parser<I, O, E>,
   E: ParseError<I>,
 {
-  move |i: I| {
-    let mut i = i.clone();
-    match f(i.clone()) {
-      Err(Err::Error(err)) => return Err(Err::Error(E::append(i, ErrorKind::Many1, err))),
-      Err(e) => return Err(e),
-      Ok((i1, o)) => {
-        let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
-        acc.push(o);
-        i = i1;
+  move |mut i: I| match f.parse(i.clone()) {
+    Err(Err::Error(err)) => Err(Err::Error(E::append(i, ErrorKind::Many1, err))),
+    Err(e) => Err(e),
+    Ok((i1, o)) => {
+      let mut acc = crate::lib::std::vec::Vec::with_capacity(4);
+      acc.push(o);
+      i = i1;
 
-        loop {
-          match f(i.clone()) {
-            Err(Err::Error(_)) => return Ok((i, acc)),
-            Err(e) => return Err(e),
-            Ok((i1, o)) => {
-              if i1 == i {
-                return Err(Err::Error(E::from_error_kind(i, ErrorKind::Many1)));
-              }
-
-              i = i1;
-              acc.push(o);
+      loop {
+        let len = i.input_len();
+        match f.parse(i.clone()) {
+          Err(Err::Error(_)) => return Ok((i, acc)),
+          Err(e) => return Err(e),
+          Ok((i1, o)) => {
+            // infinite loop check: the parser must always consume
+            if i1.input_len() == len {
+              return Err(Err::Error(E::from_error_kind(i, ErrorKind::Many1)));
             }
+
+            i = i1;
+            acc.push(o);
           }
         }
       }
@@ -134,23 +126,11 @@
   }
 }
 
-// this implementation is used for type inference issues in macros
-#[doc(hidden)]
-#[cfg(feature = "alloc")]
-pub fn many1c<I, O, E, F>(input: I, f: F) -> IResult<I, Vec<O>, E>
-where
-  I: Clone + Copy + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  E: ParseError<I>,
-{
-  many1(f)(input)
-}
-
 /// Applies the parser `f` until the parser `g` produces
 /// a result. Returns a pair consisting of the results of
 /// `f` in a `Vec` and the result of `g`.
 /// ```rust
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::multi::many_till;
 /// use nom::bytes::complete::tag;
 ///
@@ -159,33 +139,36 @@
 /// };
 ///
 /// assert_eq!(parser("abcabcend"), Ok(("", (vec!["abc", "abc"], "end"))));
-/// assert_eq!(parser("abc123end"), Err(Err::Error(("123end", ErrorKind::Tag))));
-/// assert_eq!(parser("123123end"), Err(Err::Error(("123123end", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
+/// assert_eq!(parser("abc123end"), Err(Err::Error(Error::new("123end", ErrorKind::Tag))));
+/// assert_eq!(parser("123123end"), Err(Err::Error(Error::new("123123end", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
 /// assert_eq!(parser("abcendefg"), Ok(("efg", (vec!["abc"], "end"))));
 /// ```
 #[cfg(feature = "alloc")]
-pub fn many_till<I, O, P, E, F, G>(f: F, g: G) -> impl Fn(I) -> IResult<I, (Vec<O>, P), E>
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+pub fn many_till<I, O, P, E, F, G>(
+  mut f: F,
+  mut g: G,
+) -> impl FnMut(I) -> IResult<I, (Vec<O>, P), E>
 where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  G: Fn(I) -> IResult<I, P, E>,
+  I: Clone + InputLength,
+  F: Parser<I, O, E>,
+  G: Parser<I, P, E>,
   E: ParseError<I>,
 {
-  move |i: I| {
+  move |mut i: I| {
     let mut res = crate::lib::std::vec::Vec::new();
-    let mut i = i.clone();
     loop {
-      match g(i.clone()) {
+      let len = i.input_len();
+      match g.parse(i.clone()) {
         Ok((i1, o)) => return Ok((i1, (res, o))),
         Err(Err::Error(_)) => {
-          match f(i.clone()) {
-            Err(Err::Error(err)) =>
-              return Err(Err::Error(E::append(i, ErrorKind::ManyTill, err))),
+          match f.parse(i.clone()) {
+            Err(Err::Error(err)) => return Err(Err::Error(E::append(i, ErrorKind::ManyTill, err))),
             Err(e) => return Err(e),
             Ok((i1, o)) => {
-              // loop trip must always consume (otherwise infinite loops)
-              if i1 == i {
+              // infinite loop check: the parser must always consume
+              if i1.input_len() == len {
                 return Err(Err::Error(E::from_error_kind(i1, ErrorKind::ManyTill)));
               }
 
@@ -193,26 +176,13 @@
               i = i1;
             }
           }
-        },
+        }
         Err(e) => return Err(e),
       }
     }
   }
 }
 
-// this implementation is used for type inference issues in macros
-#[doc(hidden)]
-#[cfg(feature = "alloc")]
-pub fn many_tillc<I, O, P, E, F, G>(i: I, f: F, g: G) -> IResult<I, (Vec<O>, P), E>
-where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  G: Fn(I) -> IResult<I, P, E>,
-  E: ParseError<I>,
-{
-  many_till(f, g)(i)
-}
-
 /// Alternates between two parsers to produce
 /// a list of elements.
 /// # Arguments
@@ -221,11 +191,11 @@
 ///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
-/// use nom::multi::separated_list;
+/// use nom::multi::separated_list0;
 /// use nom::bytes::complete::tag;
 ///
 /// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
-///   separated_list(tag("|"), tag("abc"))(s)
+///   separated_list0(tag("|"), tag("abc"))(s)
 /// }
 ///
 /// assert_eq!(parser("abc|abc|abc"), Ok(("", vec!["abc", "abc", "abc"])));
@@ -235,47 +205,44 @@
 /// assert_eq!(parser("def|abc"), Ok(("def|abc", vec![])));
 /// ```
 #[cfg(feature = "alloc")]
-pub fn separated_list<I, O, O2, E, F, G>(sep: G, f: F) -> impl Fn(I) -> IResult<I, Vec<O>, E>
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+pub fn separated_list0<I, O, O2, E, F, G>(
+  mut sep: G,
+  mut f: F,
+) -> impl FnMut(I) -> IResult<I, Vec<O>, E>
 where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
+  I: Clone + InputLength,
+  F: Parser<I, O, E>,
+  G: Parser<I, O2, E>,
   E: ParseError<I>,
 {
-  move |i: I| {
+  move |mut i: I| {
     let mut res = Vec::new();
-    let mut i = i.clone();
 
-    match f(i.clone()) {
+    match f.parse(i.clone()) {
       Err(Err::Error(_)) => return Ok((i, res)),
       Err(e) => return Err(e),
       Ok((i1, o)) => {
-        if i1 == i {
-          return Err(Err::Error(E::from_error_kind(i1, ErrorKind::SeparatedList)));
-        }
-
         res.push(o);
         i = i1;
       }
     }
 
     loop {
-      match sep(i.clone()) {
+      let len = i.input_len();
+      match sep.parse(i.clone()) {
         Err(Err::Error(_)) => return Ok((i, res)),
         Err(e) => return Err(e),
         Ok((i1, _)) => {
-          if i1 == i {
+          // infinite loop check: the parser must always consume
+          if i1.input_len() == len {
             return Err(Err::Error(E::from_error_kind(i1, ErrorKind::SeparatedList)));
           }
 
-          match f(i1.clone()) {
+          match f.parse(i1.clone()) {
             Err(Err::Error(_)) => return Ok((i, res)),
             Err(e) => return Err(e),
             Ok((i2, o)) => {
-              if i2 == i {
-                return Err(Err::Error(E::from_error_kind(i2, ErrorKind::SeparatedList)));
-              }
-
               res.push(o);
               i = i2;
             }
@@ -286,19 +253,6 @@
   }
 }
 
-// this implementation is used for type inference issues in macros
-#[doc(hidden)]
-#[cfg(feature = "alloc")]
-pub fn separated_listc<I, O, O2, E, F, G>(i: I, sep: G, f: F) -> IResult<I, Vec<O>, E>
-where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
-  E: ParseError<I>,
-{
-  separated_list(sep, f)(i)
-}
-
 /// Alternates between two parsers to produce
 /// a list of elements. Fails if the element
 /// parser does not produce at least one element.
@@ -306,63 +260,59 @@
 /// * `sep` Parses the separator between list elements.
 /// * `f` Parses the elements of the list.
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
-/// use nom::multi::separated_nonempty_list;
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
+/// use nom::multi::separated_list1;
 /// use nom::bytes::complete::tag;
 ///
 /// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
-///   separated_nonempty_list(tag("|"), tag("abc"))(s)
+///   separated_list1(tag("|"), tag("abc"))(s)
 /// }
 ///
 /// assert_eq!(parser("abc|abc|abc"), Ok(("", vec!["abc", "abc", "abc"])));
 /// assert_eq!(parser("abc123abc"), Ok(("123abc", vec!["abc"])));
 /// assert_eq!(parser("abc|def"), Ok(("|def", vec!["abc"])));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
-/// assert_eq!(parser("def|abc"), Err(Err::Error(("def|abc", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser("def|abc"), Err(Err::Error(Error::new("def|abc", ErrorKind::Tag))));
 /// ```
 #[cfg(feature = "alloc")]
-pub fn separated_nonempty_list<I, O, O2, E, F, G>(sep: G, f: F) -> impl Fn(I) -> IResult<I, Vec<O>, E>
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+pub fn separated_list1<I, O, O2, E, F, G>(
+  mut sep: G,
+  mut f: F,
+) -> impl FnMut(I) -> IResult<I, Vec<O>, E>
 where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
+  I: Clone + InputLength,
+  F: Parser<I, O, E>,
+  G: Parser<I, O2, E>,
   E: ParseError<I>,
 {
-  move |i: I| {
+  move |mut i: I| {
     let mut res = Vec::new();
-    let mut i = i.clone();
 
     // Parse the first element
-    match f(i.clone()) {
-      Err(e)=> return Err(e),
+    match f.parse(i.clone()) {
+      Err(e) => return Err(e),
       Ok((i1, o)) => {
-        if i1 == i {
-          return Err(Err::Error(E::from_error_kind(i1, ErrorKind::SeparatedList)));
-        }
-
         res.push(o);
         i = i1;
       }
     }
 
     loop {
-      match sep(i.clone()) {
+      let len = i.input_len();
+      match sep.parse(i.clone()) {
         Err(Err::Error(_)) => return Ok((i, res)),
         Err(e) => return Err(e),
         Ok((i1, _)) => {
-          if i1 == i {
+          // infinite loop check: the parser must always consume
+          if i1.input_len() == len {
             return Err(Err::Error(E::from_error_kind(i1, ErrorKind::SeparatedList)));
           }
 
-          match f(i1.clone()) {
+          match f.parse(i1.clone()) {
             Err(Err::Error(_)) => return Ok((i, res)),
             Err(e) => return Err(e),
             Ok((i2, o)) => {
-              if i2 == i {
-                return Err(Err::Error(E::from_error_kind(i2, ErrorKind::SeparatedList)));
-              }
-
               res.push(o);
               i = i2;
             }
@@ -373,19 +323,6 @@
   }
 }
 
-// this implementation is used for type inference issues in macros
-#[doc(hidden)]
-#[cfg(feature = "alloc")]
-pub fn separated_nonempty_listc<I, O, O2, E, F, G>(i: I, sep: G, f: F) -> IResult<I, Vec<O>, E>
-where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
-  E: ParseError<I>,
-{
-  separated_nonempty_list(sep, f)(i)
-}
-
 /// Repeats the embedded parser `n` times or until it fails
 /// and returns the results in a `Vec`. Fails if the
 /// embedded parser does not succeed at least `m` times.
@@ -394,7 +331,6 @@
 /// * `n` The maximum number of iterations.
 /// * `f` The parser to apply.
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// use nom::multi::many_m_n;
 /// use nom::bytes::complete::tag;
@@ -410,40 +346,37 @@
 /// assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));
 /// ```
 #[cfg(feature = "alloc")]
-pub fn many_m_n<I, O, E, F>(m: usize, n: usize, f: F) -> impl Fn(I) -> IResult<I, Vec<O>, E>
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+pub fn many_m_n<I, O, E, F>(
+  min: usize,
+  max: usize,
+  mut parse: F,
+) -> impl FnMut(I) -> IResult<I, Vec<O>, E>
 where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
+  I: Clone + InputLength,
+  F: Parser<I, O, E>,
   E: ParseError<I>,
 {
-  move |i: I| {
-    let mut res = crate::lib::std::vec::Vec::with_capacity(m);
-    let mut input = i.clone();
-    let mut count: usize = 0;
-
-    if n == 0 {
-        return Ok((i, vec!()))
+  move |mut input: I| {
+    if min > max {
+      return Err(Err::Failure(E::from_error_kind(input, ErrorKind::ManyMN)));
     }
 
-    loop {
-      let _i = input.clone();
-      match f(_i) {
-        Ok((i, o)) => {
-          // do not allow parsers that do not consume input (causes infinite loops)
-          if i == input {
+    let mut res = crate::lib::std::vec::Vec::with_capacity(min);
+    for count in 0..max {
+      let len = input.input_len();
+      match parse.parse(input.clone()) {
+        Ok((tail, value)) => {
+          // infinite loop check: the parser must always consume
+          if tail.input_len() == len {
             return Err(Err::Error(E::from_error_kind(input, ErrorKind::ManyMN)));
           }
 
-          res.push(o);
-          input = i;
-          count += 1;
-
-          if count == n {
-            return Ok((input, res));
-          }
+          res.push(value);
+          input = tail;
         }
         Err(Err::Error(e)) => {
-          if count < m {
+          if count < min {
             return Err(Err::Error(E::append(input, ErrorKind::ManyMN, e)));
           } else {
             return Ok((input, res));
@@ -454,19 +387,9 @@
         }
       }
     }
-  }
-}
 
-// this implementation is used for type inference issues in macros
-#[doc(hidden)]
-#[cfg(feature = "alloc")]
-pub fn many_m_nc<I, O, E, F>(i: I, m: usize, n: usize, f: F) -> IResult<I, Vec<O>, E>
-where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  E: ParseError<I>,
-{
-  many_m_n(m, n, f)(i)
+    Ok((input, res))
+  }
 }
 
 /// Repeats the embedded parser until it fails
@@ -474,7 +397,6 @@
 /// # Arguments
 /// * `f` The parser to apply.
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// use nom::multi::many0_count;
 /// use nom::bytes::complete::tag;
@@ -488,22 +410,23 @@
 /// assert_eq!(parser("123123"), Ok(("123123", 0)));
 /// assert_eq!(parser(""), Ok(("", 0)));
 /// ```
-pub fn many0_count<I, O, E, F>(f: F) -> impl Fn(I) -> IResult<I, usize, E>
+pub fn many0_count<I, O, E, F>(mut f: F) -> impl FnMut(I) -> IResult<I, usize, E>
 where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
+  I: Clone + InputLength,
+  F: Parser<I, O, E>,
   E: ParseError<I>,
 {
   move |i: I| {
-    let mut input = i.clone();
+    let mut input = i;
     let mut count = 0;
 
     loop {
       let input_ = input.clone();
-      match f(input_) {
+      let len = input.input_len();
+      match f.parse(input_) {
         Ok((i, _)) => {
-          //  loop trip must always consume (otherwise infinite loops)
-          if i == input {
+          // infinite loop check: the parser must always consume
+          if i.input_len() == len {
             return Err(Err::Error(E::from_error_kind(input, ErrorKind::Many0Count)));
           }
 
@@ -519,16 +442,6 @@
   }
 }
 
-#[doc(hidden)]
-pub fn many0_countc<I, O, E, F>(i: I, f: F) -> IResult<I, usize, E>
-where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  E: ParseError<I>,
-{
-  many0_count(f)(i)
-}
-
 /// Repeats the embedded parser until it fails
 /// and returns the number of successful iterations.
 /// Fails if the embedded parser does not succeed
@@ -536,8 +449,7 @@
 /// # Arguments
 /// * `f` The parser to apply.
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::multi::many1_count;
 /// use nom::bytes::complete::tag;
 ///
@@ -547,18 +459,18 @@
 ///
 /// assert_eq!(parser("abcabc"), Ok(("", 2)));
 /// assert_eq!(parser("abc123"), Ok(("123", 1)));
-/// assert_eq!(parser("123123"), Err(Err::Error(("123123", ErrorKind::Many1Count))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Many1Count))));
+/// assert_eq!(parser("123123"), Err(Err::Error(Error::new("123123", ErrorKind::Many1Count))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Many1Count))));
 /// ```
-pub fn many1_count<I, O, E, F>(f: F) -> impl Fn(I) -> IResult<I, usize, E>
+pub fn many1_count<I, O, E, F>(mut f: F) -> impl FnMut(I) -> IResult<I, usize, E>
 where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
+  I: Clone + InputLength,
+  F: Parser<I, O, E>,
   E: ParseError<I>,
 {
   move |i: I| {
     let i_ = i.clone();
-    match f(i_) {
+    match f.parse(i_) {
       Err(Err::Error(_)) => Err(Err::Error(E::from_error_kind(i, ErrorKind::Many1Count))),
       Err(i) => Err(i),
       Ok((i1, _)) => {
@@ -566,12 +478,14 @@
         let mut input = i1;
 
         loop {
+          let len = input.input_len();
           let input_ = input.clone();
-          match f(input_) {
+          match f.parse(input_) {
             Err(Err::Error(_)) => return Ok((input, count)),
             Err(e) => return Err(e),
             Ok((i, _)) => {
-              if i == input {
+              // infinite loop check: the parser must always consume
+              if i.input_len() == len {
                 return Err(Err::Error(E::from_error_kind(i, ErrorKind::Many1Count)));
               }
 
@@ -585,24 +499,13 @@
   }
 }
 
-#[doc(hidden)]
-pub fn many1_countc<I, O, E, F>(i: I, f: F) -> IResult<I, usize, E>
-where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  E: ParseError<I>,
-{
-  many1_count(f)(i)
-}
-
 /// Runs the embedded parser a specified number
 /// of times. Returns the results in a `Vec`.
 /// # Arguments
 /// * `f` The parser to apply.
 /// * `count` How often to apply the parser.
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::multi::count;
 /// use nom::bytes::complete::tag;
 ///
@@ -611,25 +514,26 @@
 /// }
 ///
 /// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
-/// assert_eq!(parser("abc123"), Err(Err::Error(("123", ErrorKind::Tag))));
-/// assert_eq!(parser("123123"), Err(Err::Error(("123123", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
+/// assert_eq!(parser("abc123"), Err(Err::Error(Error::new("123", ErrorKind::Tag))));
+/// assert_eq!(parser("123123"), Err(Err::Error(Error::new("123123", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
 /// assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));
 /// ```
 #[cfg(feature = "alloc")]
-pub fn count<I, O, E, F>(f: F, count: usize) -> impl Fn(I) -> IResult<I, Vec<O>, E>
+#[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,
-  F: Fn(I) -> IResult<I, O, E>,
+  F: Parser<I, O, E>,
   E: ParseError<I>,
 {
-  move |i: I | {
+  move |i: I| {
     let mut input = i.clone();
-    let mut res = crate::lib::std::vec::Vec::new();
+    let mut res = crate::lib::std::vec::Vec::with_capacity(count);
 
     for _ in 0..count {
       let input_ = input.clone();
-      match f(input_) {
+      match f.parse(input_) {
         Ok((i, o)) => {
           res.push(o);
           input = i;
@@ -647,15 +551,65 @@
   }
 }
 
+/// Runs the embedded parser repeatedly, filling the given slice with results. This parser fails if
+/// the input runs out before the given slice is full.
+/// # Arguments
+/// * `f` The parser to apply.
+/// * `buf` The slice to fill
+/// ```rust
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
+/// use nom::multi::fill;
+/// use nom::bytes::complete::tag;
+///
+/// fn parser(s: &str) -> IResult<&str, [&str; 2]> {
+///   let mut buf = ["", ""];
+///   let (rest, ()) = fill(tag("abc"), &mut buf)(s)?;
+///   Ok((rest, buf))
+/// }
+///
+/// assert_eq!(parser("abcabc"), Ok(("", ["abc", "abc"])));
+/// assert_eq!(parser("abc123"), Err(Err::Error(Error::new("123", ErrorKind::Tag))));
+/// assert_eq!(parser("123123"), Err(Err::Error(Error::new("123123", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser("abcabcabc"), Ok(("abc", ["abc", "abc"])));
+/// ```
+pub fn fill<'a, I, O, E, F>(f: F, buf: &'a mut [O]) -> impl FnMut(I) -> IResult<I, (), E> + 'a
+where
+  I: Clone + PartialEq,
+  F: Fn(I) -> IResult<I, O, E> + 'a,
+  E: ParseError<I>,
+{
+  move |i: I| {
+    let mut input = i.clone();
+
+    for elem in buf.iter_mut() {
+      let input_ = input.clone();
+      match f(input_) {
+        Ok((i, o)) => {
+          *elem = o;
+          input = i;
+        }
+        Err(Err::Error(e)) => {
+          return Err(Err::Error(E::append(i, ErrorKind::Count, e)));
+        }
+        Err(e) => {
+          return Err(e);
+        }
+      }
+    }
+
+    Ok((input, ()))
+  }
+}
+
 /// Applies a parser until it fails and accumulates
 /// the results using a given function and initial value.
 /// # Arguments
 /// * `f` The parser to apply.
-/// * `init` The initial value.
+/// * `init` A function returning the initial value.
 /// * `g` The function that combines a result of `f` with
 ///       the current accumulator.
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// use nom::multi::fold_many0;
 /// use nom::bytes::complete::tag;
@@ -663,7 +617,7 @@
 /// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
 ///   fold_many0(
 ///     tag("abc"),
-///     Vec::new(),
+///     Vec::new,
 ///     |mut acc: Vec<_>, item| {
 ///       acc.push(item);
 ///       acc
@@ -676,24 +630,29 @@
 /// assert_eq!(parser("123123"), Ok(("123123", vec![])));
 /// assert_eq!(parser(""), Ok(("", vec![])));
 /// ```
-pub fn fold_many0<I, O, E, F, G, R>(f: F, init: R, g: G) -> impl Fn(I) -> IResult<I, R, E>
+pub fn fold_many0<I, O, E, F, G, H, R>(
+  mut f: F,
+  mut init: H,
+  mut g: G,
+) -> impl FnMut(I) -> IResult<I, R, E>
 where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  G: Fn(R, O) -> R,
+  I: Clone + InputLength,
+  F: Parser<I, O, E>,
+  G: FnMut(R, O) -> R,
+  H: FnMut() -> R,
   E: ParseError<I>,
-  R: Clone,
 {
   move |i: I| {
-    let mut res = init.clone();
-    let mut input = i.clone();
+    let mut res = init();
+    let mut input = i;
 
     loop {
       let i_ = input.clone();
-      match f(i_) {
+      let len = input.input_len();
+      match f.parse(i_) {
         Ok((i, o)) => {
-          // loop trip must always consume (otherwise infinite loops)
-          if i == input {
+          // infinite loop check: the parser must always consume
+          if i.input_len() == len {
             return Err(Err::Error(E::from_error_kind(input, ErrorKind::Many0)));
           }
 
@@ -711,37 +670,24 @@
   }
 }
 
-#[doc(hidden)]
-pub fn fold_many0c<I, O, E, F, G, R>(i: I, f: F, init: R, g: G) -> IResult<I, R, E>
-where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  G: Fn(R, O) -> R,
-  E: ParseError<I>,
-  R: Clone,
-{
-  fold_many0(f, init, g)(i)
-}
-
 /// Applies a parser until it fails and accumulates
 /// the results using a given function and initial value.
 /// Fails if the embedded parser does not succeed at least
 /// once.
 /// # Arguments
 /// * `f` The parser to apply.
-/// * `init` The initial value.
+/// * `init` A function returning the initial value.
 /// * `g` The function that combines a result of `f` with
 ///       the current accumulator.
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::multi::fold_many1;
 /// use nom::bytes::complete::tag;
 ///
 /// fn parser(s: &str) -> IResult<&str, Vec<&str>> {
 ///   fold_many1(
 ///     tag("abc"),
-///     Vec::new(),
+///     Vec::new,
 ///     |mut acc: Vec<_>, item| {
 ///       acc.push(item);
 ///       acc
@@ -751,36 +697,42 @@
 ///
 /// assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"])));
 /// assert_eq!(parser("abc123"), Ok(("123", vec!["abc"])));
-/// assert_eq!(parser("123123"), Err(Err::Error(("123123", ErrorKind::Many1))));
-/// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Many1))));
+/// assert_eq!(parser("123123"), Err(Err::Error(Error::new("123123", ErrorKind::Many1))));
+/// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Many1))));
 /// ```
-pub fn fold_many1<I, O, E, F, G, R>(f: F, init: R, g: G) -> impl Fn(I) -> IResult<I, R, E>
+pub fn fold_many1<I, O, E, F, G, H, R>(
+  mut f: F,
+  mut init: H,
+  mut g: G,
+) -> impl FnMut(I) -> IResult<I, R, E>
 where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  G: Fn(R, O) -> R,
+  I: Clone + InputLength,
+  F: Parser<I, O, E>,
+  G: FnMut(R, O) -> R,
+  H: FnMut() -> R,
   E: ParseError<I>,
-  R: Clone,
 {
   move |i: I| {
     let _i = i.clone();
-    let init = init.clone();
-    match f(_i) {
+    let init = init();
+    match f.parse(_i) {
       Err(Err::Error(_)) => Err(Err::Error(E::from_error_kind(i, ErrorKind::Many1))),
-      Err(e) => return Err(e),
+      Err(e) => Err(e),
       Ok((i1, o1)) => {
         let mut acc = g(init, o1);
         let mut input = i1;
 
         loop {
           let _input = input.clone();
-          match f(_input) {
+          let len = input.input_len();
+          match f.parse(_input) {
             Err(Err::Error(_)) => {
               break;
             }
             Err(e) => return Err(e),
             Ok((i, o)) => {
-              if i == input {
+              // infinite loop check: the parser must always consume
+              if i.input_len() == len {
                 return Err(Err::Failure(E::from_error_kind(i, ErrorKind::Many1)));
               }
 
@@ -796,18 +748,6 @@
   }
 }
 
-#[doc(hidden)]
-pub fn fold_many1c<I, O, E, F, G, R>(i: I, f: F, init: R, g: G) -> IResult<I, R, E>
-where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  G: Fn(R, O) -> R,
-  E: ParseError<I>,
-  R: Clone,
-{
-  fold_many1(f, init, g)(i)
-}
-
 /// Applies a parser `n` times or until it fails and accumulates
 /// the results using a given function and initial value.
 /// Fails if the embedded parser does not succeed at least `m`
@@ -816,11 +756,10 @@
 /// * `m` The minimum number of iterations.
 /// * `n` The maximum number of iterations.
 /// * `f` The parser to apply.
-/// * `init` The initial value.
+/// * `init` A function returning the initial value.
 /// * `g` The function that combines a result of `f` with
 ///       the current accumulator.
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
 /// use nom::multi::fold_many_m_n;
 /// use nom::bytes::complete::tag;
@@ -830,7 +769,7 @@
 ///     0,
 ///     2,
 ///     tag("abc"),
-///     Vec::new(),
+///     Vec::new,
 ///     |mut acc: Vec<_>, item| {
 ///       acc.push(item);
 ///       acc
@@ -844,34 +783,45 @@
 /// assert_eq!(parser(""), Ok(("", vec![])));
 /// assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));
 /// ```
-pub fn fold_many_m_n<I, O, E, F, G, R>(m: usize, n: usize, f: F, init: R, g: G) -> impl Fn(I) ->IResult<I, R, E>
+pub fn fold_many_m_n<I, O, E, F, G, H, R>(
+  min: usize,
+  max: usize,
+  mut parse: F,
+  mut init: H,
+  mut fold: G,
+) -> impl FnMut(I) -> IResult<I, R, E>
 where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  G: Fn(R, O) -> R,
+  I: Clone + InputLength,
+  F: Parser<I, O, E>,
+  G: FnMut(R, O) -> R,
+  H: FnMut() -> R,
   E: ParseError<I>,
-  R: Clone,
 {
-  move |i: I| {
-    let mut acc = init.clone();
-    let mut input = i.clone();
-    for count in 0..n {
-      let _input = input.clone();
-      match f(_input) {
-        Ok((i, o)) => {
-          // do not allow parsers that do not consume input (causes infinite loops)
-          if i == input {
-            return Err(Err::Error(E::from_error_kind(i, ErrorKind::ManyMN)));
+  move |mut input: I| {
+    if min > max {
+      return Err(Err::Failure(E::from_error_kind(input, ErrorKind::ManyMN)));
+    }
+
+    let mut acc = init();
+    for count in 0..max {
+      let len = input.input_len();
+      match parse.parse(input.clone()) {
+        Ok((tail, value)) => {
+          // infinite loop check: the parser must always consume
+          if tail.input_len() == len {
+            return Err(Err::Error(E::from_error_kind(tail, ErrorKind::ManyMN)));
           }
 
-          acc = g(acc, o);
-          input = i;
+          acc = fold(acc, value);
+          input = tail;
         }
         //FInputXMError: handle failure properly
-        Err(Err::Error(_)) => if count < m {
-          return Err(Err::Error(E::from_error_kind(i, ErrorKind::ManyMN)));
-        } else {
-          break;
+        Err(Err::Error(err)) => {
+          if count < min {
+            return Err(Err::Error(E::append(input, ErrorKind::ManyMN, err)));
+          } else {
+            break;
+          }
         }
         Err(e) => return Err(e),
       }
@@ -881,28 +831,14 @@
   }
 }
 
-#[doc(hidden)]
-pub fn fold_many_m_nc<I, O, E, F, G, R>(i: I, m: usize, n: usize, f: F, init: R, g: G) -> IResult<I, R, E>
-where
-  I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E>,
-  G: Fn(R, O) -> R,
-  E: ParseError<I>,
-  R: Clone,
-{
-  fold_many_m_n(m, n, f, init, g)(i)
-}
-
 /// Gets a number from the parser and returns a
 /// subslice of the input of that size.
-/// If the parser returns Incomplete,
-/// length_data will return an error.
+/// If the parser returns `Incomplete`,
+/// `length_data` will return an error.
 /// # Arguments
 /// * `f` The parser to apply.
 /// ```rust
-/// # #[macro_use] extern crate nom;
 /// # use nom::{Err, error::ErrorKind, Needed, IResult};
-/// # use nom::Needed::Size;
 /// use nom::number::complete::be_u16;
 /// use nom::multi::length_data;
 /// use nom::bytes::complete::tag;
@@ -912,22 +848,25 @@
 /// }
 ///
 /// assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"efg"[..], &b"abc"[..])));
-/// assert_eq!(parser(b"\x00\x03"), Err(Err::Incomplete(Size(3))));
+/// assert_eq!(parser(b"\x00\x03a"), Err(Err::Incomplete(Needed::new(2))));
 /// ```
-pub fn length_data<I, N, E, F>(f: F) -> impl Fn(I) -> IResult<I, I, E>
+pub fn length_data<I, N, E, F>(mut f: F) -> impl FnMut(I) -> IResult<I, I, E>
 where
-  I: Clone + InputLength + InputTake,
-  N: Copy + ToUsize,
-  F: Fn(I) -> IResult<I, N, E>,
+  I: InputLength + InputTake,
+  N: ToUsize,
+  F: Parser<I, N, E>,
   E: ParseError<I>,
 {
   move |i: I| {
-    let (i, length) = f(i)?;
+    let (i, length) = f.parse(i)?;
 
     let length: usize = length.to_usize();
 
-    if i.input_len() < length {
-      Err(Err::Incomplete(Needed::Size(length)))
+    if let Some(needed) = length
+      .checked_sub(i.input_len())
+      .and_then(NonZeroUsize::new)
+    {
+      Err(Err::Incomplete(Needed::Size(needed)))
     } else {
       Ok(i.take_split(length))
     }
@@ -937,14 +876,13 @@
 /// Gets a number from the first parser,
 /// takes a subslice of the input of that size,
 /// then applies the second parser on that subslice.
-/// If the second parser returns Incomplete,
-/// length_value will return an error.
+/// If the second parser returns `Incomplete`,
+/// `length_value` will return an error.
 /// # Arguments
 /// * `f` The parser to apply.
+/// * `g` The parser to apply on the subslice.
 /// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, error::ErrorKind, Needed, IResult};
-/// # use nom::Needed::Size;
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
 /// use nom::number::complete::be_u16;
 /// use nom::multi::length_value;
 /// use nom::bytes::complete::tag;
@@ -954,44 +892,90 @@
 /// }
 ///
 /// assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"efg"[..], &b"abc"[..])));
-/// assert_eq!(parser(b"\x00\x03123123"), Err(Err::Error((&b"123"[..], ErrorKind::Tag))));
-/// assert_eq!(parser(b"\x00\x03"), Err(Err::Incomplete(Size(3))));
+/// assert_eq!(parser(b"\x00\x03123123"), Err(Err::Error(Error::new(&b"123"[..], ErrorKind::Tag))));
+/// assert_eq!(parser(b"\x00\x03a"), Err(Err::Incomplete(Needed::new(2))));
 /// ```
-pub fn length_value<I, O, N, E, F, G>(f: F, g: G) -> impl Fn(I) -> IResult<I, O, E>
+pub fn length_value<I, O, N, E, F, G>(mut f: F, mut g: G) -> impl FnMut(I) -> IResult<I, O, E>
 where
   I: Clone + InputLength + InputTake,
-  N: Copy + ToUsize,
-  F: Fn(I) -> IResult<I, N, E>,
-  G: Fn(I) -> IResult<I, O, E>,
+  N: ToUsize,
+  F: Parser<I, N, E>,
+  G: Parser<I, O, E>,
   E: ParseError<I>,
 {
   move |i: I| {
-    let (i, length) = f(i)?;
+    let (i, length) = f.parse(i)?;
 
     let length: usize = length.to_usize();
 
-    if i.input_len() < length {
-      Err(Err::Incomplete(Needed::Size(length)))
+    if let Some(needed) = length
+      .checked_sub(i.input_len())
+      .and_then(NonZeroUsize::new)
+    {
+      Err(Err::Incomplete(Needed::Size(needed)))
     } else {
       let (rest, i) = i.take_split(length);
-      match g(i.clone()) {
-        Err(Err::Incomplete(_)) =>
-          Err(Err::Error(E::from_error_kind(i, ErrorKind::Complete))),
+      match g.parse(i.clone()) {
+        Err(Err::Incomplete(_)) => Err(Err::Error(E::from_error_kind(i, ErrorKind::Complete))),
         Err(e) => Err(e),
-        Ok((_, o)) => Ok((rest,o)),
+        Ok((_, o)) => Ok((rest, o)),
       }
     }
   }
 }
 
-#[doc(hidden)]
-pub fn length_valuec<I, O, N, E, F, G>(i: I, f: F, g: G) -> IResult<I, O, E>
+/// Gets a number from the first parser,
+/// then applies the second parser that many times.
+/// # Arguments
+/// * `f` The parser to apply to obtain the count.
+/// * `g` The parser to apply repeatedly.
+/// ```rust
+/// # use nom::{Err, error::{Error, ErrorKind}, Needed, IResult};
+/// use nom::number::complete::u8;
+/// use nom::multi::length_count;
+/// use nom::bytes::complete::tag;
+/// use nom::combinator::map;
+///
+/// fn parser(s: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+///   length_count(map(u8, |i| {
+///      println!("got number: {}", i);
+///      i
+///   }), tag("abc"))(s)
+/// }
+///
+/// assert_eq!(parser(&b"\x02abcabcabc"[..]), Ok(((&b"abc"[..], vec![&b"abc"[..], &b"abc"[..]]))));
+/// assert_eq!(parser(b"\x03123123123"), Err(Err::Error(Error::new(&b"123123123"[..], ErrorKind::Tag))));
+/// ```
+#[cfg(feature = "alloc")]
+pub fn length_count<I, O, N, E, F, G>(mut f: F, mut g: G) -> impl FnMut(I) -> IResult<I, Vec<O>, E>
 where
-  I: Clone + InputLength + InputTake,
-  N: Copy + ToUsize,
-  F: Fn(I) -> IResult<I, N, E>,
-  G: Fn(I) -> IResult<I, O, E>,
+  I: Clone,
+  N: ToUsize,
+  F: Parser<I, N, E>,
+  G: Parser<I, O, E>,
   E: ParseError<I>,
 {
-  length_value(f, g)(i)
+  move |i: I| {
+    let (i, count) = f.parse(i)?;
+    let mut input = i.clone();
+    let mut res = Vec::new();
+
+    for _ in 0..count.to_usize() {
+      let input_ = input.clone();
+      match g.parse(input_) {
+        Ok((i, o)) => {
+          res.push(o);
+          input = i;
+        }
+        Err(Err::Error(e)) => {
+          return Err(Err::Error(E::append(i, ErrorKind::Count, e)));
+        }
+        Err(e) => {
+          return Err(e);
+        }
+      }
+    }
+
+    Ok((input, res))
+  }
 }
diff --git a/src/multi/tests.rs b/src/multi/tests.rs
new file mode 100644
index 0000000..2a96f84
--- /dev/null
+++ b/src/multi/tests.rs
@@ -0,0 +1,544 @@
+use super::{length_data, length_value, many0_count, many1_count};
+use crate::{
+  bytes::streaming::tag,
+  character::streaming::digit1 as digit,
+  error::{ErrorKind, ParseError},
+  internal::{Err, IResult, Needed},
+  lib::std::str::{self, FromStr},
+  number::streaming::{be_u16, be_u8},
+  sequence::{pair, tuple},
+};
+#[cfg(feature = "alloc")]
+use crate::{
+  lib::std::vec::Vec,
+  multi::{
+    count, fold_many0, fold_many1, fold_many_m_n, length_count, many0, many1, many_m_n, many_till,
+    separated_list0, separated_list1,
+  },
+};
+
+#[test]
+#[cfg(feature = "alloc")]
+fn separated_list0_test() {
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    separated_list0(tag(","), tag("abcd"))(i)
+  }
+  fn multi_empty(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    separated_list0(tag(","), tag(""))(i)
+  }
+  fn empty_sep(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    separated_list0(tag(""), tag("abc"))(i)
+  }
+  fn multi_longsep(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    separated_list0(tag(".."), tag("abcd"))(i)
+  }
+
+  let a = &b"abcdef"[..];
+  let b = &b"abcd,abcdef"[..];
+  let c = &b"azerty"[..];
+  let d = &b",,abc"[..];
+  let e = &b"abcd,abcd,ef"[..];
+  let f = &b"abc"[..];
+  let g = &b"abcd."[..];
+  let h = &b"abcd,abc"[..];
+  let i = &b"abcabc"[..];
+
+  let res1 = vec![&b"abcd"[..]];
+  assert_eq!(multi(a), Ok((&b"ef"[..], res1)));
+  let res2 = vec![&b"abcd"[..], &b"abcd"[..]];
+  assert_eq!(multi(b), Ok((&b"ef"[..], res2)));
+  assert_eq!(multi(c), Ok((&b"azerty"[..], Vec::new())));
+  let res3 = vec![&b""[..], &b""[..], &b""[..]];
+  assert_eq!(multi_empty(d), Ok((&b"abc"[..], res3)));
+  let i_err_pos = &i[3..];
+  assert_eq!(
+    empty_sep(i),
+    Err(Err::Error(error_position!(
+      i_err_pos,
+      ErrorKind::SeparatedList
+    )))
+  );
+  let res4 = vec![&b"abcd"[..], &b"abcd"[..]];
+  assert_eq!(multi(e), Ok((&b",ef"[..], res4)));
+
+  assert_eq!(multi(f), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(multi_longsep(g), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(multi(h), Err(Err::Incomplete(Needed::new(1))));
+}
+
+#[test]
+#[cfg(feature = "alloc")]
+fn separated_list1_test() {
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    separated_list1(tag(","), tag("abcd"))(i)
+  }
+  fn multi_longsep(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    separated_list1(tag(".."), tag("abcd"))(i)
+  }
+
+  let a = &b"abcdef"[..];
+  let b = &b"abcd,abcdef"[..];
+  let c = &b"azerty"[..];
+  let d = &b"abcd,abcd,ef"[..];
+
+  let f = &b"abc"[..];
+  let g = &b"abcd."[..];
+  let h = &b"abcd,abc"[..];
+
+  let res1 = vec![&b"abcd"[..]];
+  assert_eq!(multi(a), Ok((&b"ef"[..], res1)));
+  let res2 = vec![&b"abcd"[..], &b"abcd"[..]];
+  assert_eq!(multi(b), Ok((&b"ef"[..], res2)));
+  assert_eq!(
+    multi(c),
+    Err(Err::Error(error_position!(c, ErrorKind::Tag)))
+  );
+  let res3 = vec![&b"abcd"[..], &b"abcd"[..]];
+  assert_eq!(multi(d), Ok((&b",ef"[..], res3)));
+
+  assert_eq!(multi(f), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(multi_longsep(g), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(multi(h), Err(Err::Incomplete(Needed::new(1))));
+}
+
+#[test]
+#[cfg(feature = "alloc")]
+fn many0_test() {
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    many0(tag("abcd"))(i)
+  }
+  fn multi_empty(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    many0(tag(""))(i)
+  }
+
+  assert_eq!(multi(&b"abcdef"[..]), Ok((&b"ef"[..], vec![&b"abcd"[..]])));
+  assert_eq!(
+    multi(&b"abcdabcdefgh"[..]),
+    Ok((&b"efgh"[..], vec![&b"abcd"[..], &b"abcd"[..]]))
+  );
+  assert_eq!(multi(&b"azerty"[..]), Ok((&b"azerty"[..], Vec::new())));
+  assert_eq!(multi(&b"abcdab"[..]), Err(Err::Incomplete(Needed::new(2))));
+  assert_eq!(multi(&b"abcd"[..]), Err(Err::Incomplete(Needed::new(4))));
+  assert_eq!(multi(&b""[..]), Err(Err::Incomplete(Needed::new(4))));
+  assert_eq!(
+    multi_empty(&b"abcdef"[..]),
+    Err(Err::Error(error_position!(
+      &b"abcdef"[..],
+      ErrorKind::Many0
+    )))
+  );
+}
+
+#[cfg(nightly)]
+use test::Bencher;
+
+#[cfg(nightly)]
+#[bench]
+fn many0_bench(b: &mut Bencher) {
+  named!(multi<&[u8],Vec<&[u8]> >, many0!(tag!("abcd")));
+  b.iter(|| multi(&b"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd"[..]));
+}
+
+#[test]
+#[cfg(feature = "alloc")]
+fn many1_test() {
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    many1(tag("abcd"))(i)
+  }
+
+  let a = &b"abcdef"[..];
+  let b = &b"abcdabcdefgh"[..];
+  let c = &b"azerty"[..];
+  let d = &b"abcdab"[..];
+
+  let res1 = vec![&b"abcd"[..]];
+  assert_eq!(multi(a), Ok((&b"ef"[..], res1)));
+  let res2 = vec![&b"abcd"[..], &b"abcd"[..]];
+  assert_eq!(multi(b), Ok((&b"efgh"[..], res2)));
+  assert_eq!(
+    multi(c),
+    Err(Err::Error(error_position!(c, ErrorKind::Tag)))
+  );
+  assert_eq!(multi(d), Err(Err::Incomplete(Needed::new(2))));
+}
+
+#[test]
+#[cfg(feature = "alloc")]
+fn many_till_test() {
+  fn multi(i: &[u8]) -> IResult<&[u8], (Vec<&[u8]>, &[u8])> {
+    many_till(tag("abcd"), tag("efgh"))(i)
+  }
+
+  let a = b"abcdabcdefghabcd";
+  let b = b"efghabcd";
+  let c = b"azerty";
+
+  let res_a = (vec![&b"abcd"[..], &b"abcd"[..]], &b"efgh"[..]);
+  let res_b: (Vec<&[u8]>, &[u8]) = (Vec::new(), &b"efgh"[..]);
+  assert_eq!(multi(&a[..]), Ok((&b"abcd"[..], res_a)));
+  assert_eq!(multi(&b[..]), Ok((&b"abcd"[..], res_b)));
+  assert_eq!(
+    multi(&c[..]),
+    Err(Err::Error(error_node_position!(
+      &c[..],
+      ErrorKind::ManyTill,
+      error_position!(&c[..], ErrorKind::Tag)
+    )))
+  );
+}
+
+#[test]
+#[cfg(feature = "std")]
+fn infinite_many() {
+  fn tst(input: &[u8]) -> IResult<&[u8], &[u8]> {
+    println!("input: {:?}", input);
+    Err(Err::Error(error_position!(input, ErrorKind::Tag)))
+  }
+
+  // should not go into an infinite loop
+  fn multi0(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    many0(tst)(i)
+  }
+  let a = &b"abcdef"[..];
+  assert_eq!(multi0(a), Ok((a, Vec::new())));
+
+  fn multi1(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    many1(tst)(i)
+  }
+  let a = &b"abcdef"[..];
+  assert_eq!(
+    multi1(a),
+    Err(Err::Error(error_position!(a, ErrorKind::Tag)))
+  );
+}
+
+#[test]
+#[cfg(feature = "alloc")]
+fn many_m_n_test() {
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    many_m_n(2, 4, tag("Abcd"))(i)
+  }
+
+  let a = &b"Abcdef"[..];
+  let b = &b"AbcdAbcdefgh"[..];
+  let c = &b"AbcdAbcdAbcdAbcdefgh"[..];
+  let d = &b"AbcdAbcdAbcdAbcdAbcdefgh"[..];
+  let e = &b"AbcdAb"[..];
+
+  assert_eq!(
+    multi(a),
+    Err(Err::Error(error_position!(&b"ef"[..], ErrorKind::Tag)))
+  );
+  let res1 = vec![&b"Abcd"[..], &b"Abcd"[..]];
+  assert_eq!(multi(b), Ok((&b"efgh"[..], res1)));
+  let res2 = vec![&b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..]];
+  assert_eq!(multi(c), Ok((&b"efgh"[..], res2)));
+  let res3 = vec![&b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..]];
+  assert_eq!(multi(d), Ok((&b"Abcdefgh"[..], res3)));
+  assert_eq!(multi(e), Err(Err::Incomplete(Needed::new(2))));
+}
+
+#[test]
+#[cfg(feature = "alloc")]
+fn count_test() {
+  const TIMES: usize = 2;
+  fn cnt_2(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    count(tag("abc"), TIMES)(i)
+  }
+
+  assert_eq!(
+    cnt_2(&b"abcabcabcdef"[..]),
+    Ok((&b"abcdef"[..], vec![&b"abc"[..], &b"abc"[..]]))
+  );
+  assert_eq!(cnt_2(&b"ab"[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(cnt_2(&b"abcab"[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(
+    cnt_2(&b"xxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    cnt_2(&b"xxxabcabcdef"[..]),
+    Err(Err::Error(error_position!(
+      &b"xxxabcabcdef"[..],
+      ErrorKind::Tag
+    )))
+  );
+  assert_eq!(
+    cnt_2(&b"abcxxxabcdef"[..]),
+    Err(Err::Error(error_position!(
+      &b"xxxabcdef"[..],
+      ErrorKind::Tag
+    )))
+  );
+}
+
+#[test]
+#[cfg(feature = "alloc")]
+fn count_zero() {
+  const TIMES: usize = 0;
+  fn counter_2(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    count(tag("abc"), TIMES)(i)
+  }
+
+  let done = &b"abcabcabcdef"[..];
+  let parsed_done = Vec::new();
+  let rest = done;
+  let incomplete_1 = &b"ab"[..];
+  let parsed_incompl_1 = Vec::new();
+  let incomplete_2 = &b"abcab"[..];
+  let parsed_incompl_2 = Vec::new();
+  let error = &b"xxx"[..];
+  let error_remain = &b"xxx"[..];
+  let parsed_err = Vec::new();
+  let error_1 = &b"xxxabcabcdef"[..];
+  let parsed_err_1 = Vec::new();
+  let error_1_remain = &b"xxxabcabcdef"[..];
+  let error_2 = &b"abcxxxabcdef"[..];
+  let parsed_err_2 = Vec::new();
+  let error_2_remain = &b"abcxxxabcdef"[..];
+
+  assert_eq!(counter_2(done), Ok((rest, parsed_done)));
+  assert_eq!(
+    counter_2(incomplete_1),
+    Ok((incomplete_1, parsed_incompl_1))
+  );
+  assert_eq!(
+    counter_2(incomplete_2),
+    Ok((incomplete_2, parsed_incompl_2))
+  );
+  assert_eq!(counter_2(error), Ok((error_remain, parsed_err)));
+  assert_eq!(counter_2(error_1), Ok((error_1_remain, parsed_err_1)));
+  assert_eq!(counter_2(error_2), Ok((error_2_remain, parsed_err_2)));
+}
+
+#[derive(Debug, Clone, PartialEq)]
+pub struct NilError;
+
+impl<I> From<(I, ErrorKind)> for NilError {
+  fn from(_: (I, ErrorKind)) -> Self {
+    NilError
+  }
+}
+
+impl<I> ParseError<I> for NilError {
+  fn from_error_kind(_: I, _: ErrorKind) -> NilError {
+    NilError
+  }
+  fn append(_: I, _: ErrorKind, _: NilError) -> NilError {
+    NilError
+  }
+}
+
+fn number(i: &[u8]) -> IResult<&[u8], u32> {
+  use crate::combinator::map_res;
+
+  map_res(map_res(digit, str::from_utf8), FromStr::from_str)(i)
+}
+
+#[test]
+#[cfg(feature = "alloc")]
+fn length_count_test() {
+  fn cnt(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    length_count(number, tag("abc"))(i)
+  }
+
+  assert_eq!(
+    cnt(&b"2abcabcabcdef"[..]),
+    Ok((&b"abcdef"[..], vec![&b"abc"[..], &b"abc"[..]]))
+  );
+  assert_eq!(cnt(&b"2ab"[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(cnt(&b"3abcab"[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(
+    cnt(&b"xxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Digit)))
+  );
+  assert_eq!(
+    cnt(&b"2abcxxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
+  );
+}
+
+#[test]
+fn length_data_test() {
+  fn take(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    length_data(number)(i)
+  }
+
+  assert_eq!(
+    take(&b"6abcabcabcdef"[..]),
+    Ok((&b"abcdef"[..], &b"abcabc"[..]))
+  );
+  assert_eq!(take(&b"3ab"[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(
+    take(&b"xxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Digit)))
+  );
+  assert_eq!(take(&b"2abcxxx"[..]), Ok((&b"cxxx"[..], &b"ab"[..])));
+}
+
+#[test]
+fn length_value_test() {
+  fn length_value_1(i: &[u8]) -> IResult<&[u8], u16> {
+    length_value(be_u8, be_u16)(i)
+  }
+  fn length_value_2(i: &[u8]) -> IResult<&[u8], (u8, u8)> {
+    length_value(be_u8, tuple((be_u8, be_u8)))(i)
+  }
+
+  let i1 = [0, 5, 6];
+  assert_eq!(
+    length_value_1(&i1),
+    Err(Err::Error(error_position!(&b""[..], ErrorKind::Complete)))
+  );
+  assert_eq!(
+    length_value_2(&i1),
+    Err(Err::Error(error_position!(&b""[..], ErrorKind::Complete)))
+  );
+
+  let i2 = [1, 5, 6, 3];
+  assert_eq!(
+    length_value_1(&i2),
+    Err(Err::Error(error_position!(&i2[1..2], ErrorKind::Complete)))
+  );
+  assert_eq!(
+    length_value_2(&i2),
+    Err(Err::Error(error_position!(&i2[1..2], ErrorKind::Complete)))
+  );
+
+  let i3 = [2, 5, 6, 3, 4, 5, 7];
+  assert_eq!(length_value_1(&i3), Ok((&i3[3..], 1286)));
+  assert_eq!(length_value_2(&i3), Ok((&i3[3..], (5, 6))));
+
+  let i4 = [3, 5, 6, 3, 4, 5];
+  assert_eq!(length_value_1(&i4), Ok((&i4[4..], 1286)));
+  assert_eq!(length_value_2(&i4), Ok((&i4[4..], (5, 6))));
+}
+
+#[test]
+#[cfg(feature = "alloc")]
+fn fold_many0_test() {
+  fn fold_into_vec<T>(mut acc: Vec<T>, item: T) -> Vec<T> {
+    acc.push(item);
+    acc
+  }
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    fold_many0(tag("abcd"), Vec::new, fold_into_vec)(i)
+  }
+  fn multi_empty(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    fold_many0(tag(""), Vec::new, fold_into_vec)(i)
+  }
+
+  assert_eq!(multi(&b"abcdef"[..]), Ok((&b"ef"[..], vec![&b"abcd"[..]])));
+  assert_eq!(
+    multi(&b"abcdabcdefgh"[..]),
+    Ok((&b"efgh"[..], vec![&b"abcd"[..], &b"abcd"[..]]))
+  );
+  assert_eq!(multi(&b"azerty"[..]), Ok((&b"azerty"[..], Vec::new())));
+  assert_eq!(multi(&b"abcdab"[..]), Err(Err::Incomplete(Needed::new(2))));
+  assert_eq!(multi(&b"abcd"[..]), Err(Err::Incomplete(Needed::new(4))));
+  assert_eq!(multi(&b""[..]), Err(Err::Incomplete(Needed::new(4))));
+  assert_eq!(
+    multi_empty(&b"abcdef"[..]),
+    Err(Err::Error(error_position!(
+      &b"abcdef"[..],
+      ErrorKind::Many0
+    )))
+  );
+}
+
+#[test]
+#[cfg(feature = "alloc")]
+fn fold_many1_test() {
+  fn fold_into_vec<T>(mut acc: Vec<T>, item: T) -> Vec<T> {
+    acc.push(item);
+    acc
+  }
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    fold_many1(tag("abcd"), Vec::new, fold_into_vec)(i)
+  }
+
+  let a = &b"abcdef"[..];
+  let b = &b"abcdabcdefgh"[..];
+  let c = &b"azerty"[..];
+  let d = &b"abcdab"[..];
+
+  let res1 = vec![&b"abcd"[..]];
+  assert_eq!(multi(a), Ok((&b"ef"[..], res1)));
+  let res2 = vec![&b"abcd"[..], &b"abcd"[..]];
+  assert_eq!(multi(b), Ok((&b"efgh"[..], res2)));
+  assert_eq!(
+    multi(c),
+    Err(Err::Error(error_position!(c, ErrorKind::Many1)))
+  );
+  assert_eq!(multi(d), Err(Err::Incomplete(Needed::new(2))));
+}
+
+#[test]
+#[cfg(feature = "alloc")]
+fn fold_many_m_n_test() {
+  fn fold_into_vec<T>(mut acc: Vec<T>, item: T) -> Vec<T> {
+    acc.push(item);
+    acc
+  }
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    fold_many_m_n(2, 4, tag("Abcd"), Vec::new, fold_into_vec)(i)
+  }
+
+  let a = &b"Abcdef"[..];
+  let b = &b"AbcdAbcdefgh"[..];
+  let c = &b"AbcdAbcdAbcdAbcdefgh"[..];
+  let d = &b"AbcdAbcdAbcdAbcdAbcdefgh"[..];
+  let e = &b"AbcdAb"[..];
+
+  assert_eq!(
+    multi(a),
+    Err(Err::Error(error_position!(&b"ef"[..], ErrorKind::Tag)))
+  );
+  let res1 = vec![&b"Abcd"[..], &b"Abcd"[..]];
+  assert_eq!(multi(b), Ok((&b"efgh"[..], res1)));
+  let res2 = vec![&b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..]];
+  assert_eq!(multi(c), Ok((&b"efgh"[..], res2)));
+  let res3 = vec![&b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..], &b"Abcd"[..]];
+  assert_eq!(multi(d), Ok((&b"Abcdefgh"[..], res3)));
+  assert_eq!(multi(e), Err(Err::Incomplete(Needed::new(2))));
+}
+
+#[test]
+fn many0_count_test() {
+  fn count0_nums(i: &[u8]) -> IResult<&[u8], usize> {
+    many0_count(pair(digit, tag(",")))(i)
+  }
+
+  assert_eq!(count0_nums(&b"123,junk"[..]), Ok((&b"junk"[..], 1)));
+
+  assert_eq!(count0_nums(&b"123,45,junk"[..]), Ok((&b"junk"[..], 2)));
+
+  assert_eq!(
+    count0_nums(&b"1,2,3,4,5,6,7,8,9,0,junk"[..]),
+    Ok((&b"junk"[..], 10))
+  );
+
+  assert_eq!(count0_nums(&b"hello"[..]), Ok((&b"hello"[..], 0)));
+}
+
+#[test]
+fn many1_count_test() {
+  fn count1_nums(i: &[u8]) -> IResult<&[u8], usize> {
+    many1_count(pair(digit, tag(",")))(i)
+  }
+
+  assert_eq!(count1_nums(&b"123,45,junk"[..]), Ok((&b"junk"[..], 2)));
+
+  assert_eq!(
+    count1_nums(&b"1,2,3,4,5,6,7,8,9,0,junk"[..]),
+    Ok((&b"junk"[..], 10))
+  );
+
+  assert_eq!(
+    count1_nums(&b"hello"[..]),
+    Err(Err::Error(error_position!(
+      &b"hello"[..],
+      ErrorKind::Many1Count
+    )))
+  );
+}
diff --git a/src/number/complete.rs b/src/number/complete.rs
index b8d4232..d23079e 100644
--- a/src/number/complete.rs
+++ b/src/number/complete.rs
@@ -1,19 +1,41 @@
-//! parsers recognizing numbers, complete input version
+//! Parsers recognizing numbers, complete input version
 
-use crate::internal::*;
-use crate::error::ParseError;
-use crate::traits::{AsChar, InputIter, InputLength, InputTakeAtPosition};
-use crate::lib::std::ops::{RangeFrom, RangeTo};
-use crate::traits::{Offset, Slice};
-use crate::error::{ErrorKind, make_error};
-use crate::character::complete::{char, digit1};
-use crate::combinator::{opt, cut, map, recognize};
 use crate::branch::alt;
-use crate::sequence::{tuple, pair};
+use crate::bytes::complete::tag;
+use crate::character::complete::{char, digit1, sign};
+use crate::combinator::{cut, map, opt, recognize};
+use crate::error::ParseError;
+use crate::error::{make_error, ErrorKind};
+use crate::internal::*;
+use crate::lib::std::ops::{Range, RangeFrom, RangeTo};
+use crate::sequence::{pair, tuple};
+use crate::traits::{
+  AsBytes, AsChar, Compare, InputIter, InputLength, InputTake, InputTakeAtPosition, Offset, Slice,
+};
 
-/// Recognizes an unsigned 1 byte integer
+#[doc(hidden)]
+macro_rules! map(
+  // Internal parser, do not use directly
+  (__impl $i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
+    $crate::combinator::map(move |i| {$submac!(i, $($args)*)}, $g).parse($i)
+  );
+  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
+    map!(__impl $i, $submac!($($args)*), $g)
+  );
+  ($i:expr, $f:expr, $g:expr) => (
+    map!(__impl $i, call!($f), $g)
+  );
+);
+
+#[doc(hidden)]
+macro_rules! call (
+  ($i:expr, $fun:expr) => ( $fun( $i ) );
+  ($i:expr, $fun:expr, $($args:expr),* ) => ( $fun( $i, $($args),* ) );
+);
+
+/// Recognizes an unsigned 1 byte integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -23,21 +45,27 @@
 ///   be_u8(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"\x03abcefg"[..], 0x00)));
-/// assert_eq!(parser(b""), Err(Err::Error((&[][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Error((&[][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn be_u8<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u8, E> {
-  if i.len() < 1 {
-    Err(Err::Error(make_error(i, ErrorKind::Eof)))
+pub fn be_u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 1;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
   } else {
-    Ok((&i[1..], i[0]))
+    let res = input.iter_elements().next().unwrap();
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a big endian unsigned 2 bytes integer
+/// Recognizes a big endian unsigned 2 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -47,22 +75,30 @@
 ///   be_u16(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"abcefg"[..], 0x0003)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn be_u16<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u16, E> {
-  if i.len() < 2 {
-    Err(Err::Error(make_error(i, ErrorKind::Eof)))
+pub fn be_u16<I, E: ParseError<I>>(input: I) -> IResult<I, u16, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 2;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
   } else {
-    let res = ((i[0] as u16) << 8) + i[1] as u16;
-    Ok((&i[2..], res))
+    let mut res = 0u16;
+    for byte in input.iter_elements().take(bound) {
+      res = (res << 8) + byte as u16;
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a big endian unsigned 3 byte integer
+/// Recognizes a big endian unsigned 3 byte integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -72,22 +108,30 @@
 ///   be_u24(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03\x05abcefg"), Ok((&b"abcefg"[..], 0x000305)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn be_u24<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u32, E> {
-  if i.len() < 3 {
-    Err(Err::Error(make_error(i, ErrorKind::Eof)))
+pub fn be_u24<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 3;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
   } else {
-    let res = ((i[0] as u32) << 16) + ((i[1] as u32) << 8) + (i[2] as u32);
-    Ok((&i[3..], res))
+    let mut res = 0u32;
+    for byte in input.iter_elements().take(bound) {
+      res = (res << 8) + byte as u32;
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a big endian unsigned 4 bytes integer
+/// Recognizes a big endian unsigned 4 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -97,22 +141,30 @@
 ///   be_u32(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03\x05\x07abcefg"), Ok((&b"abcefg"[..], 0x00030507)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn be_u32<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u32, E> {
-  if i.len() < 4 {
-    Err(Err::Error(make_error(i, ErrorKind::Eof)))
+pub fn be_u32<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 4;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
   } else {
-    let res = ((i[0] as u32) << 24) + ((i[1] as u32) << 16) + ((i[2] as u32) << 8) + i[3] as u32;
-    Ok((&i[4..], res))
+    let mut res = 0u32;
+    for byte in input.iter_elements().take(bound) {
+      res = (res << 8) + byte as u32;
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a big endian unsigned 8 bytes integer
+/// Recognizes a big endian unsigned 8 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -122,23 +174,30 @@
 ///   be_u64(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"), Ok((&b"abcefg"[..], 0x0001020304050607)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn be_u64<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u64, E> {
-  if i.len() < 8 {
-    Err(Err::Error(make_error(i, ErrorKind::Eof)))
+pub fn be_u64<I, E: ParseError<I>>(input: I) -> IResult<I, u64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 8;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
   } else {
-    let res = ((i[0] as u64) << 56) + ((i[1] as u64) << 48) + ((i[2] as u64) << 40) + ((i[3] as u64) << 32) + ((i[4] as u64) << 24)
-      + ((i[5] as u64) << 16) + ((i[6] as u64) << 8) + i[7] as u64;
-    Ok((&i[8..], res))
+    let mut res = 0u64;
+    for byte in input.iter_elements().take(bound) {
+      res = (res << 8) + byte as u64;
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a big endian unsigned 16 bytes integer
+/// Recognizes a big endian unsigned 16 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -148,38 +207,31 @@
 ///   be_u128(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
 #[cfg(stable_i128)]
-pub fn be_u128<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u128, E> {
-  if i.len() < 16 {
-    Err(Err::Error(make_error(i, ErrorKind::Eof)))
+pub fn be_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 16;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
   } else {
-    let res = ((i[0] as u128) << 120)
-      + ((i[1] as u128) << 112)
-      + ((i[2] as u128) << 104)
-      + ((i[3] as u128) << 96)
-      + ((i[4] as u128) << 88)
-      + ((i[5] as u128) << 80)
-      + ((i[6] as u128) << 72)
-      + ((i[7] as u128) << 64)
-      + ((i[8] as u128) << 56)
-      + ((i[9] as u128) << 48)
-      + ((i[10] as u128) << 40)
-      + ((i[11] as u128) << 32)
-      + ((i[12] as u128) << 24)
-      + ((i[13] as u128) << 16)
-      + ((i[14] as u128) << 8)
-      + i[15] as u128;
-    Ok((&i[16..], res))
+    let mut res = 0u128;
+    for byte in input.iter_elements().take(bound) {
+      res = (res << 8) + byte as u128;
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a signed 1 byte integer
+/// Recognizes a signed 1 byte integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -189,17 +241,20 @@
 ///   be_i8(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"\x03abcefg"[..], 0x00)));
-/// assert_eq!(parser(b""), Err(Err::Error((&[][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Error((&[][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn be_i8<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i8, E> {
-  map!(i, be_u8, |x| x as i8)
+pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, be_u8, |x| x as i8)
 }
 
-/// Recognizes a big endian signed 2 bytes integer
+/// Recognizes a big endian signed 2 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -209,17 +264,20 @@
 ///   be_i16(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"abcefg"[..], 0x0003)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn be_i16<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i16, E> {
-  map!(i, be_u16, |x| x as i16)
+pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, be_u16, |x| x as i16)
 }
 
-/// Recognizes a big endian signed 3 bytes integer
+/// Recognizes a big endian signed 3 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -229,22 +287,25 @@
 ///   be_i24(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03\x05abcefg"), Ok((&b"abcefg"[..], 0x000305)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn be_i24<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i32, E> {
+pub fn be_i24<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
   // Same as the unsigned version but we need to sign-extend manually here
-  map!(i, be_u24, |x| if x & 0x80_00_00 != 0 {
+  map!(input, be_u24, |x| if x & 0x80_00_00 != 0 {
     (x | 0xff_00_00_00) as i32
   } else {
     x as i32
   })
 }
 
-/// Recognizes a big endian signed 4 bytes integer
+/// Recognizes a big endian signed 4 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Teturns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -254,17 +315,20 @@
 ///   be_i32(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03\x05\x07abcefg"), Ok((&b"abcefg"[..], 0x00030507)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn be_i32<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i32, E> {
-  map!(i, be_u32, |x| x as i32)
+pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, be_u32, |x| x as i32)
 }
 
-/// Recognizes a big endian signed 8 bytes integer
+/// Recognizes a big endian signed 8 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -274,17 +338,20 @@
 ///   be_i64(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"), Ok((&b"abcefg"[..], 0x0001020304050607)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn be_i64<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i64, E> {
-  map!(i, be_u64, |x| x as i64)
+pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, be_u64, |x| x as i64)
 }
 
-/// Recognizes a big endian signed 16 bytes integer
+/// Recognizes a big endian signed 16 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -294,18 +361,21 @@
 ///   be_i128(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
 #[cfg(stable_i128)]
-pub fn be_i128<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i128, E> {
-  map!(i, be_u128, |x| x as i128)
+pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, be_u128, |x| x as i128)
 }
 
-/// Recognizes an unsigned 1 byte integer
+/// Recognizes an unsigned 1 byte integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -315,21 +385,27 @@
 ///   le_u8(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"\x03abcefg"[..], 0x00)));
-/// assert_eq!(parser(b""), Err(Err::Error((&[][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Error((&[][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn le_u8<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u8, E> {
-  if i.len() < 1 {
-    Err(Err::Error(make_error(i, ErrorKind::Eof)))
+pub fn le_u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 1;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
   } else {
-    Ok((&i[1..], i[0]))
+    let res = input.iter_elements().next().unwrap();
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a little endian unsigned 2 bytes integer
+/// Recognizes a little endian unsigned 2 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -339,22 +415,30 @@
 ///   le_u16(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"abcefg"[..], 0x0300)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn le_u16<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u16, E> {
-  if i.len() < 2 {
-    Err(Err::Error(make_error(i, ErrorKind::Eof)))
+pub fn le_u16<I, E: ParseError<I>>(input: I) -> IResult<I, u16, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 2;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
   } else {
-    let res = ((i[1] as u16) << 8) + i[0] as u16;
-    Ok((&i[2..], res))
+    let mut res = 0u16;
+    for (index, byte) in input.iter_indices().take(bound) {
+      res += (byte as u16) << (8 * index);
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a little endian unsigned 3 byte integer
+/// Recognizes a little endian unsigned 3 byte integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -364,22 +448,30 @@
 ///   le_u24(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03\x05abcefg"), Ok((&b"abcefg"[..], 0x050300)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn le_u24<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u32, E> {
-  if i.len() < 3 {
-    Err(Err::Error(make_error(i, ErrorKind::Eof)))
+pub fn le_u24<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 3;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
   } else {
-    let res = (i[0] as u32) + ((i[1] as u32) << 8) + ((i[2] as u32) << 16);
-    Ok((&i[3..], res))
+    let mut res = 0u32;
+    for (index, byte) in input.iter_indices().take(bound) {
+      res += (byte as u32) << (8 * index);
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a little endian unsigned 4 bytes integer
+/// Recognizes a little endian unsigned 4 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -389,22 +481,30 @@
 ///   le_u32(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03\x05\x07abcefg"), Ok((&b"abcefg"[..], 0x07050300)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn le_u32<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u32, E> {
-  if i.len() < 4 {
-    Err(Err::Error(make_error(i, ErrorKind::Eof)))
+pub fn le_u32<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 4;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
   } else {
-    let res = ((i[3] as u32) << 24) + ((i[2] as u32) << 16) + ((i[1] as u32) << 8) + i[0] as u32;
-    Ok((&i[4..], res))
+    let mut res = 0u32;
+    for (index, byte) in input.iter_indices().take(bound) {
+      res += (byte as u32) << (8 * index);
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a little endian unsigned 8 bytes integer
+/// Recognizes a little endian unsigned 8 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -414,23 +514,30 @@
 ///   le_u64(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"), Ok((&b"abcefg"[..], 0x0706050403020100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn le_u64<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u64, E> {
-  if i.len() < 8 {
-    Err(Err::Error(make_error(i, ErrorKind::Eof)))
+pub fn le_u64<I, E: ParseError<I>>(input: I) -> IResult<I, u64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 8;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
   } else {
-    let res = ((i[7] as u64) << 56) + ((i[6] as u64) << 48) + ((i[5] as u64) << 40) + ((i[4] as u64) << 32) + ((i[3] as u64) << 24)
-      + ((i[2] as u64) << 16) + ((i[1] as u64) << 8) + i[0] as u64;
-    Ok((&i[8..], res))
+    let mut res = 0u64;
+    for (index, byte) in input.iter_indices().take(bound) {
+      res += (byte as u64) << (8 * index);
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a little endian unsigned 16 bytes integer
+/// Recognizes a little endian unsigned 16 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -440,38 +547,31 @@
 ///   le_u128(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
 #[cfg(stable_i128)]
-pub fn le_u128<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u128, E> {
-  if i.len() < 16 {
-    Err(Err::Error(make_error(i, ErrorKind::Eof)))
+pub fn le_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 16;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
   } else {
-    let res = ((i[15] as u128) << 120)
-      + ((i[14] as u128) << 112)
-      + ((i[13] as u128) << 104)
-      + ((i[12] as u128) << 96)
-      + ((i[11] as u128) << 88)
-      + ((i[10] as u128) << 80)
-      + ((i[9] as u128) << 72)
-      + ((i[8] as u128) << 64)
-      + ((i[7] as u128) << 56)
-      + ((i[6] as u128) << 48)
-      + ((i[5] as u128) << 40)
-      + ((i[4] as u128) << 32)
-      + ((i[3] as u128) << 24)
-      + ((i[2] as u128) << 16)
-      + ((i[1] as u128) << 8)
-      + i[0] as u128;
-    Ok((&i[16..], res))
+    let mut res = 0u128;
+    for (index, byte) in input.iter_indices().take(bound) {
+      res += (byte as u128) << (8 * index);
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a signed 1 byte integer
+/// Recognizes a signed 1 byte integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -481,17 +581,20 @@
 ///   le_i8(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"\x03abcefg"[..], 0x00)));
-/// assert_eq!(parser(b""), Err(Err::Error((&[][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Error((&[][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn le_i8<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i8, E> {
-  map!(i, le_u8, |x| x as i8)
+pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, be_u8, |x| x as i8)
 }
 
-/// Recognizes a little endian signed 2 bytes integer
+/// Recognizes a little endian signed 2 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -501,17 +604,20 @@
 ///   le_i16(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03abcefg"), Ok((&b"abcefg"[..], 0x0300)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn le_i16<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i16, E> {
-  map!(i, le_u16, |x| x as i16)
+pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, le_u16, |x| x as i16)
 }
 
-/// Recognizes a little endian signed 3 bytes integer
+/// Recognizes a little endian signed 3 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -521,22 +627,25 @@
 ///   le_i24(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03\x05abcefg"), Ok((&b"abcefg"[..], 0x050300)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn le_i24<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i32, E> {
+pub fn le_i24<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
   // Same as the unsigned version but we need to sign-extend manually here
-  map!(i, le_u24, |x| if x & 0x80_00_00 != 0 {
+  map!(input, le_u24, |x| if x & 0x80_00_00 != 0 {
     (x | 0xff_00_00_00) as i32
   } else {
     x as i32
   })
 }
 
-/// Recognizes a little endian signed 4 bytes integer
+/// Recognizes a little endian signed 4 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -546,17 +655,20 @@
 ///   le_i32(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x03\x05\x07abcefg"), Ok((&b"abcefg"[..], 0x07050300)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn le_i32<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i32, E> {
-  map!(i, le_u32, |x| x as i32)
+pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, le_u32, |x| x as i32)
 }
 
-/// Recognizes a little endian signed 8 bytes integer
+/// Recognizes a little endian signed 8 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -566,17 +678,20 @@
 ///   le_i64(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"), Ok((&b"abcefg"[..], 0x0706050403020100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn le_i64<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i64, E> {
-  map!(i, le_u64, |x| x as i64)
+pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, le_u64, |x| x as i64)
 }
 
-/// Recognizes a little endian signed 16 bytes integer
+/// Recognizes a little endian signed 16 bytes integer.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -586,21 +701,472 @@
 ///   le_i128(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
 /// ```
 #[inline]
 #[cfg(stable_i128)]
-pub fn le_i128<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i128, E> {
-  map!(i, le_u128, |x| x as i128)
+pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, le_u128, |x| x as i128)
 }
 
-/// Recognizes a big endian 4 bytes floating point number
+/// Recognizes an unsigned 1 byte integer
 ///
+/// Note that endianness does not apply to 1 byte numbers.
 /// *complete version*: returns an error if there is not enough input data
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
+/// use nom::number::complete::u8;
+///
+/// let parser = |s| {
+///   u8(s)
+/// };
+///
+/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Error((&[][..], ErrorKind::Eof))));
+/// ```
+#[inline]
+pub fn u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 1;
+  if input.input_len() < bound {
+    Err(Err::Error(make_error(input, ErrorKind::Eof)))
+  } else {
+    let res = input.iter_elements().next().unwrap();
+
+    Ok((input.slice(bound..), res))
+  }
+}
+
+/// Recognizes an unsigned 2 bytes integer
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian u16 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian u16 integer.
+/// *complete version*: returns an error if there is not enough input data
+///
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::u16;
+///
+/// let be_u16 = |s| {
+///   u16(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_u16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003)));
+/// assert_eq!(be_u16(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+///
+/// let le_u16 = |s| {
+///   u16(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_u16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300)));
+/// assert_eq!(le_u16(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// ```
+#[inline]
+pub fn u16<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u16, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_u16,
+    crate::number::Endianness::Little => le_u16,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_u16,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_u16,
+  }
+}
+
+/// Recognizes an unsigned 3 byte integer
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian u24 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian u24 integer.
+/// *complete version*: returns an error if there is not enough input data
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::u24;
+///
+/// let be_u24 = |s| {
+///   u24(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_u24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305)));
+/// assert_eq!(be_u24(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+///
+/// let le_u24 = |s| {
+///   u24(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_u24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300)));
+/// assert_eq!(le_u24(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// ```
+#[inline]
+pub fn u24<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_u24,
+    crate::number::Endianness::Little => le_u24,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_u24,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_u24,
+  }
+}
+
+/// Recognizes an unsigned 4 byte integer
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian u32 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian u32 integer.
+/// *complete version*: returns an error if there is not enough input data
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::u32;
+///
+/// let be_u32 = |s| {
+///   u32(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_u32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507)));
+/// assert_eq!(be_u32(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+///
+/// let le_u32 = |s| {
+///   u32(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_u32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300)));
+/// assert_eq!(le_u32(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// ```
+#[inline]
+pub fn u32<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_u32,
+    crate::number::Endianness::Little => le_u32,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_u32,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_u32,
+  }
+}
+
+/// Recognizes an unsigned 8 byte integer
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian u64 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian u64 integer.
+/// *complete version*: returns an error if there is not enough input data
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::u64;
+///
+/// let be_u64 = |s| {
+///   u64(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_u64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607)));
+/// assert_eq!(be_u64(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+///
+/// let le_u64 = |s| {
+///   u64(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_u64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100)));
+/// assert_eq!(le_u64(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// ```
+#[inline]
+pub fn u64<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_u64,
+    crate::number::Endianness::Little => le_u64,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_u64,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_u64,
+  }
+}
+
+/// Recognizes an unsigned 16 byte integer
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian u128 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian u128 integer.
+/// *complete version*: returns an error if there is not enough input data
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::u128;
+///
+/// let be_u128 = |s| {
+///   u128(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_u128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607)));
+/// assert_eq!(be_u128(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+///
+/// let le_u128 = |s| {
+///   u128(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_u128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100)));
+/// assert_eq!(le_u128(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// ```
+#[inline]
+#[cfg(stable_i128)]
+pub fn u128<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u128, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_u128,
+    crate::number::Endianness::Little => le_u128,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_u128,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_u128,
+  }
+}
+
+/// Recognizes a signed 1 byte integer
+///
+/// Note that endianness does not apply to 1 byte numbers.
+/// *complete version*: returns an error if there is not enough input data
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::i8;
+///
+/// let parser = |s| {
+///   i8(s)
+/// };
+///
+/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Error((&[][..], ErrorKind::Eof))));
+/// ```
+#[inline]
+pub fn i8<I, E: ParseError<I>>(i: I) -> IResult<I, i8, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(i, u8, |x| x as i8)
+}
+
+/// Recognizes a signed 2 byte integer
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian i16 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian i16 integer.
+/// *complete version*: returns an error if there is not enough input data
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::i16;
+///
+/// let be_i16 = |s| {
+///   i16(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_i16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003)));
+/// assert_eq!(be_i16(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+///
+/// let le_i16 = |s| {
+///   i16(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_i16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300)));
+/// assert_eq!(le_i16(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// ```
+#[inline]
+pub fn i16<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i16, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_i16,
+    crate::number::Endianness::Little => le_i16,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_i16,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_i16,
+  }
+}
+
+/// Recognizes a signed 3 byte integer
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian i24 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian i24 integer.
+/// *complete version*: returns an error if there is not enough input data
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::i24;
+///
+/// let be_i24 = |s| {
+///   i24(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_i24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305)));
+/// assert_eq!(be_i24(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+///
+/// let le_i24 = |s| {
+///   i24(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_i24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300)));
+/// assert_eq!(le_i24(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// ```
+#[inline]
+pub fn i24<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_i24,
+    crate::number::Endianness::Little => le_i24,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_i24,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_i24,
+  }
+}
+
+/// Recognizes a signed 4 byte integer
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian i32 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian i32 integer.
+/// *complete version*: returns an error if there is not enough input data
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::i32;
+///
+/// let be_i32 = |s| {
+///   i32(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_i32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507)));
+/// assert_eq!(be_i32(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+///
+/// let le_i32 = |s| {
+///   i32(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_i32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300)));
+/// assert_eq!(le_i32(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// ```
+#[inline]
+pub fn i32<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_i32,
+    crate::number::Endianness::Little => le_i32,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_i32,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_i32,
+  }
+}
+
+/// Recognizes a signed 8 byte integer
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian i64 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian i64 integer.
+/// *complete version*: returns an error if there is not enough input data
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::i64;
+///
+/// let be_i64 = |s| {
+///   i64(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_i64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607)));
+/// assert_eq!(be_i64(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+///
+/// let le_i64 = |s| {
+///   i64(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_i64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100)));
+/// assert_eq!(le_i64(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// ```
+#[inline]
+pub fn i64<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_i64,
+    crate::number::Endianness::Little => le_i64,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_i64,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_i64,
+  }
+}
+
+/// Recognizes a signed 16 byte integer
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian i128 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian i128 integer.
+/// *complete version*: returns an error if there is not enough input data
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::i128;
+///
+/// let be_i128 = |s| {
+///   i128(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_i128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607)));
+/// assert_eq!(be_i128(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+///
+/// let le_i128 = |s| {
+///   i128(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_i128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100)));
+/// assert_eq!(le_i128(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof))));
+/// ```
+#[inline]
+#[cfg(stable_i128)]
+pub fn i128<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i128, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_i128,
+    crate::number::Endianness::Little => le_i128,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_i128,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_i128,
+  }
+}
+
+/// Recognizes a big endian 4 bytes floating point number.
+///
+/// *Complete version*: Returns an error if there is not enough input data.
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
 /// use nom::number::complete::be_f32;
 ///
 /// let parser = |s| {
@@ -608,19 +1174,22 @@
 /// };
 ///
 /// assert_eq!(parser(&[0x41, 0x48, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(parser(b"abc"), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn be_f32<'a, E: ParseError<&'a [u8]>>(input: &'a[u8]) -> IResult<&'a[u8], f32, E> {
+pub fn be_f32<I, E: ParseError<I>>(input: I) -> IResult<I, f32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
   match be_u32(input) {
     Err(e) => Err(e),
     Ok((i, o)) => Ok((i, f32::from_bits(o))),
   }
 }
 
-/// Recognizes a big endian 8 bytes floating point number
+/// Recognizes a big endian 8 bytes floating point number.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -631,19 +1200,22 @@
 /// };
 ///
 /// assert_eq!(parser(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(parser(b"abc"), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn be_f64<'a, E: ParseError<&'a [u8]>>(input: &'a[u8]) -> IResult<&'a[u8], f64, E> {
+pub fn be_f64<I, E: ParseError<I>>(input: I) -> IResult<I, f64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
   match be_u64(input) {
     Err(e) => Err(e),
     Ok((i, o)) => Ok((i, f64::from_bits(o))),
   }
 }
 
-/// Recognizes a little endian 4 bytes floating point number
+/// Recognizes a little endian 4 bytes floating point number.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -654,19 +1226,22 @@
 /// };
 ///
 /// assert_eq!(parser(&[0x00, 0x00, 0x48, 0x41][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(parser(b"abc"), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn le_f32<'a, E: ParseError<&'a [u8]>>(input: &'a[u8]) -> IResult<&'a[u8], f32, E> {
+pub fn le_f32<I, E: ParseError<I>>(input: I) -> IResult<I, f32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
   match le_u32(input) {
     Err(e) => Err(e),
     Ok((i, o)) => Ok((i, f32::from_bits(o))),
   }
 }
 
-/// Recognizes a little endian 8 bytes floating point number
+/// Recognizes a little endian 8 bytes floating point number.
 ///
-/// *complete version*: returns an error if there is not enough input data
+/// *Complete version*: Returns an error if there is not enough input data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -677,19 +1252,100 @@
 /// };
 ///
 /// assert_eq!(parser(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(parser(b"abc"), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
+/// assert_eq!(parser(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
 /// ```
 #[inline]
-pub fn le_f64<'a, E: ParseError<&'a [u8]>>(input: &'a[u8]) -> IResult<&'a[u8], f64, E> {
+pub fn le_f64<I, E: ParseError<I>>(input: I) -> IResult<I, f64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
   match le_u64(input) {
     Err(e) => Err(e),
     Ok((i, o)) => Ok((i, f64::from_bits(o))),
   }
 }
 
-/// Recognizes a hex-encoded integer
+/// Recognizes a 4 byte floating point number
 ///
-/// *complete version*: will parse until the end of input if it has less than 8 bytes
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian f32 float,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian f32 float.
+/// *complete version*: returns an error if there is not enough input data
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::f32;
+///
+/// let be_f32 = |s| {
+///   f32(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_f32(&[0x41, 0x48, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
+/// assert_eq!(be_f32(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
+///
+/// let le_f32 = |s| {
+///   f32(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_f32(&[0x00, 0x00, 0x48, 0x41][..]), Ok((&b""[..], 12.5)));
+/// assert_eq!(le_f32(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
+/// ```
+#[inline]
+pub fn f32<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, f32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_f32,
+    crate::number::Endianness::Little => le_f32,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_f32,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_f32,
+  }
+}
+
+/// Recognizes an 8 byte floating point number
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian f64 float,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian f64 float.
+/// *complete version*: returns an error if there is not enough input data
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::complete::f64;
+///
+/// let be_f64 = |s| {
+///   f64(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_f64(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
+/// assert_eq!(be_f64(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
+///
+/// let le_f64 = |s| {
+///   f64(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40][..]), Ok((&b""[..], 12.5)));
+/// assert_eq!(le_f64(&b"abc"[..]), Err(Err::Error((&b"abc"[..], ErrorKind::Eof))));
+/// ```
+#[inline]
+pub fn f64<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, f64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_f64,
+    crate::number::Endianness::Little => le_f64,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_f64,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_f64,
+  }
+}
+
+/// Recognizes a hex-encoded integer.
+///
+/// *Complete version*: Will parse until the end of input if it has less than 8 bytes.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -699,12 +1355,12 @@
 ///   hex_u32(s)
 /// };
 ///
-/// assert_eq!(parser(b"01AE"), Ok((&b""[..], 0x01AE)));
-/// assert_eq!(parser(b"abc"), Ok((&b""[..], 0x0ABC)));
-/// assert_eq!(parser(b"ggg"), Err(Err::Error((&b"ggg"[..], ErrorKind::IsA))));
+/// assert_eq!(parser(&b"01AE"[..]), Ok((&b""[..], 0x01AE)));
+/// assert_eq!(parser(&b"abc"[..]), Ok((&b""[..], 0x0ABC)));
+/// assert_eq!(parser(&b"ggg"[..]), Err(Err::Error((&b"ggg"[..], ErrorKind::IsA))));
 /// ```
 #[inline]
-pub fn hex_u32<'a, E: ParseError<&'a [u8]>>(input: &'a[u8]) -> IResult<&'a[u8], u32, E> {
+pub fn hex_u32<'a, E: ParseError<&'a [u8]>>(input: &'a [u8]) -> IResult<&'a [u8], u32, E> {
   let (i, o) = crate::bytes::complete::is_a(&b"0123456789abcdefABCDEF"[..])(input)?;
   // Do not parse more than 8 characters for a u32
   let (parsed, remaining) = if o.len() <= 8 {
@@ -726,9 +1382,9 @@
   Ok((remaining, res))
 }
 
-/// Recognizes floating point number in a byte string and returns the corresponding slice
+/// Recognizes floating point number in a byte string and returns the corresponding slice.
 ///
-/// *complete version*: can parse until the end of input
+/// *Complete version*: Can parse until the end of input.
 ///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
@@ -744,8 +1400,7 @@
 /// assert_eq!(parser("123K-01"), Ok(("K-01", "123")));
 /// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Char))));
 /// ```
-#[allow(unused_imports)]
-#[cfg_attr(rustfmt, rustfmt_skip)]
+#[rustfmt::skip]
 pub fn recognize_float<T, E:ParseError<T>>(input: T) -> IResult<T, T, E>
 where
   T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
@@ -771,9 +1426,136 @@
   )(input)
 }
 
-/// Recognizes floating point number in a byte string and returns a f32
+// workaround until issues with minimal-lexical are fixed
+#[doc(hidden)]
+pub fn recognize_float_or_exceptions<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
+where
+  T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
+  T: Clone + Offset,
+  T: InputIter + InputTake + Compare<&'static str>,
+  <T as InputIter>::Item: AsChar,
+  T: InputTakeAtPosition,
+  <T as InputTakeAtPosition>::Item: AsChar,
+{
+  alt((
+    |i: T| {
+      recognize_float::<_, E>(i.clone()).map_err(|e| match e {
+        crate::Err::Error(_) => crate::Err::Error(E::from_error_kind(i, ErrorKind::Float)),
+        crate::Err::Failure(_) => crate::Err::Failure(E::from_error_kind(i, ErrorKind::Float)),
+        crate::Err::Incomplete(needed) => crate::Err::Incomplete(needed),
+      })
+    },
+    |i: T| {
+      crate::bytes::complete::tag_no_case::<_, _, E>("nan")(i.clone())
+        .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float)))
+    },
+    |i: T| {
+      crate::bytes::complete::tag_no_case::<_, _, E>("inf")(i.clone())
+        .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float)))
+    },
+    |i: T| {
+      crate::bytes::complete::tag_no_case::<_, _, E>("infinity")(i.clone())
+        .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float)))
+    },
+  ))(input)
+}
+
+/// Recognizes a floating point number in text format and returns the integer, fraction and exponent parts of the input data
 ///
-/// *complete version*: can parse until the end of input
+/// *Complete version*: Can parse until the end of input.
+///
+pub fn recognize_float_parts<T, E: ParseError<T>>(input: T) -> IResult<T, (bool, T, T, i32), E>
+where
+  T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + Slice<Range<usize>>,
+  T: Clone + Offset,
+  T: InputIter + InputTake,
+  <T as InputIter>::Item: AsChar + Copy,
+  T: InputTakeAtPosition + InputLength,
+  <T as InputTakeAtPosition>::Item: AsChar,
+  T: for<'a> Compare<&'a [u8]>,
+  T: AsBytes,
+{
+  let (i, sign) = sign(input.clone())?;
+
+  //let (i, zeroes) = take_while(|c: <T as InputTakeAtPosition>::Item| c.as_char() == '0')(i)?;
+  let (i, zeroes) = match i.as_bytes().iter().position(|c| *c != b'0') {
+    Some(index) => i.take_split(index),
+    None => i.take_split(i.input_len()),
+  };
+  //let (i, mut integer) = digit0(i)?;
+  let (i, mut integer) = match i
+    .as_bytes()
+    .iter()
+    .position(|c| !(*c >= b'0' && *c <= b'9'))
+  {
+    Some(index) => i.take_split(index),
+    None => i.take_split(i.input_len()),
+  };
+
+  if integer.input_len() == 0 && zeroes.input_len() > 0 {
+    // keep the last zero if integer is empty
+    integer = zeroes.slice(zeroes.input_len() - 1..);
+  }
+
+  let (i, opt_dot) = opt(tag(&b"."[..]))(i)?;
+  let (i, fraction) = if opt_dot.is_none() {
+    let i2 = i.clone();
+    (i2, i.slice(..0))
+  } else {
+    // match number, trim right zeroes
+    let mut zero_count = 0usize;
+    let mut position = None;
+    for (pos, c) in i.as_bytes().iter().enumerate() {
+      if *c >= b'0' && *c <= b'9' {
+        if *c == b'0' {
+          zero_count += 1;
+        } else {
+          zero_count = 0;
+        }
+      } else {
+        position = Some(pos);
+        break;
+      }
+    }
+
+    let position = position.unwrap_or(i.input_len());
+
+    let index = if zero_count == 0 {
+      position
+    } else if zero_count == position {
+      position - zero_count + 1
+    } else {
+      position - zero_count
+    };
+
+    (i.slice(position..), i.slice(..index))
+  };
+
+  if integer.input_len() == 0 && fraction.input_len() == 0 {
+    return Err(Err::Error(E::from_error_kind(input, ErrorKind::Float)));
+  }
+
+  let i2 = i.clone();
+  let (i, e) = match i.as_bytes().iter().next() {
+    Some(b'e') => (i.slice(1..), true),
+    Some(b'E') => (i.slice(1..), true),
+    _ => (i, false),
+  };
+
+  let (i, exp) = if e {
+    cut(crate::character::complete::i32)(i)?
+  } else {
+    (i2, 0)
+  };
+
+  Ok((i, (sign, integer, fraction, exp)))
+}
+
+use crate::traits::ParseTo;
+
+/// Recognizes floating point number in text format and returns a f32.
+///
+/// *Complete version*: Can parse until the end of input.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -786,61 +1568,47 @@
 /// assert_eq!(parser("11e-1"), Ok(("", 1.1)));
 /// assert_eq!(parser("123E-02"), Ok(("", 1.23)));
 /// assert_eq!(parser("123K-01"), Ok(("K-01", 123.0)));
-/// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Char))));
-/// ```
-#[cfg(not(feature = "lexical"))]
-pub fn float<T, E:ParseError<T>>(input: T) -> IResult<T, f32, E>
-where
-  T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
-  T: Clone + Offset,
-  T: InputIter + InputLength + crate::traits::ParseTo<f32>,
-  <T as InputIter>::Item: AsChar,
-  T: InputTakeAtPosition,
-  <T as InputTakeAtPosition>::Item: AsChar
-{
-  match recognize_float(input) {
-    Err(e) => Err(e),
-    Ok((i, s)) => match s.parse_to() {
-      Some(n) => Ok((i, n)),
-      None =>  Err(Err::Error(E::from_error_kind(i, ErrorKind::Float)))
-    }
-  }
-}
-
-/// Recognizes floating point number in a byte string and returns a f32
-///
-/// *complete version*: can parse until the end of input
-///
-/// this function uses the lexical-core crate for float parsing by default, you
-/// can deactivate it by removing the "lexical" feature
-/// ```rust
-/// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
-/// use nom::number::complete::float;
-///
-/// let parser = |s| {
-///   float(s)
-/// };
-///
-/// assert_eq!(parser("1.1"), Ok(("", 1.1)));
-/// assert_eq!(parser("123E-02"), Ok(("", 1.23)));
-/// assert_eq!(parser("123K-01"), Ok(("K-01", 123.0)));
 /// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Float))));
 /// ```
-#[cfg(feature = "lexical")]
-pub fn float<T, E:ParseError<T>>(input: T) -> IResult<T, f32, E>
+pub fn float<T, E: ParseError<T>>(input: T) -> IResult<T, f32, E>
 where
-  T: crate::traits::AsBytes + InputLength + Slice<RangeFrom<usize>>,
+  T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + Slice<Range<usize>>,
+  T: Clone + Offset + ParseTo<f32> + Compare<&'static str>,
+  T: InputIter + InputLength + InputTake,
+  <T as InputIter>::Item: AsChar + Copy,
+  <T as InputIter>::IterElem: Clone,
+  T: InputTakeAtPosition,
+  <T as InputTakeAtPosition>::Item: AsChar,
+  T: AsBytes,
+  T: for<'a> Compare<&'a [u8]>,
 {
-  match ::lexical_core::parse_partial(input.as_bytes()) {
-    Ok((value, processed)) => Ok((input.slice(processed..), value)),
-    Err(_) => Err(Err::Error(E::from_error_kind(input, ErrorKind::Float)))
+  /*
+  let (i, (sign, integer, fraction, exponent)) = recognize_float_parts(input)?;
+
+  let mut float: f32 = minimal_lexical::parse_float(
+    integer.as_bytes().iter(),
+    fraction.as_bytes().iter(),
+    exponent,
+  );
+  if !sign {
+    float = -float;
+  }
+
+  Ok((i, float))
+      */
+  let (i, s) = recognize_float_or_exceptions(input)?;
+  match s.parse_to() {
+    Some(f) => (Ok((i, f))),
+    None => Err(crate::Err::Error(E::from_error_kind(
+      i,
+      crate::error::ErrorKind::Float,
+    ))),
   }
 }
 
-/// Recognizes floating point number in a byte string and returns a f64
+/// Recognizes floating point number in text format and returns a f64.
 ///
-/// *complete version*: can parse until the end of input
+/// *Complete version*: Can parse until the end of input.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
@@ -853,63 +1621,50 @@
 /// assert_eq!(parser("11e-1"), Ok(("", 1.1)));
 /// assert_eq!(parser("123E-02"), Ok(("", 1.23)));
 /// assert_eq!(parser("123K-01"), Ok(("K-01", 123.0)));
-/// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Char))));
-/// ```
-#[cfg(not(feature = "lexical"))]
-pub fn double<T, E:ParseError<T>>(input: T) -> IResult<T, f64, E>
-where
-  T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
-  T: Clone + Offset,
-  T: InputIter + InputLength + crate::traits::ParseTo<f64>,
-  <T as InputIter>::Item: AsChar,
-  T: InputTakeAtPosition,
-  <T as InputTakeAtPosition>::Item: AsChar
-{
-  match recognize_float(input) {
-    Err(e) => Err(e),
-    Ok((i, s)) => match s.parse_to() {
-      Some(n) => Ok((i, n)),
-      None =>  Err(Err::Error(E::from_error_kind(i, ErrorKind::Float)))
-    }
-  }
-}
-
-/// Recognizes floating point number in a byte string and returns a f64
-///
-/// *complete version*: can parse until the end of input
-///
-/// this function uses the lexical-core crate for float parsing by default, you
-/// can deactivate it by removing the "lexical" feature
-/// ```rust
-/// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
-/// use nom::number::complete::double;
-///
-/// let parser = |s| {
-///   double(s)
-/// };
-///
-/// assert_eq!(parser("1.1"), Ok(("", 1.1)));
-/// assert_eq!(parser("123E-02"), Ok(("", 1.23)));
-/// assert_eq!(parser("123K-01"), Ok(("K-01", 123.0)));
 /// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Float))));
 /// ```
-#[cfg(feature = "lexical")]
-pub fn double<T, E:ParseError<T>>(input: T) -> IResult<T, f64, E>
+pub fn double<T, E: ParseError<T>>(input: T) -> IResult<T, f64, E>
 where
-  T: crate::traits::AsBytes + InputLength + Slice<RangeFrom<usize>>,
+  T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>> + Slice<Range<usize>>,
+  T: Clone + Offset + ParseTo<f64> + Compare<&'static str>,
+  T: InputIter + InputLength + InputTake,
+  <T as InputIter>::Item: AsChar + Copy,
+  <T as InputIter>::IterElem: Clone,
+  T: InputTakeAtPosition,
+  <T as InputTakeAtPosition>::Item: AsChar,
+  T: AsBytes,
+  T: for<'a> Compare<&'a [u8]>,
 {
-  match ::lexical_core::parse_partial(input.as_bytes()) {
-    Ok((value, processed)) => Ok((input.slice(processed..), value)),
-    Err(_) => Err(Err::Error(E::from_error_kind(input, ErrorKind::Float)))
+  /*
+  let (i, (sign, integer, fraction, exponent)) = recognize_float_parts(input)?;
+
+  let mut float: f64 = minimal_lexical::parse_float(
+    integer.as_bytes().iter(),
+    fraction.as_bytes().iter(),
+    exponent,
+  );
+  if !sign {
+    float = -float;
+  }
+
+  Ok((i, float))
+      */
+  let (i, s) = recognize_float_or_exceptions(input)?;
+  match s.parse_to() {
+    Some(f) => (Ok((i, f))),
+    None => Err(crate::Err::Error(E::from_error_kind(
+      i,
+      crate::error::ErrorKind::Float,
+    ))),
   }
 }
 
 #[cfg(test)]
 mod tests {
   use super::*;
-  use crate::internal::Err;
   use crate::error::ErrorKind;
+  use crate::internal::Err;
+  use proptest::prelude::*;
 
   macro_rules! assert_parse(
     ($left: expr, $right: expr) => {
@@ -920,129 +1675,175 @@
 
   #[test]
   fn i8_tests() {
-    assert_parse!(be_i8(&[0x00]), Ok((&b""[..], 0)));
-    assert_parse!(be_i8(&[0x7f]), Ok((&b""[..], 127)));
-    assert_parse!(be_i8(&[0xff]), Ok((&b""[..], -1)));
-    assert_parse!(be_i8(&[0x80]), Ok((&b""[..], -128)));
+    assert_parse!(i8(&[0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(i8(&[0x7f][..]), Ok((&b""[..], 127)));
+    assert_parse!(i8(&[0xff][..]), Ok((&b""[..], -1)));
+    assert_parse!(i8(&[0x80][..]), Ok((&b""[..], -128)));
   }
 
   #[test]
-  fn i16_tests() {
-    assert_parse!(be_i16(&[0x00, 0x00]), Ok((&b""[..], 0)));
-    assert_parse!(be_i16(&[0x7f, 0xff]), Ok((&b""[..], 32_767_i16)));
-    assert_parse!(be_i16(&[0xff, 0xff]), Ok((&b""[..], -1)));
-    assert_parse!(be_i16(&[0x80, 0x00]), Ok((&b""[..], -32_768_i16)));
+  fn be_i8_tests() {
+    assert_parse!(be_i8(&[0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(be_i8(&[0x7f][..]), Ok((&b""[..], 127)));
+    assert_parse!(be_i8(&[0xff][..]), Ok((&b""[..], -1)));
+    assert_parse!(be_i8(&[0x80][..]), Ok((&b""[..], -128)));
   }
 
   #[test]
-  fn u24_tests() {
-    assert_parse!(be_u24(&[0x00, 0x00, 0x00]), Ok((&b""[..], 0)));
-    assert_parse!(be_u24(&[0x00, 0xFF, 0xFF]), Ok((&b""[..], 65_535_u32)));
-    assert_parse!(be_u24(&[0x12, 0x34, 0x56]), Ok((&b""[..], 1_193_046_u32)));
+  fn be_i16_tests() {
+    assert_parse!(be_i16(&[0x00, 0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(be_i16(&[0x7f, 0xff][..]), Ok((&b""[..], 32_767_i16)));
+    assert_parse!(be_i16(&[0xff, 0xff][..]), Ok((&b""[..], -1)));
+    assert_parse!(be_i16(&[0x80, 0x00][..]), Ok((&b""[..], -32_768_i16)));
   }
 
   #[test]
-  fn i24_tests() {
-    assert_parse!(be_i24(&[0xFF, 0xFF, 0xFF]), Ok((&b""[..], -1_i32)));
-    assert_parse!(be_i24(&[0xFF, 0x00, 0x00]), Ok((&b""[..], -65_536_i32)));
-    assert_parse!(be_i24(&[0xED, 0xCB, 0xAA]), Ok((&b""[..], -1_193_046_i32)));
-  }
-
-  #[test]
-  fn i32_tests() {
-    assert_parse!(be_i32(&[0x00, 0x00, 0x00, 0x00]), Ok((&b""[..], 0)));
+  fn be_u24_tests() {
+    assert_parse!(be_u24(&[0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(be_u24(&[0x00, 0xFF, 0xFF][..]), Ok((&b""[..], 65_535_u32)));
     assert_parse!(
-      be_i32(&[0x7f, 0xff, 0xff, 0xff]),
+      be_u24(&[0x12, 0x34, 0x56][..]),
+      Ok((&b""[..], 1_193_046_u32))
+    );
+  }
+
+  #[test]
+  fn be_i24_tests() {
+    assert_parse!(be_i24(&[0xFF, 0xFF, 0xFF][..]), Ok((&b""[..], -1_i32)));
+    assert_parse!(be_i24(&[0xFF, 0x00, 0x00][..]), Ok((&b""[..], -65_536_i32)));
+    assert_parse!(
+      be_i24(&[0xED, 0xCB, 0xAA][..]),
+      Ok((&b""[..], -1_193_046_i32))
+    );
+  }
+
+  #[test]
+  fn be_i32_tests() {
+    assert_parse!(be_i32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(
+      be_i32(&[0x7f, 0xff, 0xff, 0xff][..]),
       Ok((&b""[..], 2_147_483_647_i32))
     );
-    assert_parse!(be_i32(&[0xff, 0xff, 0xff, 0xff]), Ok((&b""[..], -1)));
+    assert_parse!(be_i32(&[0xff, 0xff, 0xff, 0xff][..]), Ok((&b""[..], -1)));
     assert_parse!(
-      be_i32(&[0x80, 0x00, 0x00, 0x00]),
+      be_i32(&[0x80, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], -2_147_483_648_i32))
     );
   }
 
   #[test]
-  fn i64_tests() {
+  fn be_i64_tests() {
     assert_parse!(
-      be_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      be_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], 0))
     );
     assert_parse!(
-      be_i64(&[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
+      be_i64(&[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]),
       Ok((&b""[..], 9_223_372_036_854_775_807_i64))
     );
     assert_parse!(
-      be_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
+      be_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]),
       Ok((&b""[..], -1))
     );
     assert_parse!(
-      be_i64(&[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      be_i64(&[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], -9_223_372_036_854_775_808_i64))
     );
   }
 
   #[test]
   #[cfg(stable_i128)]
-  fn i128_tests() {
+  fn be_i128_tests() {
     assert_parse!(
-      be_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      be_i128(
+        &[
+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+          0x00
+        ][..]
+      ),
       Ok((&b""[..], 0))
     );
     assert_parse!(
-      be_i128(&[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
-      Ok((&b""[..], 170_141_183_460_469_231_731_687_303_715_884_105_727_i128))
+      be_i128(
+        &[
+          0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+          0xff
+        ][..]
+      ),
+      Ok((
+        &b""[..],
+        170_141_183_460_469_231_731_687_303_715_884_105_727_i128
+      ))
     );
     assert_parse!(
-      be_i128(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
+      be_i128(
+        &[
+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+          0xff
+        ][..]
+      ),
       Ok((&b""[..], -1))
     );
     assert_parse!(
-      be_i128(&[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
-      Ok((&b""[..], -170_141_183_460_469_231_731_687_303_715_884_105_728_i128))
+      be_i128(
+        &[
+          0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+          0x00
+        ][..]
+      ),
+      Ok((
+        &b""[..],
+        -170_141_183_460_469_231_731_687_303_715_884_105_728_i128
+      ))
     );
   }
 
   #[test]
   fn le_i8_tests() {
-    assert_parse!(le_i8(&[0x00]), Ok((&b""[..], 0)));
-    assert_parse!(le_i8(&[0x7f]), Ok((&b""[..], 127)));
-    assert_parse!(le_i8(&[0xff]), Ok((&b""[..], -1)));
-    assert_parse!(le_i8(&[0x80]), Ok((&b""[..], -128)));
+    assert_parse!(le_i8(&[0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(le_i8(&[0x7f][..]), Ok((&b""[..], 127)));
+    assert_parse!(le_i8(&[0xff][..]), Ok((&b""[..], -1)));
+    assert_parse!(le_i8(&[0x80][..]), Ok((&b""[..], -128)));
   }
 
   #[test]
   fn le_i16_tests() {
-    assert_parse!(le_i16(&[0x00, 0x00]), Ok((&b""[..], 0)));
-    assert_parse!(le_i16(&[0xff, 0x7f]), Ok((&b""[..], 32_767_i16)));
-    assert_parse!(le_i16(&[0xff, 0xff]), Ok((&b""[..], -1)));
-    assert_parse!(le_i16(&[0x00, 0x80]), Ok((&b""[..], -32_768_i16)));
+    assert_parse!(le_i16(&[0x00, 0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(le_i16(&[0xff, 0x7f][..]), Ok((&b""[..], 32_767_i16)));
+    assert_parse!(le_i16(&[0xff, 0xff][..]), Ok((&b""[..], -1)));
+    assert_parse!(le_i16(&[0x00, 0x80][..]), Ok((&b""[..], -32_768_i16)));
   }
 
   #[test]
   fn le_u24_tests() {
-    assert_parse!(le_u24(&[0x00, 0x00, 0x00]), Ok((&b""[..], 0)));
-    assert_parse!(le_u24(&[0xFF, 0xFF, 0x00]), Ok((&b""[..], 65_535_u32)));
-    assert_parse!(le_u24(&[0x56, 0x34, 0x12]), Ok((&b""[..], 1_193_046_u32)));
+    assert_parse!(le_u24(&[0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(le_u24(&[0xFF, 0xFF, 0x00][..]), Ok((&b""[..], 65_535_u32)));
+    assert_parse!(
+      le_u24(&[0x56, 0x34, 0x12][..]),
+      Ok((&b""[..], 1_193_046_u32))
+    );
   }
 
   #[test]
   fn le_i24_tests() {
-    assert_parse!(le_i24(&[0xFF, 0xFF, 0xFF]), Ok((&b""[..], -1_i32)));
-    assert_parse!(le_i24(&[0x00, 0x00, 0xFF]), Ok((&b""[..], -65_536_i32)));
-    assert_parse!(le_i24(&[0xAA, 0xCB, 0xED]), Ok((&b""[..], -1_193_046_i32)));
+    assert_parse!(le_i24(&[0xFF, 0xFF, 0xFF][..]), Ok((&b""[..], -1_i32)));
+    assert_parse!(le_i24(&[0x00, 0x00, 0xFF][..]), Ok((&b""[..], -65_536_i32)));
+    assert_parse!(
+      le_i24(&[0xAA, 0xCB, 0xED][..]),
+      Ok((&b""[..], -1_193_046_i32))
+    );
   }
 
   #[test]
   fn le_i32_tests() {
-    assert_parse!(le_i32(&[0x00, 0x00, 0x00, 0x00]), Ok((&b""[..], 0)));
+    assert_parse!(le_i32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)));
     assert_parse!(
-      le_i32(&[0xff, 0xff, 0xff, 0x7f]),
+      le_i32(&[0xff, 0xff, 0xff, 0x7f][..]),
       Ok((&b""[..], 2_147_483_647_i32))
     );
-    assert_parse!(le_i32(&[0xff, 0xff, 0xff, 0xff]), Ok((&b""[..], -1)));
+    assert_parse!(le_i32(&[0xff, 0xff, 0xff, 0xff][..]), Ok((&b""[..], -1)));
     assert_parse!(
-      le_i32(&[0x00, 0x00, 0x00, 0x80]),
+      le_i32(&[0x00, 0x00, 0x00, 0x80][..]),
       Ok((&b""[..], -2_147_483_648_i32))
     );
   }
@@ -1050,19 +1851,19 @@
   #[test]
   fn le_i64_tests() {
     assert_parse!(
-      le_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      le_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], 0))
     );
     assert_parse!(
-      le_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f]),
+      le_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f][..]),
       Ok((&b""[..], 9_223_372_036_854_775_807_i64))
     );
     assert_parse!(
-      le_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
+      le_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]),
       Ok((&b""[..], -1))
     );
     assert_parse!(
-      le_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]),
+      le_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80][..]),
       Ok((&b""[..], -9_223_372_036_854_775_808_i64))
     );
   }
@@ -1071,28 +1872,54 @@
   #[cfg(stable_i128)]
   fn le_i128_tests() {
     assert_parse!(
-      le_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      le_i128(
+        &[
+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+          0x00
+        ][..]
+      ),
       Ok((&b""[..], 0))
     );
     assert_parse!(
-      le_i128(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f]),
-      Ok((&b""[..], 170_141_183_460_469_231_731_687_303_715_884_105_727_i128))
+      le_i128(
+        &[
+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+          0x7f
+        ][..]
+      ),
+      Ok((
+        &b""[..],
+        170_141_183_460_469_231_731_687_303_715_884_105_727_i128
+      ))
     );
     assert_parse!(
-      le_i128(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
+      le_i128(
+        &[
+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+          0xff
+        ][..]
+      ),
       Ok((&b""[..], -1))
     );
     assert_parse!(
-      le_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]),
-      Ok((&b""[..], -170_141_183_460_469_231_731_687_303_715_884_105_728_i128))
+      le_i128(
+        &[
+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+          0x80
+        ][..]
+      ),
+      Ok((
+        &b""[..],
+        -170_141_183_460_469_231_731_687_303_715_884_105_728_i128
+      ))
     );
   }
 
   #[test]
   fn be_f32_tests() {
-    assert_parse!(be_f32(&[0x00, 0x00, 0x00, 0x00]), Ok((&b""[..], 0_f32)));
+    assert_parse!(be_f32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0_f32)));
     assert_parse!(
-      be_f32(&[0x4d, 0x31, 0x1f, 0xd8]),
+      be_f32(&[0x4d, 0x31, 0x1f, 0xd8][..]),
       Ok((&b""[..], 185_728_392_f32))
     );
   }
@@ -1100,20 +1927,20 @@
   #[test]
   fn be_f64_tests() {
     assert_parse!(
-      be_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      be_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], 0_f64))
     );
     assert_parse!(
-      be_f64(&[0x41, 0xa6, 0x23, 0xfb, 0x10, 0x00, 0x00, 0x00]),
+      be_f64(&[0x41, 0xa6, 0x23, 0xfb, 0x10, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], 185_728_392_f64))
     );
   }
 
   #[test]
   fn le_f32_tests() {
-    assert_parse!(le_f32(&[0x00, 0x00, 0x00, 0x00]), Ok((&b""[..], 0_f32)));
+    assert_parse!(le_f32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0_f32)));
     assert_parse!(
-      le_f32(&[0xd8, 0x1f, 0x31, 0x4d]),
+      le_f32(&[0xd8, 0x1f, 0x31, 0x4d][..]),
       Ok((&b""[..], 185_728_392_f32))
     );
   }
@@ -1121,11 +1948,11 @@
   #[test]
   fn le_f64_tests() {
     assert_parse!(
-      le_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      le_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], 0_f64))
     );
     assert_parse!(
-      le_f64(&[0x00, 0x00, 0x00, 0x10, 0xfb, 0x23, 0xa6, 0x41]),
+      le_f64(&[0x00, 0x00, 0x00, 0x10, 0xfb, 0x23, 0xa6, 0x41][..]),
       Ok((&b""[..], 185_728_392_f64))
     );
   }
@@ -1170,6 +1997,7 @@
       "12.34",
       "-1.234E-12",
       "-1.234e-12",
+      "0.00000000000000000087",
     ];
 
     for test in test_cases.drain(..) {
@@ -1193,6 +2021,123 @@
       recognize_float(remaining_exponent),
       Err(Err::Failure(("", ErrorKind::Digit)))
     );
+
+    let (_i, nan) = float::<_, ()>("NaN").unwrap();
+    assert!(nan.is_nan());
+
+    let (_i, inf) = float::<_, ()>("inf").unwrap();
+    assert!(inf.is_infinite());
+    let (_i, inf) = float::<_, ()>("infinite").unwrap();
+    assert!(inf.is_infinite());
   }
 
+  #[test]
+  fn configurable_endianness() {
+    use crate::number::Endianness;
+
+    fn be_tst16(i: &[u8]) -> IResult<&[u8], u16> {
+      u16(Endianness::Big)(i)
+    }
+    fn le_tst16(i: &[u8]) -> IResult<&[u8], u16> {
+      u16(Endianness::Little)(i)
+    }
+    assert_eq!(be_tst16(&[0x80, 0x00]), Ok((&b""[..], 32_768_u16)));
+    assert_eq!(le_tst16(&[0x80, 0x00]), Ok((&b""[..], 128_u16)));
+
+    fn be_tst32(i: &[u8]) -> IResult<&[u8], u32> {
+      u32(Endianness::Big)(i)
+    }
+    fn le_tst32(i: &[u8]) -> IResult<&[u8], u32> {
+      u32(Endianness::Little)(i)
+    }
+    assert_eq!(
+      be_tst32(&[0x12, 0x00, 0x60, 0x00]),
+      Ok((&b""[..], 302_014_464_u32))
+    );
+    assert_eq!(
+      le_tst32(&[0x12, 0x00, 0x60, 0x00]),
+      Ok((&b""[..], 6_291_474_u32))
+    );
+
+    fn be_tst64(i: &[u8]) -> IResult<&[u8], u64> {
+      u64(Endianness::Big)(i)
+    }
+    fn le_tst64(i: &[u8]) -> IResult<&[u8], u64> {
+      u64(Endianness::Little)(i)
+    }
+    assert_eq!(
+      be_tst64(&[0x12, 0x00, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
+      Ok((&b""[..], 1_297_142_246_100_992_000_u64))
+    );
+    assert_eq!(
+      le_tst64(&[0x12, 0x00, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
+      Ok((&b""[..], 36_028_874_334_666_770_u64))
+    );
+
+    fn be_tsti16(i: &[u8]) -> IResult<&[u8], i16> {
+      i16(Endianness::Big)(i)
+    }
+    fn le_tsti16(i: &[u8]) -> IResult<&[u8], i16> {
+      i16(Endianness::Little)(i)
+    }
+    assert_eq!(be_tsti16(&[0x00, 0x80]), Ok((&b""[..], 128_i16)));
+    assert_eq!(le_tsti16(&[0x00, 0x80]), Ok((&b""[..], -32_768_i16)));
+
+    fn be_tsti32(i: &[u8]) -> IResult<&[u8], i32> {
+      i32(Endianness::Big)(i)
+    }
+    fn le_tsti32(i: &[u8]) -> IResult<&[u8], i32> {
+      i32(Endianness::Little)(i)
+    }
+    assert_eq!(
+      be_tsti32(&[0x00, 0x12, 0x60, 0x00]),
+      Ok((&b""[..], 1_204_224_i32))
+    );
+    assert_eq!(
+      le_tsti32(&[0x00, 0x12, 0x60, 0x00]),
+      Ok((&b""[..], 6_296_064_i32))
+    );
+
+    fn be_tsti64(i: &[u8]) -> IResult<&[u8], i64> {
+      i64(Endianness::Big)(i)
+    }
+    fn le_tsti64(i: &[u8]) -> IResult<&[u8], i64> {
+      i64(Endianness::Little)(i)
+    }
+    assert_eq!(
+      be_tsti64(&[0x00, 0xFF, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
+      Ok((&b""[..], 71_881_672_479_506_432_i64))
+    );
+    assert_eq!(
+      le_tsti64(&[0x00, 0xFF, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
+      Ok((&b""[..], 36_028_874_334_732_032_i64))
+    );
+  }
+
+  #[cfg(feature = "std")]
+  fn parse_f64(i: &str) -> IResult<&str, f64, ()> {
+    match recognize_float(i) {
+      Err(e) => Err(e),
+      Ok((i, s)) => {
+        if s.is_empty() {
+          return Err(Err::Error(()));
+        }
+        match s.parse_to() {
+          Some(n) => Ok((i, n)),
+          None => Err(Err::Error(())),
+        }
+      }
+    }
+  }
+
+  proptest! {
+    #[test]
+    #[cfg(feature = "std")]
+    fn floats(s in "\\PC*") {
+        println!("testing {}", s);
+        let res1 = parse_f64(&s);
+        let res2 = double::<_, ()>(s.as_str());
+        assert_eq!(res1, res2);
+    }
+  }
 }
diff --git a/src/number/macros.rs b/src/number/macros.rs
deleted file mode 100644
index cb8c2a9..0000000
--- a/src/number/macros.rs
+++ /dev/null
@@ -1,265 +0,0 @@
-//! parsers recognizing numbers
-
-/// if the parameter is nom::Endianness::Big, parse a big endian u16 integer,
-/// otherwise a little endian u16 integer
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, Needed};
-/// use nom::number::Endianness;
-///
-/// # fn main() {
-/// named!(be<u16>, u16!(Endianness::Big));
-///
-/// assert_eq!(be(b"\x00\x01abcd"), Ok((&b"abcd"[..], 0x0001)));
-/// assert_eq!(be(b"\x01"), Err(Err::Incomplete(Needed::Size(2))));
-///
-/// named!(le<u16>, u16!(Endianness::Little));
-///
-/// assert_eq!(le(b"\x00\x01abcd"), Ok((&b"abcd"[..], 0x0100)));
-/// assert_eq!(le(b"\x01"), Err(Err::Incomplete(Needed::Size(2))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! u16 ( ($i:expr, $e:expr) => ( {if $crate::number::Endianness::Big == $e { $crate::number::streaming::be_u16($i) } else { $crate::number::streaming::le_u16($i) } } ););
-
-/// if the parameter is nom::Endianness::Big, parse a big endian u32 integer,
-/// otherwise a little endian u32 integer
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, Needed};
-/// use nom::number::Endianness;
-///
-/// # fn main() {
-/// named!(be<u32>, u32!(Endianness::Big));
-///
-/// assert_eq!(be(b"\x00\x01\x02\x03abcd"), Ok((&b"abcd"[..], 0x00010203)));
-/// assert_eq!(be(b"\x01"), Err(Err::Incomplete(Needed::Size(4))));
-///
-/// named!(le<u32>, u32!(Endianness::Little));
-///
-/// assert_eq!(le(b"\x00\x01\x02\x03abcd"), Ok((&b"abcd"[..], 0x03020100)));
-/// assert_eq!(le(b"\x01"), Err(Err::Incomplete(Needed::Size(4))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! u32 ( ($i:expr, $e:expr) => ( {if $crate::number::Endianness::Big == $e { $crate::number::streaming::be_u32($i) } else { $crate::number::streaming::le_u32($i) } } ););
-
-/// if the parameter is nom::Endianness::Big, parse a big endian u64 integer,
-/// otherwise a little endian u64 integer
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, Needed};
-/// use nom::number::Endianness;
-///
-/// # fn main() {
-/// named!(be<u64>, u64!(Endianness::Big));
-///
-/// assert_eq!(be(b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"), Ok((&b"abcd"[..], 0x0001020304050607)));
-/// assert_eq!(be(b"\x01"), Err(Err::Incomplete(Needed::Size(8))));
-///
-/// named!(le<u64>, u64!(Endianness::Little));
-///
-/// assert_eq!(le(b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"), Ok((&b"abcd"[..], 0x0706050403020100)));
-/// assert_eq!(le(b"\x01"), Err(Err::Incomplete(Needed::Size(8))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! u64 ( ($i:expr, $e:expr) => ( {if $crate::number::Endianness::Big == $e { $crate::number::streaming::be_u64($i) } else { $crate::number::streaming::le_u64($i) } } ););
-
-/// if the parameter is nom::Endianness::Big, parse a big endian u128 integer,
-/// otherwise a little endian u128 integer
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, Needed};
-/// use nom::number::Endianness;
-///
-/// # fn main() {
-/// named!(be<u128>, u128!(Endianness::Big));
-///
-/// assert_eq!(be(b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"), Ok((&b"abcd"[..], 0x00010203040506070809101112131415)));
-/// assert_eq!(be(b"\x01"), Err(Err::Incomplete(Needed::Size(16))));
-///
-/// named!(le<u128>, u128!(Endianness::Little));
-///
-/// assert_eq!(le(b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"), Ok((&b"abcd"[..], 0x15141312111009080706050403020100)));
-/// assert_eq!(le(b"\x01"), Err(Err::Incomplete(Needed::Size(16))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-#[cfg(stable_i128)]
-macro_rules! u128 ( ($i:expr, $e:expr) => ( {if $crate::number::Endianness::Big == $e { $crate::number::streaming::be_u128($i) } else { $crate::number::streaming::le_u128($i) } } ););
-
-/// if the parameter is nom::Endianness::Big, parse a big endian i16 integer,
-/// otherwise a little endian i16 integer
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, Needed};
-/// use nom::number::Endianness;
-///
-/// # fn main() {
-/// named!(be<i16>, i16!(Endianness::Big));
-///
-/// assert_eq!(be(b"\x00\x01abcd"), Ok((&b"abcd"[..], 0x0001)));
-/// assert_eq!(be(b"\x01"), Err(Err::Incomplete(Needed::Size(2))));
-///
-/// named!(le<i16>, i16!(Endianness::Little));
-///
-/// assert_eq!(le(b"\x00\x01abcd"), Ok((&b"abcd"[..], 0x0100)));
-/// assert_eq!(le(b"\x01"), Err(Err::Incomplete(Needed::Size(2))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! i16 ( ($i:expr, $e:expr) => ( {if $crate::number::Endianness::Big == $e { $crate::number::streaming::be_i16($i) } else { $crate::number::streaming::le_i16($i) } } ););
-
-/// if the parameter is nom::Endianness::Big, parse a big endian i32 integer,
-/// otherwise a little endian i32 integer
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, Needed};
-/// use nom::number::Endianness;
-///
-/// # fn main() {
-/// named!(be<i32>, i32!(Endianness::Big));
-///
-/// assert_eq!(be(b"\x00\x01\x02\x03abcd"), Ok((&b"abcd"[..], 0x00010203)));
-/// assert_eq!(be(b"\x01"), Err(Err::Incomplete(Needed::Size(4))));
-///
-/// named!(le<i32>, i32!(Endianness::Little));
-///
-/// assert_eq!(le(b"\x00\x01\x02\x03abcd"), Ok((&b"abcd"[..], 0x03020100)));
-/// assert_eq!(le(b"\x01"), Err(Err::Incomplete(Needed::Size(4))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! i32 ( ($i:expr, $e:expr) => ( {if $crate::number::Endianness::Big == $e { $crate::number::streaming::be_i32($i) } else { $crate::number::streaming::le_i32($i) } } ););
-
-/// if the parameter is nom::Endianness::Big, parse a big endian i64 integer,
-/// otherwise a little endian i64 integer
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, Needed};
-/// use nom::number::Endianness;
-///
-/// # fn main() {
-/// named!(be<i64>, i64!(Endianness::Big));
-///
-/// assert_eq!(be(b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"), Ok((&b"abcd"[..], 0x0001020304050607)));
-/// assert_eq!(be(b"\x01"), Err(Err::Incomplete(Needed::Size(8))));
-///
-/// named!(le<i64>, i64!(Endianness::Little));
-///
-/// assert_eq!(le(b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"), Ok((&b"abcd"[..], 0x0706050403020100)));
-/// assert_eq!(le(b"\x01"), Err(Err::Incomplete(Needed::Size(8))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! i64 ( ($i:expr, $e:expr) => ( {if $crate::number::Endianness::Big == $e { $crate::number::streaming::be_i64($i) } else { $crate::number::streaming::le_i64($i) } } ););
-
-/// if the parameter is nom::Endianness::Big, parse a big endian i64 integer,
-/// otherwise a little endian i64 integer
-///
-/// ```rust
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err, Needed};
-/// use nom::number::Endianness;
-///
-/// # fn main() {
-/// named!(be<i128>, i128!(Endianness::Big));
-///
-/// assert_eq!(be(b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"), Ok((&b"abcd"[..], 0x00010203040506070809101112131415)));
-/// assert_eq!(be(b"\x01"), Err(Err::Incomplete(Needed::Size(16))));
-///
-/// named!(le<i128>, i128!(Endianness::Little));
-///
-/// assert_eq!(le(b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"), Ok((&b"abcd"[..], 0x15141312111009080706050403020100)));
-/// assert_eq!(le(b"\x01"), Err(Err::Incomplete(Needed::Size(16))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-#[cfg(stable_i128)]
-macro_rules! i128 ( ($i:expr, $e:expr) => ( {if $crate::number::Endianness::Big == $e { $crate::number::streaming::be_i128($i) } else { $crate::number::streaming::le_i128($i) } } ););
-
-#[cfg(test)]
-mod tests {
-  use crate::number::Endianness;
-
-  #[test]
-  fn configurable_endianness() {
-    named!(be_tst16<u16>, u16!(Endianness::Big));
-    named!(le_tst16<u16>, u16!(Endianness::Little));
-    assert_eq!(be_tst16(&[0x80, 0x00]), Ok((&b""[..], 32_768_u16)));
-    assert_eq!(le_tst16(&[0x80, 0x00]), Ok((&b""[..], 128_u16)));
-
-    named!(be_tst32<u32>, u32!(Endianness::Big));
-    named!(le_tst32<u32>, u32!(Endianness::Little));
-    assert_eq!(
-      be_tst32(&[0x12, 0x00, 0x60, 0x00]),
-      Ok((&b""[..], 302_014_464_u32))
-    );
-    assert_eq!(
-      le_tst32(&[0x12, 0x00, 0x60, 0x00]),
-      Ok((&b""[..], 6_291_474_u32))
-    );
-
-    named!(be_tst64<u64>, u64!(Endianness::Big));
-    named!(le_tst64<u64>, u64!(Endianness::Little));
-    assert_eq!(
-      be_tst64(&[0x12, 0x00, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
-      Ok((&b""[..], 1_297_142_246_100_992_000_u64))
-    );
-    assert_eq!(
-      le_tst64(&[0x12, 0x00, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
-      Ok((&b""[..], 36_028_874_334_666_770_u64))
-    );
-
-    named!(be_tsti16<i16>, i16!(Endianness::Big));
-    named!(le_tsti16<i16>, i16!(Endianness::Little));
-    assert_eq!(be_tsti16(&[0x00, 0x80]), Ok((&b""[..], 128_i16)));
-    assert_eq!(le_tsti16(&[0x00, 0x80]), Ok((&b""[..], -32_768_i16)));
-
-    named!(be_tsti32<i32>, i32!(Endianness::Big));
-    named!(le_tsti32<i32>, i32!(Endianness::Little));
-    assert_eq!(
-      be_tsti32(&[0x00, 0x12, 0x60, 0x00]),
-      Ok((&b""[..], 1_204_224_i32))
-    );
-    assert_eq!(
-      le_tsti32(&[0x00, 0x12, 0x60, 0x00]),
-      Ok((&b""[..], 6_296_064_i32))
-    );
-
-    named!(be_tsti64<i64>, i64!(Endianness::Big));
-    named!(le_tsti64<i64>, i64!(Endianness::Little));
-    assert_eq!(
-      be_tsti64(&[0x00, 0xFF, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
-      Ok((&b""[..], 71_881_672_479_506_432_i64))
-    );
-    assert_eq!(
-      le_tsti64(&[0x00, 0xFF, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
-      Ok((&b""[..], 36_028_874_334_732_032_i64))
-    );
-  }
-
-  //FIXME
-  /*
-  #[test]
-  #[cfg(feature = "std")]
-  fn manual_configurable_endianness_test() {
-    let x = 1;
-    let int_parse: Box<Fn(&[u8]) -> IResult<&[u8], u16, (&[u8], ErrorKind)>> = if x == 2 {
-      Box::new(be_u16)
-    } else {
-      Box::new(le_u16)
-    };
-    println!("{:?}", int_parse(&b"3"[..]));
-    assert_eq!(int_parse(&[0x80, 0x00]), Ok((&b""[..], 128_u16)));
-  }
-  */
-}
diff --git a/src/number/mod.rs b/src/number/mod.rs
index 9be4c38..58c3d51 100644
--- a/src/number/mod.rs
+++ b/src/number/mod.rs
@@ -1,17 +1,15 @@
-//! parsers recognizing numbers
+//! Parsers recognizing numbers
 
-#[macro_use]
-mod macros;
-
-pub mod streaming;
 pub mod complete;
+pub mod streaming;
 
 /// Configurable endianness
 #[derive(Debug, PartialEq, Eq, Clone, Copy)]
 pub enum Endianness {
-  /// big endian
+  /// Big endian
   Big,
-  /// little endian
+  /// Little endian
   Little,
+  /// Will match the host's endianness
+  Native,
 }
-
diff --git a/src/number/streaming.rs b/src/number/streaming.rs
index 15a89a4..7c53ccc 100644
--- a/src/number/streaming.rs
+++ b/src/number/streaming.rs
@@ -1,694 +1,1323 @@
-//! parsers recognizing numbers, streaming version
+//! Parsers recognizing numbers, streaming version
 
-use crate::internal::*;
-use crate::error::{ErrorKind, ParseError};
-use crate::traits::{AsChar, InputIter, InputLength, InputTakeAtPosition};
-use crate::lib::std::ops::{RangeFrom, RangeTo};
-use crate::traits::{Offset, Slice};
-use crate::character::streaming::{char, digit1};
-use crate::sequence::{pair, tuple};
-use crate::combinator::{cut, map, opt, recognize};
 use crate::branch::alt;
+use crate::bytes::streaming::tag;
+use crate::character::streaming::{char, digit1, sign};
+use crate::combinator::{cut, map, opt, recognize};
+use crate::error::{ErrorKind, ParseError};
+use crate::internal::*;
+use crate::lib::std::ops::{RangeFrom, RangeTo};
+use crate::sequence::{pair, tuple};
+use crate::traits::{
+  AsBytes, AsChar, Compare, InputIter, InputLength, InputTake, InputTakeAtPosition, Offset, Slice,
+};
 
-/// Recognizes an unsigned 1 byte integer
+#[doc(hidden)]
+macro_rules! map(
+  // Internal parser, do not use directly
+  (__impl $i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
+    $crate::combinator::map(move |i| {$submac!(i, $($args)*)}, $g).parse($i)
+  );
+  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
+    map!(__impl $i, $submac!($($args)*), $g)
+  );
+  ($i:expr, $f:expr, $g:expr) => (
+    map!(__impl $i, call!($f), $g)
+  );
+);
+
+#[doc(hidden)]
+macro_rules! call (
+  ($i:expr, $fun:expr) => ( $fun( $i ) );
+  ($i:expr, $fun:expr, $($args:expr),* ) => ( $fun( $i, $($args),* ) );
+);
+
+/// Recognizes an unsigned 1 byte integer.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_u8;
 ///
-/// let parser = be_u8::<(_, ErrorKind)>;
+/// let parser = |s| {
+///   be_u8::<_, (_, ErrorKind)>(s)
+/// };
 ///
-/// assert_eq!(parser(b"\x00\x01abcd"), Ok((&b"\x01abcd"[..], 0x00)));
-/// assert_eq!(parser(b""), Err(Err::Incomplete(Needed::Size(1))));
+/// assert_eq!(parser(&b"\x00\x01abcd"[..]), Ok((&b"\x01abcd"[..], 0x00)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 #[inline]
-pub fn be_u8<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u8, E> {
-  if i.len() < 1 {
-    Err(Err::Incomplete(Needed::Size(1)))
+pub fn be_u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 1;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(1)))
   } else {
-    Ok((&i[1..], i[0]))
+    let res = input.iter_elements().next().unwrap();
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a big endian unsigned 2 bytes integer
+/// Recognizes a big endian unsigned 2 bytes integer.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 ///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_u16;
 ///
 /// let parser = |s| {
-///   be_u16::<(_, ErrorKind)>(s)
+///   be_u16::<_, (_, ErrorKind)>(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01abcd"), Ok((&b"abcd"[..], 0x0001)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(2))));
+/// assert_eq!(parser(&b"\x00\x01abcd"[..]), Ok((&b"abcd"[..], 0x0001)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 #[inline]
-pub fn be_u16<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u16, E> {
-  if i.len() < 2 {
-    Err(Err::Incomplete(Needed::Size(2)))
+pub fn be_u16<I, E: ParseError<I>>(input: I) -> IResult<I, u16, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 2;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(bound - input.input_len())))
   } else {
-    let res = ((i[0] as u16) << 8) + i[1] as u16;
-    Ok((&i[2..], res))
+    let mut res = 0u16;
+    for byte in input.iter_elements().take(bound) {
+      res = (res << 8) + byte as u16;
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a big endian unsigned 3 byte integer
+/// Recognizes a big endian unsigned 3 byte integer.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 ///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_u24;
 ///
 /// let parser = |s| {
-///   be_u24::<(_, ErrorKind)>(s)
+///   be_u24::<_, (_, ErrorKind)>(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02abcd"), Ok((&b"abcd"[..], 0x000102)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(3))));
+/// assert_eq!(parser(&b"\x00\x01\x02abcd"[..]), Ok((&b"abcd"[..], 0x000102)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2))));
 /// ```
 #[inline]
-pub fn be_u24<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u32, E> {
-  if i.len() < 3 {
-    Err(Err::Incomplete(Needed::Size(3)))
+pub fn be_u24<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 3;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(bound - input.input_len())))
   } else {
-    let res = ((i[0] as u32) << 16) + ((i[1] as u32) << 8) + (i[2] as u32);
-    Ok((&i[3..], res))
+    let mut res = 0u32;
+    for byte in input.iter_elements().take(bound) {
+      res = (res << 8) + byte as u32;
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a big endian unsigned 4 bytes integer
+/// Recognizes a big endian unsigned 4 bytes integer.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 ///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_u32;
 ///
 /// let parser = |s| {
-///   be_u32::<(_, ErrorKind)>(s)
+///   be_u32::<_, (_, ErrorKind)>(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03abcd"), Ok((&b"abcd"[..], 0x00010203)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(4))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03abcd"[..]), Ok((&b"abcd"[..], 0x00010203)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3))));
 /// ```
 #[inline]
-pub fn be_u32<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u32, E> {
-  if i.len() < 4 {
-    Err(Err::Incomplete(Needed::Size(4)))
+pub fn be_u32<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 4;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(bound - input.input_len())))
   } else {
-    let res = ((i[0] as u32) << 24) + ((i[1] as u32) << 16) + ((i[2] as u32) << 8) + i[3] as u32;
-    Ok((&i[4..], res))
+    let mut res = 0u32;
+    for byte in input.iter_elements().take(bound) {
+      res = (res << 8) + byte as u32;
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a big endian unsigned 8 bytes integer
+/// Recognizes a big endian unsigned 8 bytes integer.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 ///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_u64;
 ///
 /// let parser = |s| {
-///   be_u64::<(_, ErrorKind)>(s)
+///   be_u64::<_, (_, ErrorKind)>(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"), Ok((&b"abcd"[..], 0x0001020304050607)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(8))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"[..]), Ok((&b"abcd"[..], 0x0001020304050607)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7))));
 /// ```
 #[inline]
-pub fn be_u64<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u64, E> {
-  if i.len() < 8 {
-    Err(Err::Incomplete(Needed::Size(8)))
+pub fn be_u64<I, E: ParseError<I>>(input: I) -> IResult<I, u64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 8;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(bound - input.input_len())))
   } else {
-    let res = ((i[0] as u64) << 56) + ((i[1] as u64) << 48) + ((i[2] as u64) << 40) + ((i[3] as u64) << 32) + ((i[4] as u64) << 24)
-      + ((i[5] as u64) << 16) + ((i[6] as u64) << 8) + i[7] as u64;
-    Ok((&i[8..], res))
+    let mut res = 0u64;
+    for byte in input.iter_elements().take(bound) {
+      res = (res << 8) + byte as u64;
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a big endian unsigned 16 bytes integer
+/// Recognizes a big endian unsigned 16 bytes integer.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_u128;
 ///
 /// let parser = |s| {
-///   be_u128::<(_, ErrorKind)>(s)
+///   be_u128::<_, (_, ErrorKind)>(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"), Ok((&b"abcd"[..], 0x00010203040506070809101112131415)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(16))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"[..]), Ok((&b"abcd"[..], 0x00010203040506070809101112131415)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15))));
 /// ```
 #[inline]
 #[cfg(stable_i128)]
-pub fn be_u128<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u128, E> {
-  if i.len() < 16 {
-    Err(Err::Incomplete(Needed::Size(16)))
+pub fn be_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 16;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(bound - input.input_len())))
   } else {
-    let res = ((i[0] as u128) << 120)
-      + ((i[1] as u128) << 112)
-      + ((i[2] as u128) << 104)
-      + ((i[3] as u128) << 96)
-      + ((i[4] as u128) << 88)
-      + ((i[5] as u128) << 80)
-      + ((i[6] as u128) << 72)
-      + ((i[7] as u128) << 64)
-      + ((i[8] as u128) << 56)
-      + ((i[9] as u128) << 48)
-      + ((i[10] as u128) << 40)
-      + ((i[11] as u128) << 32)
-      + ((i[12] as u128) << 24)
-      + ((i[13] as u128) << 16)
-      + ((i[14] as u128) << 8)
-      + i[15] as u128;
-    Ok((&i[16..], res))
+    let mut res = 0u128;
+    for byte in input.iter_elements().take(bound) {
+      res = (res << 8) + byte as u128;
+    }
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a signed 1 byte integer
+/// Recognizes a signed 1 byte integer.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_i8;
 ///
-/// let parser = be_i8::<(_, ErrorKind)>;
+/// let parser = be_i8::<_, (_, ErrorKind)>;
 ///
-/// assert_eq!(parser(b"\x00\x01abcd"), Ok((&b"\x01abcd"[..], 0x00)));
-/// assert_eq!(parser(b""), Err(Err::Incomplete(Needed::Size(1))));
+/// assert_eq!(parser(&b"\x00\x01abcd"[..]), Ok((&b"\x01abcd"[..], 0x00)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 #[inline]
-pub fn be_i8<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i8, E> {
-  map!(i, be_u8, |x| x as i8)
+pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, be_u8, |x| x as i8)
 }
 
-/// Recognizes a big endian signed 2 bytes integer
+/// Recognizes a big endian signed 2 bytes integer.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_i16;
 ///
-/// let parser = be_i16::<(_, ErrorKind)>;
+/// let parser = be_i16::<_, (_, ErrorKind)>;
 ///
-/// assert_eq!(parser(b"\x00\x01abcd"), Ok((&b"abcd"[..], 0x0001)));
-/// assert_eq!(parser(b""), Err(Err::Incomplete(Needed::Size(2))));
+/// assert_eq!(parser(&b"\x00\x01abcd"[..]), Ok((&b"abcd"[..], 0x0001)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(2))));
 /// ```
 #[inline]
-pub fn be_i16<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i16, E> {
-  map!(i, be_u16, |x| x as i16)
+pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, be_u16, |x| x as i16)
 }
 
-/// Recognizes a big endian signed 3 bytes integer
+/// Recognizes a big endian signed 3 bytes integer.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_i24;
 ///
-/// let parser = be_i24::<(_, ErrorKind)>;
+/// let parser = be_i24::<_, (_, ErrorKind)>;
 ///
-/// assert_eq!(parser(b"\x00\x01\x02abcd"), Ok((&b"abcd"[..], 0x000102)));
-/// assert_eq!(parser(b""), Err(Err::Incomplete(Needed::Size(3))));
+/// assert_eq!(parser(&b"\x00\x01\x02abcd"[..]), Ok((&b"abcd"[..], 0x000102)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(3))));
 /// ```
 #[inline]
-pub fn be_i24<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i32, E> {
+pub fn be_i24<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
   // Same as the unsigned version but we need to sign-extend manually here
-  map!(i, be_u24, |x| if x & 0x80_00_00 != 0 {
+  map!(input, be_u24, |x| if x & 0x80_00_00 != 0 {
     (x | 0xff_00_00_00) as i32
   } else {
     x as i32
   })
 }
 
-/// Recognizes a big endian signed 4 bytes integer
+/// Recognizes a big endian signed 4 bytes integer.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_i32;
 ///
-/// let parser = be_i32::<(_, ErrorKind)>;
+/// let parser = be_i32::<_, (_, ErrorKind)>;
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03abcd"), Ok((&b"abcd"[..], 0x00010203)));
-/// assert_eq!(parser(b""), Err(Err::Incomplete(Needed::Size(4))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03abcd"[..]), Ok((&b"abcd"[..], 0x00010203)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(4))));
 /// ```
 #[inline]
-pub fn be_i32<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i32, E> {
-  map!(i, be_u32, |x| x as i32)
+pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, be_u32, |x| x as i32)
 }
 
-/// Recognizes a big endian signed 8 bytes integer
+/// Recognizes a big endian signed 8 bytes integer.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 ///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_i64;
 ///
-/// let parser = be_i64::<(_, ErrorKind)>;
+/// let parser = be_i64::<_, (_, ErrorKind)>;
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"), Ok((&b"abcd"[..], 0x0001020304050607)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(8))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"[..]), Ok((&b"abcd"[..], 0x0001020304050607)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7))));
 /// ```
 #[inline]
-pub fn be_i64<'a, E: ParseError<&'a[u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i64, E> {
-  map!(i, be_u64, |x| x as i64)
+pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, be_u64, |x| x as i64)
 }
 
-/// Recognizes a big endian signed 16 bytes integer
+/// Recognizes a big endian signed 16 bytes integer.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_i128;
 ///
-/// let parser = be_i128::<(_, ErrorKind)>;
+/// let parser = be_i128::<_, (_, ErrorKind)>;
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"), Ok((&b"abcd"[..], 0x00010203040506070809101112131415)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(16))));
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"[..]), Ok((&b"abcd"[..], 0x00010203040506070809101112131415)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15))));
 /// ```
 #[inline]
 #[cfg(stable_i128)]
-pub fn be_i128<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i128, E> {
-  map!(i, be_u128, |x| x as i128)
+pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, be_u128, |x| x as i128)
+}
+
+/// Recognizes an unsigned 1 byte integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// use nom::number::streaming::le_u8;
+///
+/// let parser = le_u8::<_, (_, ErrorKind)>;
+///
+/// assert_eq!(parser(&b"\x00\x01abcd"[..]), Ok((&b"\x01abcd"[..], 0x00)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1))));
+/// ```
+#[inline]
+pub fn le_u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 1;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(1)))
+  } else {
+    let res = input.iter_elements().next().unwrap();
+
+    Ok((input.slice(bound..), res))
+  }
+}
+
+/// Recognizes a little endian unsigned 2 bytes integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// use nom::number::streaming::le_u16;
+///
+/// let parser = |s| {
+///   le_u16::<_, (_, ErrorKind)>(s)
+/// };
+///
+/// assert_eq!(parser(&b"\x00\x01abcd"[..]), Ok((&b"abcd"[..], 0x0100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1))));
+/// ```
+#[inline]
+pub fn le_u16<I, E: ParseError<I>>(input: I) -> IResult<I, u16, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 2;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(bound - input.input_len())))
+  } else {
+    let mut res = 0u16;
+    for (index, byte) in input.iter_indices().take(bound) {
+      res += (byte as u16) << (8 * index);
+    }
+
+    Ok((input.slice(bound..), res))
+  }
+}
+
+/// Recognizes a little endian unsigned 3 bytes integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// use nom::number::streaming::le_u24;
+///
+/// let parser = |s| {
+///   le_u24::<_, (_, ErrorKind)>(s)
+/// };
+///
+/// assert_eq!(parser(&b"\x00\x01\x02abcd"[..]), Ok((&b"abcd"[..], 0x020100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2))));
+/// ```
+#[inline]
+pub fn le_u24<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 3;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(bound - input.input_len())))
+  } else {
+    let mut res = 0u32;
+    for (index, byte) in input.iter_indices().take(bound) {
+      res += (byte as u32) << (8 * index);
+    }
+
+    Ok((input.slice(bound..), res))
+  }
+}
+
+/// Recognizes a little endian unsigned 4 bytes integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// use nom::number::streaming::le_u32;
+///
+/// let parser = |s| {
+///   le_u32::<_, (_, ErrorKind)>(s)
+/// };
+///
+/// assert_eq!(parser(&b"\x00\x01\x02\x03abcd"[..]), Ok((&b"abcd"[..], 0x03020100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3))));
+/// ```
+#[inline]
+pub fn le_u32<I, E: ParseError<I>>(input: I) -> IResult<I, u32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 4;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(bound - input.input_len())))
+  } else {
+    let mut res = 0u32;
+    for (index, byte) in input.iter_indices().take(bound) {
+      res += (byte as u32) << (8 * index);
+    }
+
+    Ok((input.slice(bound..), res))
+  }
+}
+
+/// Recognizes a little endian unsigned 8 bytes integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// use nom::number::streaming::le_u64;
+///
+/// let parser = |s| {
+///   le_u64::<_, (_, ErrorKind)>(s)
+/// };
+///
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"[..]), Ok((&b"abcd"[..], 0x0706050403020100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7))));
+/// ```
+#[inline]
+pub fn le_u64<I, E: ParseError<I>>(input: I) -> IResult<I, u64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 8;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(bound - input.input_len())))
+  } else {
+    let mut res = 0u64;
+    for (index, byte) in input.iter_indices().take(bound) {
+      res += (byte as u64) << (8 * index);
+    }
+
+    Ok((input.slice(bound..), res))
+  }
+}
+
+/// Recognizes a little endian unsigned 16 bytes integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// use nom::number::streaming::le_u128;
+///
+/// let parser = |s| {
+///   le_u128::<_, (_, ErrorKind)>(s)
+/// };
+///
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"[..]), Ok((&b"abcd"[..], 0x15141312111009080706050403020100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15))));
+/// ```
+#[inline]
+#[cfg(stable_i128)]
+pub fn le_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 16;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(bound - input.input_len())))
+  } else {
+    let mut res = 0u128;
+    for (index, byte) in input.iter_indices().take(bound) {
+      res += (byte as u128) << (8 * index);
+    }
+
+    Ok((input.slice(bound..), res))
+  }
+}
+
+/// Recognizes a signed 1 byte integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// use nom::number::streaming::le_i8;
+///
+/// let parser = le_i8::<_, (_, ErrorKind)>;
+///
+/// assert_eq!(parser(&b"\x00\x01abcd"[..]), Ok((&b"\x01abcd"[..], 0x00)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1))));
+/// ```
+#[inline]
+pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, le_u8, |x| x as i8)
+}
+
+/// Recognizes a little endian signed 2 bytes integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// use nom::number::streaming::le_i16;
+///
+/// let parser = |s| {
+///   le_i16::<_, (_, ErrorKind)>(s)
+/// };
+///
+/// assert_eq!(parser(&b"\x00\x01abcd"[..]), Ok((&b"abcd"[..], 0x0100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1))));
+/// ```
+#[inline]
+pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, le_u16, |x| x as i16)
+}
+
+/// Recognizes a little endian signed 3 bytes integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// use nom::number::streaming::le_i24;
+///
+/// let parser = |s| {
+///   le_i24::<_, (_, ErrorKind)>(s)
+/// };
+///
+/// assert_eq!(parser(&b"\x00\x01\x02abcd"[..]), Ok((&b"abcd"[..], 0x020100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2))));
+/// ```
+#[inline]
+pub fn le_i24<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  // Same as the unsigned version but we need to sign-extend manually here
+  map!(input, le_u24, |x| if x & 0x80_00_00 != 0 {
+    (x | 0xff_00_00_00) as i32
+  } else {
+    x as i32
+  })
+}
+
+/// Recognizes a little endian signed 4 bytes integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// use nom::number::streaming::le_i32;
+///
+/// let parser = |s| {
+///   le_i32::<_, (_, ErrorKind)>(s)
+/// };
+///
+/// assert_eq!(parser(&b"\x00\x01\x02\x03abcd"[..]), Ok((&b"abcd"[..], 0x03020100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3))));
+/// ```
+#[inline]
+pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, le_u32, |x| x as i32)
+}
+
+/// Recognizes a little endian signed 8 bytes integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// use nom::number::streaming::le_i64;
+///
+/// let parser = |s| {
+///   le_i64::<_, (_, ErrorKind)>(s)
+/// };
+///
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"[..]), Ok((&b"abcd"[..], 0x0706050403020100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7))));
+/// ```
+#[inline]
+pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, le_u64, |x| x as i64)
+}
+
+/// Recognizes a little endian signed 16 bytes integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// use nom::number::streaming::le_i128;
+///
+/// let parser = |s| {
+///   le_i128::<_, (_, ErrorKind)>(s)
+/// };
+///
+/// assert_eq!(parser(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"[..]), Ok((&b"abcd"[..], 0x15141312111009080706050403020100)));
+/// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15))));
+/// ```
+#[inline]
+#[cfg(stable_i128)]
+pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(input, le_u128, |x| x as i128)
 }
 
 /// Recognizes an unsigned 1 byte integer
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// Note that endianness does not apply to 1 byte numbers.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::le_u8;
+/// use nom::number::streaming::u8;
 ///
-/// let parser = le_u8::<(_, ErrorKind)>;
+/// let parser = |s| {
+///   u8::<_, (_, ErrorKind)>(s)
+/// };
 ///
-/// assert_eq!(parser(b"\x00\x01abcd"), Ok((&b"\x01abcd"[..], 0x00)));
-/// assert_eq!(parser(b""), Err(Err::Incomplete(Needed::Size(1))));
+/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 #[inline]
-pub fn le_u8<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u8, E> {
-  if i.len() < 1 {
-    Err(Err::Incomplete(Needed::Size(1)))
+pub fn u8<I, E: ParseError<I>>(input: I) -> IResult<I, u8, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  let bound: usize = 1;
+  if input.input_len() < bound {
+    Err(Err::Incomplete(Needed::new(1)))
   } else {
-    Ok((&i[1..], i[0]))
+    let res = input.iter_elements().next().unwrap();
+
+    Ok((input.slice(bound..), res))
   }
 }
 
-/// Recognizes a little endian unsigned 2 bytes integer
+/// Recognizes an unsigned 2 bytes integer
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian u16 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian u16 integer.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 ///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::le_u16;
+/// use nom::number::streaming::u16;
 ///
-/// let parser = |s| {
-///   le_u16::<(_, ErrorKind)>(s)
+/// let be_u16 = |s| {
+///   u16::<_, (_, ErrorKind)>(nom::number::Endianness::Big)(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01abcd"), Ok((&b"abcd"[..], 0x0100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(2))));
+/// assert_eq!(be_u16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003)));
+/// assert_eq!(be_u16(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1))));
+///
+/// let le_u16 = |s| {
+///   u16::<_, (_, ErrorKind)>(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_u16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300)));
+/// assert_eq!(le_u16(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 #[inline]
-pub fn le_u16<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u16, E> {
-  if i.len() < 2 {
-    Err(Err::Incomplete(Needed::Size(2)))
-  } else {
-    let res = ((i[1] as u16) << 8) + i[0] as u16;
-    Ok((&i[2..], res))
+pub fn u16<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u16, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_u16,
+    crate::number::Endianness::Little => le_u16,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_u16,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_u16,
   }
 }
 
-/// Recognizes a little endian unsigned 3 bytes integer
+/// Recognizes an unsigned 3 byte integer
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
-///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian u24 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian u24 integer.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::le_u24;
+/// use nom::number::streaming::u24;
 ///
-/// let parser = |s| {
-///   le_u24::<(_, ErrorKind)>(s)
+/// let be_u24 = |s| {
+///   u24::<_,(_, ErrorKind)>(nom::number::Endianness::Big)(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02abcd"), Ok((&b"abcd"[..], 0x020100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(3))));
+/// assert_eq!(be_u24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305)));
+/// assert_eq!(be_u24(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2))));
+///
+/// let le_u24 = |s| {
+///   u24::<_, (_, ErrorKind)>(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_u24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300)));
+/// assert_eq!(le_u24(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2))));
 /// ```
 #[inline]
-pub fn le_u24<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u32, E> {
-  if i.len() < 3 {
-    Err(Err::Incomplete(Needed::Size(3)))
-  } else {
-    let res = (i[0] as u32) + ((i[1] as u32) << 8) + ((i[2] as u32) << 16);
-    Ok((&i[3..], res))
+pub fn u24<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_u24,
+    crate::number::Endianness::Little => le_u24,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_u24,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_u24,
   }
 }
 
-/// Recognizes a little endian unsigned 4 bytes integer
+/// Recognizes an unsigned 4 byte integer
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
-///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian u32 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian u32 integer.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::le_u32;
+/// use nom::number::streaming::u32;
 ///
-/// let parser = |s| {
-///   le_u32::<(_, ErrorKind)>(s)
+/// let be_u32 = |s| {
+///   u32::<_, (_, ErrorKind)>(nom::number::Endianness::Big)(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03abcd"), Ok((&b"abcd"[..], 0x03020100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(4))));
+/// assert_eq!(be_u32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507)));
+/// assert_eq!(be_u32(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3))));
+///
+/// let le_u32 = |s| {
+///   u32::<_, (_, ErrorKind)>(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_u32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300)));
+/// assert_eq!(le_u32(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3))));
 /// ```
 #[inline]
-pub fn le_u32<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u32, E> {
-  if i.len() < 4 {
-    Err(Err::Incomplete(Needed::Size(4)))
-  } else {
-    let res = ((i[3] as u32) << 24) + ((i[2] as u32) << 16) + ((i[1] as u32) << 8) + i[0] as u32;
-    Ok((&i[4..], res))
+pub fn u32<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_u32,
+    crate::number::Endianness::Little => le_u32,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_u32,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_u32,
   }
 }
 
-/// Recognizes a little endian unsigned 8 bytes integer
+/// Recognizes an unsigned 8 byte integer
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
-///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian u64 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian u64 integer.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::le_u64;
+/// use nom::number::streaming::u64;
 ///
-/// let parser = |s| {
-///   le_u64::<(_, ErrorKind)>(s)
+/// let be_u64 = |s| {
+///   u64::<_, (_, ErrorKind)>(nom::number::Endianness::Big)(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"), Ok((&b"abcd"[..], 0x0706050403020100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(8))));
+/// assert_eq!(be_u64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607)));
+/// assert_eq!(be_u64(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7))));
+///
+/// let le_u64 = |s| {
+///   u64::<_, (_, ErrorKind)>(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_u64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100)));
+/// assert_eq!(le_u64(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7))));
 /// ```
 #[inline]
-pub fn le_u64<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u64, E> {
-  if i.len() < 8 {
-    Err(Err::Incomplete(Needed::Size(8)))
-  } else {
-    let res = ((i[7] as u64) << 56) + ((i[6] as u64) << 48) + ((i[5] as u64) << 40) + ((i[4] as u64) << 32) + ((i[3] as u64) << 24)
-      + ((i[2] as u64) << 16) + ((i[1] as u64) << 8) + i[0] as u64;
-    Ok((&i[8..], res))
+pub fn u64<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_u64,
+    crate::number::Endianness::Little => le_u64,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_u64,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_u64,
   }
 }
 
-/// Recognizes a little endian unsigned 16 bytes integer
+/// Recognizes an unsigned 16 byte integer
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
-///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian u128 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian u128 integer.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::le_u128;
+/// use nom::number::streaming::u128;
 ///
-/// let parser = |s| {
-///   le_u128::<(_, ErrorKind)>(s)
+/// let be_u128 = |s| {
+///   u128::<_, (_, ErrorKind)>(nom::number::Endianness::Big)(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"), Ok((&b"abcd"[..], 0x15141312111009080706050403020100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(16))));
+/// assert_eq!(be_u128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607)));
+/// assert_eq!(be_u128(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15))));
+///
+/// let le_u128 = |s| {
+///   u128::<_, (_, ErrorKind)>(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_u128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100)));
+/// assert_eq!(le_u128(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15))));
 /// ```
 #[inline]
 #[cfg(stable_i128)]
-pub fn le_u128<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], u128, E> {
-  if i.len() < 16 {
-    Err(Err::Incomplete(Needed::Size(16)))
-  } else {
-    let res = ((i[15] as u128) << 120)
-      + ((i[14] as u128) << 112)
-      + ((i[13] as u128) << 104)
-      + ((i[12] as u128) << 96)
-      + ((i[11] as u128) << 88)
-      + ((i[10] as u128) << 80)
-      + ((i[9] as u128) << 72)
-      + ((i[8] as u128) << 64)
-      + ((i[7] as u128) << 56)
-      + ((i[6] as u128) << 48)
-      + ((i[5] as u128) << 40)
-      + ((i[4] as u128) << 32)
-      + ((i[3] as u128) << 24)
-      + ((i[2] as u128) << 16)
-      + ((i[1] as u128) << 8)
-      + i[0] as u128;
-    Ok((&i[16..], res))
+pub fn u128<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u128, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_u128,
+    crate::number::Endianness::Little => le_u128,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_u128,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_u128,
   }
 }
 
 /// Recognizes a signed 1 byte integer
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// Note that endianness does not apply to 1 byte numbers.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::le_i8;
-///
-/// let parser = le_i8::<(_, ErrorKind)>;
-///
-/// assert_eq!(parser(b"\x00\x01abcd"), Ok((&b"\x01abcd"[..], 0x00)));
-/// assert_eq!(parser(b""), Err(Err::Incomplete(Needed::Size(1))));
-/// ```
-#[inline]
-pub fn le_i8<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i8, E> {
-  map!(i, le_u8, |x| x as i8)
-}
-
-/// Recognizes a little endian signed 2 bytes integer
-///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
-///
-/// ```rust
-/// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
-/// use nom::number::streaming::le_i16;
+/// use nom::number::streaming::i8;
 ///
 /// let parser = |s| {
-///   le_i16::<(_, ErrorKind)>(s)
+///   i8::<_, (_, ErrorKind)>(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01abcd"), Ok((&b"abcd"[..], 0x0100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(2))));
+/// assert_eq!(parser(&b"\x00\x03abcefg"[..]), Ok((&b"\x03abcefg"[..], 0x00)));
+/// assert_eq!(parser(&b""[..]), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 #[inline]
-pub fn le_i16<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i16, E> {
-  map!(i, le_u16, |x| x as i16)
+pub fn i8<I, E: ParseError<I>>(i: I) -> IResult<I, i8, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  map!(i, u8, |x| x as i8)
 }
 
-/// Recognizes a little endian signed 3 bytes integer
+/// Recognizes a signed 2 byte integer
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
-///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian i16 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian i16 integer.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::le_i24;
+/// use nom::number::streaming::i16;
 ///
-/// let parser = |s| {
-///   le_i24::<(_, ErrorKind)>(s)
+/// let be_i16 = |s| {
+///   i16::<_, (_, ErrorKind)>(nom::number::Endianness::Big)(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02abcd"), Ok((&b"abcd"[..], 0x020100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(3))));
+/// assert_eq!(be_i16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0003)));
+/// assert_eq!(be_i16(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1))));
+///
+/// let le_i16 = |s| {
+///   i16::<_, (_, ErrorKind)>(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_i16(&b"\x00\x03abcefg"[..]), Ok((&b"abcefg"[..], 0x0300)));
+/// assert_eq!(le_i16(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(1))));
 /// ```
 #[inline]
-pub fn le_i24<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i32, E> {
-  // Same as the unsigned version but we need to sign-extend manually here
-  map!(i, le_u24, |x| if x & 0x80_00_00 != 0 {
-    (x | 0xff_00_00_00) as i32
-  } else {
-    x as i32
-  })
+pub fn i16<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i16, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_i16,
+    crate::number::Endianness::Little => le_i16,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_i16,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_i16,
+  }
 }
 
-/// Recognizes a little endian signed 4 bytes integer
+/// Recognizes a signed 3 byte integer
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
-///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian i24 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian i24 integer.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::le_i32;
+/// use nom::number::streaming::i24;
 ///
-/// let parser = |s| {
-///   le_i32::<(_, ErrorKind)>(s)
+/// let be_i24 = |s| {
+///   i24::<_, (_, ErrorKind)>(nom::number::Endianness::Big)(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03abcd"), Ok((&b"abcd"[..], 0x03020100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(4))));
+/// assert_eq!(be_i24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x000305)));
+/// assert_eq!(be_i24(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2))));
+///
+/// let le_i24 = |s| {
+///   i24::<_, (_, ErrorKind)>(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_i24(&b"\x00\x03\x05abcefg"[..]), Ok((&b"abcefg"[..], 0x050300)));
+/// assert_eq!(le_i24(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(2))));
 /// ```
 #[inline]
-pub fn le_i32<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i32, E> {
-  map!(i, le_u32, |x| x as i32)
+pub fn i24<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_i24,
+    crate::number::Endianness::Little => le_i24,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_i24,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_i24,
+  }
 }
 
-/// Recognizes a little endian signed 8 bytes integer
+/// Recognizes a signed 4 byte integer
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
-///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian i32 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian i32 integer.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::le_i64;
+/// use nom::number::streaming::i32;
 ///
-/// let parser = |s| {
-///   le_i64::<(_, ErrorKind)>(s)
+/// let be_i32 = |s| {
+///   i32::<_, (_, ErrorKind)>(nom::number::Endianness::Big)(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07abcd"), Ok((&b"abcd"[..], 0x0706050403020100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(8))));
+/// assert_eq!(be_i32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00030507)));
+/// assert_eq!(be_i32(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3))));
+///
+/// let le_i32 = |s| {
+///   i32::<_, (_, ErrorKind)>(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_i32(&b"\x00\x03\x05\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07050300)));
+/// assert_eq!(le_i32(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(3))));
 /// ```
 #[inline]
-pub fn le_i64<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i64, E> {
-  map!(i, le_u64, |x| x as i64)
+pub fn i32<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_i32,
+    crate::number::Endianness::Little => le_i32,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_i32,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_i32,
+  }
 }
 
-/// Recognizes a little endian signed 16 bytes integer
+/// Recognizes a signed 8 byte integer
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
-///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian i64 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian i64 integer.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::le_i128;
+/// use nom::number::streaming::i64;
 ///
-/// let parser = |s| {
-///   le_i128::<(_, ErrorKind)>(s)
+/// let be_i64 = |s| {
+///   i64::<_, (_, ErrorKind)>(nom::number::Endianness::Big)(s)
 /// };
 ///
-/// assert_eq!(parser(b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15abcd"), Ok((&b"abcd"[..], 0x15141312111009080706050403020100)));
-/// assert_eq!(parser(b"\x01"), Err(Err::Incomplete(Needed::Size(16))));
+/// assert_eq!(be_i64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0001020304050607)));
+/// assert_eq!(be_i64(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7))));
+///
+/// let le_i64 = |s| {
+///   i64::<_, (_, ErrorKind)>(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_i64(&b"\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x0706050403020100)));
+/// assert_eq!(le_i64(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(7))));
+/// ```
+#[inline]
+pub fn i64<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_i64,
+    crate::number::Endianness::Little => le_i64,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_i64,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_i64,
+  }
+}
+
+/// Recognizes a signed 16 byte integer
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian i128 integer,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian i128 integer.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::streaming::i128;
+///
+/// let be_i128 = |s| {
+///   i128::<_, (_, ErrorKind)>(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_i128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x00010203040506070001020304050607)));
+/// assert_eq!(be_i128(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15))));
+///
+/// let le_i128 = |s| {
+///   i128::<_, (_, ErrorKind)>(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_i128(&b"\x00\x01\x02\x03\x04\x05\x06\x07\x00\x01\x02\x03\x04\x05\x06\x07abcefg"[..]), Ok((&b"abcefg"[..], 0x07060504030201000706050403020100)));
+/// assert_eq!(le_i128(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15))));
 /// ```
 #[inline]
 #[cfg(stable_i128)]
-pub fn le_i128<'a, E: ParseError<&'a [u8]>>(i: &'a[u8]) -> IResult<&'a[u8], i128, E> {
-  map!(i, le_u128, |x| x as i128)
+pub fn i128<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i128, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_i128,
+    crate::number::Endianness::Little => le_i128,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_i128,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_i128,
+  }
 }
 
-/// Recognizes a big endian 4 bytes floating point number
+/// Recognizes a big endian 4 bytes floating point number.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_f32;
 ///
 /// let parser = |s| {
-///   be_f32::<(_, ErrorKind)>(s)
+///   be_f32::<_, (_, ErrorKind)>(s)
 /// };
 ///
 /// assert_eq!(parser(&[0x40, 0x29, 0x00, 0x00][..]), Ok((&b""[..], 2.640625)));
-/// assert_eq!(parser(&[0x01]), Err(Err::Incomplete(Needed::Size(4))));
+/// assert_eq!(parser(&[0x01][..]), Err(Err::Incomplete(Needed::new(3))));
 /// ```
 #[inline]
-pub fn be_f32<'a, E: ParseError<&'a [u8]>>(input: &'a[u8]) -> IResult<&'a[u8], f32, E> {
+pub fn be_f32<I, E: ParseError<I>>(input: I) -> IResult<I, f32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
   match be_u32(input) {
     Err(e) => Err(e),
     Ok((i, o)) => Ok((i, f32::from_bits(o))),
   }
 }
 
-/// Recognizes a big endian 8 bytes floating point number
+/// Recognizes a big endian 8 bytes floating point number.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::be_f64;
 ///
 /// let parser = |s| {
-///   be_f64::<(_, ErrorKind)>(s)
+///   be_f64::<_, (_, ErrorKind)>(s)
 /// };
 ///
 /// assert_eq!(parser(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(parser(&[0x01]), Err(Err::Incomplete(Needed::Size(8))));
+/// assert_eq!(parser(&[0x01][..]), Err(Err::Incomplete(Needed::new(7))));
 /// ```
 #[inline]
-pub fn be_f64<'a, E: ParseError<&'a [u8]>>(input: &'a[u8]) -> IResult<&'a[u8], f64, E> {
+pub fn be_f64<I, E: ParseError<I>>(input: I) -> IResult<I, f64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
   match be_u64(input) {
     Err(e) => Err(e),
     Ok((i, o)) => Ok((i, f64::from_bits(o))),
   }
 }
 
-/// Recognizes a little endian 4 bytes floating point number
+/// Recognizes a little endian 4 bytes floating point number.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::le_f32;
 ///
 /// let parser = |s| {
-///   le_f32::<(_, ErrorKind)>(s)
+///   le_f32::<_, (_, ErrorKind)>(s)
 /// };
 ///
 /// assert_eq!(parser(&[0x00, 0x00, 0x48, 0x41][..]), Ok((&b""[..], 12.5)));
-/// assert_eq!(parser(&[0x01]), Err(Err::Incomplete(Needed::Size(4))));
+/// assert_eq!(parser(&[0x01][..]), Err(Err::Incomplete(Needed::new(3))));
 /// ```
 #[inline]
-pub fn le_f32<'a, E: ParseError<&'a [u8]>>(input: &'a[u8]) -> IResult<&'a[u8], f32, E> {
+pub fn le_f32<I, E: ParseError<I>>(input: I) -> IResult<I, f32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
   match le_u32(input) {
     Err(e) => Err(e),
     Ok((i, o)) => Ok((i, f32::from_bits(o))),
   }
 }
 
-/// Recognizes a little endian 8 bytes floating point number
+/// Recognizes a little endian 8 bytes floating point number.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::le_f64;
 ///
 /// let parser = |s| {
-///   le_f64::<(_, ErrorKind)>(s)
+///   le_f64::<_, (_, ErrorKind)>(s)
 /// };
 ///
 /// assert_eq!(parser(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x41][..]), Ok((&b""[..], 3145728.0)));
-/// assert_eq!(parser(&[0x01]), Err(Err::Incomplete(Needed::Size(8))));
+/// assert_eq!(parser(&[0x01][..]), Err(Err::Incomplete(Needed::new(7))));
 /// ```
 #[inline]
-pub fn le_f64<'a, E: ParseError<&'a [u8]>>(input: &'a[u8]) -> IResult<&'a[u8], f64, E> {
+pub fn le_f64<I, E: ParseError<I>>(input: I) -> IResult<I, f64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
   match le_u64(input) {
     Err(e) => Err(e),
     Ok((i, o)) => Ok((i, f64::from_bits(o))),
   }
 }
 
-/// Recognizes a hex-encoded integer
+/// Recognizes a 4 byte floating point number
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if there is not enough data
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian f32 float,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian f32 float.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
+/// use nom::number::streaming::f32;
+///
+/// let be_f32 = |s| {
+///   f32::<_, (_, ErrorKind)>(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_f32(&[0x41, 0x48, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
+/// assert_eq!(be_f32(&b"abc"[..]), Err(Err::Incomplete(Needed::new(1))));
+///
+/// let le_f32 = |s| {
+///   f32::<_, (_, ErrorKind)>(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_f32(&[0x00, 0x00, 0x48, 0x41][..]), Ok((&b""[..], 12.5)));
+/// assert_eq!(le_f32(&b"abc"[..]), Err(Err::Incomplete(Needed::new(1))));
+/// ```
+#[inline]
+pub fn f32<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, f32, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_f32,
+    crate::number::Endianness::Little => le_f32,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_f32,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_f32,
+  }
+}
+
+/// Recognizes an 8 byte floating point number
+///
+/// If the parameter is `nom::number::Endianness::Big`, parse a big endian f64 float,
+/// otherwise if `nom::number::Endianness::Little` parse a little endian f64 float.
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
+/// # use nom::Needed::Size;
+/// use nom::number::streaming::f64;
+///
+/// let be_f64 = |s| {
+///   f64::<_, (_, ErrorKind)>(nom::number::Endianness::Big)(s)
+/// };
+///
+/// assert_eq!(be_f64(&[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 12.5)));
+/// assert_eq!(be_f64(&b"abc"[..]), Err(Err::Incomplete(Needed::new(5))));
+///
+/// let le_f64 = |s| {
+///   f64::<_, (_, ErrorKind)>(nom::number::Endianness::Little)(s)
+/// };
+///
+/// assert_eq!(le_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40][..]), Ok((&b""[..], 12.5)));
+/// assert_eq!(le_f64(&b"abc"[..]), Err(Err::Incomplete(Needed::new(5))));
+/// ```
+#[inline]
+pub fn f64<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, f64, E>
+where
+  I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
+{
+  match endian {
+    crate::number::Endianness::Big => be_f64,
+    crate::number::Endianness::Little => le_f64,
+    #[cfg(target_endian = "big")]
+    crate::number::Endianness::Native => be_f64,
+    #[cfg(target_endian = "little")]
+    crate::number::Endianness::Native => le_f64,
+  }
+}
+
+/// Recognizes a hex-encoded integer.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+/// ```rust
+/// # use nom::{Err, error::ErrorKind, Needed};
 /// use nom::number::streaming::hex_u32;
 ///
 /// let parser = |s| {
@@ -696,11 +1325,11 @@
 /// };
 ///
 /// assert_eq!(parser(b"01AE;"), Ok((&b";"[..], 0x01AE)));
-/// assert_eq!(parser(b"abc"), Err(Err::Incomplete(Needed::Size(1))));
+/// assert_eq!(parser(b"abc"), Err(Err::Incomplete(Needed::new(1))));
 /// assert_eq!(parser(b"ggg"), Err(Err::Error((&b"ggg"[..], ErrorKind::IsA))));
 /// ```
 #[inline]
-pub fn hex_u32<'a, E: ParseError<&'a [u8]>>(input: &'a[u8]) -> IResult<&'a[u8], u32, E> {
+pub fn hex_u32<'a, E: ParseError<&'a [u8]>>(input: &'a [u8]) -> IResult<&'a [u8], u32, E> {
   let (i, o) = crate::bytes::streaming::is_a(&b"0123456789abcdefABCDEF"[..])(input)?;
 
   // Do not parse more than 8 characters for a u32
@@ -723,13 +1352,12 @@
   Ok((remaining, res))
 }
 
-/// Recognizes a floating point number in text format and returns the corresponding part of the input
+/// Recognizes a floating point number in text format and returns the corresponding part of the input.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if it reaches the end of input
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if it reaches the end of input.
 ///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
 /// use nom::number::streaming::recognize_float;
 ///
 /// let parser = |s| {
@@ -741,15 +1369,14 @@
 /// assert_eq!(parser("123K-01"), Ok(("K-01", "123")));
 /// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Char))));
 /// ```
-#[allow(unused_imports)]
-#[cfg_attr(rustfmt, rustfmt_skip)]
+#[rustfmt::skip]
 pub fn recognize_float<T, E:ParseError<T>>(input: T) -> IResult<T, T, E>
 where
   T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
   T: Clone + Offset,
   T: InputIter,
   <T as InputIter>::Item: AsChar,
-  T: InputTakeAtPosition,
+  T: InputTakeAtPosition + InputLength,
   <T as InputTakeAtPosition>::Item: AsChar
 {
   recognize(
@@ -768,157 +1395,249 @@
   )(input)
 }
 
-/// Recognizes floating point number in a byte string and returns a f32
+// workaround until issues with minimal-lexical are fixed
+#[doc(hidden)]
+pub fn recognize_float_or_exceptions<T, E: ParseError<T>>(input: T) -> IResult<T, T, E>
+where
+  T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
+  T: Clone + Offset,
+  T: InputIter + InputTake + InputLength + Compare<&'static str>,
+  <T as InputIter>::Item: AsChar,
+  T: InputTakeAtPosition,
+  <T as InputTakeAtPosition>::Item: AsChar,
+{
+  alt((
+    |i: T| {
+      recognize_float::<_, E>(i.clone()).map_err(|e| match e {
+        crate::Err::Error(_) => crate::Err::Error(E::from_error_kind(i, ErrorKind::Float)),
+        crate::Err::Failure(_) => crate::Err::Failure(E::from_error_kind(i, ErrorKind::Float)),
+        crate::Err::Incomplete(needed) => crate::Err::Incomplete(needed),
+      })
+    },
+    |i: T| {
+      crate::bytes::streaming::tag_no_case::<_, _, E>("nan")(i.clone())
+        .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float)))
+    },
+    |i: T| {
+      crate::bytes::streaming::tag_no_case::<_, _, E>("inf")(i.clone())
+        .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float)))
+    },
+    |i: T| {
+      crate::bytes::streaming::tag_no_case::<_, _, E>("infinity")(i.clone())
+        .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float)))
+    },
+  ))(input)
+}
+
+/// Recognizes a floating point number in text format and returns the integer, fraction and exponent parts of the input data
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if it reaches the end of input
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
+pub fn recognize_float_parts<T, E: ParseError<T>>(input: T) -> IResult<T, (bool, T, T, i32), E>
+where
+  T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
+  T: Clone + Offset,
+  T: InputIter + crate::traits::ParseTo<i32>,
+  <T as InputIter>::Item: AsChar,
+  T: InputTakeAtPosition + InputTake + InputLength,
+  <T as InputTakeAtPosition>::Item: AsChar,
+  T: for<'a> Compare<&'a [u8]>,
+  T: AsBytes,
+{
+  let (i, sign) = sign(input.clone())?;
+
+  //let (i, zeroes) = take_while(|c: <T as InputTakeAtPosition>::Item| c.as_char() == '0')(i)?;
+  let (i, zeroes) = match i.as_bytes().iter().position(|c| *c != b'0') {
+    Some(index) => i.take_split(index),
+    None => i.take_split(i.input_len()),
+  };
+
+  //let (i, mut integer) = digit0(i)?;
+  let (i, mut integer) = match i
+    .as_bytes()
+    .iter()
+    .position(|c| !(*c >= b'0' && *c <= b'9'))
+  {
+    Some(index) => i.take_split(index),
+    None => i.take_split(i.input_len()),
+  };
+
+  if integer.input_len() == 0 && zeroes.input_len() > 0 {
+    // keep the last zero if integer is empty
+    integer = zeroes.slice(zeroes.input_len() - 1..);
+  }
+
+  let (i, opt_dot) = opt(tag(&b"."[..]))(i)?;
+  let (i, fraction) = if opt_dot.is_none() {
+    let i2 = i.clone();
+    (i2, i.slice(..0))
+  } else {
+    // match number, trim right zeroes
+    let mut zero_count = 0usize;
+    let mut position = None;
+    for (pos, c) in i.as_bytes().iter().enumerate() {
+      if *c >= b'0' && *c <= b'9' {
+        if *c == b'0' {
+          zero_count += 1;
+        } else {
+          zero_count = 0;
+        }
+      } else {
+        position = Some(pos);
+        break;
+      }
+    }
+
+    let position = match position {
+      Some(p) => p,
+      None => return Err(Err::Incomplete(Needed::new(1))),
+    };
+
+    let index = if zero_count == 0 {
+      position
+    } else if zero_count == position {
+      position - zero_count + 1
+    } else {
+      position - zero_count
+    };
+
+    (i.slice(position..), i.slice(..index))
+  };
+
+  if integer.input_len() == 0 && fraction.input_len() == 0 {
+    return Err(Err::Error(E::from_error_kind(input, ErrorKind::Float)));
+  }
+
+  let i2 = i.clone();
+  let (i, e) = match i.as_bytes().iter().next() {
+    Some(b'e') => (i.slice(1..), true),
+    Some(b'E') => (i.slice(1..), true),
+    _ => (i, false),
+  };
+
+  let (i, exp) = if e {
+    cut(crate::character::streaming::i32)(i)?
+  } else {
+    (i2, 0)
+  };
+
+  Ok((i, (sign, integer, fraction, exp)))
+}
+
+/// Recognizes floating point number in text format and returns a f32.
+///
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::float;
+/// use nom::number::complete::float;
 ///
 /// let parser = |s| {
 ///   float(s)
 /// };
 ///
-/// assert_eq!(parser("11e-1;"), Ok((";", 1.1)));
-/// assert_eq!(parser("123E-02;"), Ok((";", 1.23)));
-/// assert_eq!(parser("123K-01"), Ok(("K-01", 123.0)));
-/// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Char))));
-/// ```
-#[cfg(not(feature = "lexical"))]
-pub fn float<T, E:ParseError<T>>(input: T) -> IResult<T, f32, E>
-where
-  T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
-  T: Clone + Offset,
-  T: InputIter + InputLength + crate::traits::ParseTo<f32>,
-  <T as InputIter>::Item: AsChar,
-  T: InputTakeAtPosition,
-  <T as InputTakeAtPosition>::Item: AsChar
-{
-  match recognize_float(input) {
-    Err(e) => Err(e),
-    Ok((i, s)) => match s.parse_to() {
-      Some(n) => Ok((i, n)),
-      None =>  Err(Err::Error(E::from_error_kind(i, ErrorKind::Float)))
-    }
-  }
-}
-
-/// Recognizes floating point number in a byte string and returns a f32
-///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if it reaches the end of input
-/// ```rust
-/// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
-/// use nom::number::streaming::float;
-///
-/// let parser = |s| {
-///   float(s)
-/// };
-///
-/// assert_eq!(parser("11e-1;"), Ok((";", 1.1)));
-/// assert_eq!(parser("123E-02;"), Ok((";", 1.23)));
+/// assert_eq!(parser("11e-1"), Ok(("", 1.1)));
+/// assert_eq!(parser("123E-02"), Ok(("", 1.23)));
 /// assert_eq!(parser("123K-01"), Ok(("K-01", 123.0)));
 /// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Float))));
 /// ```
-///
-/// this function uses the lexical-core crate for float parsing by default, you
-/// can deactivate it by removing the "lexical" feature
-#[cfg(feature = "lexical")]
-pub fn float<T, E:ParseError<T>>(input: T) -> IResult<T, f32, E>
+pub fn float<T, E: ParseError<T>>(input: T) -> IResult<T, f32, E>
 where
-  T: crate::traits::AsBytes + InputLength + Slice<RangeFrom<usize>>,
+  T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
+  T: Clone + Offset,
+  T: InputIter + InputLength + InputTake + crate::traits::ParseTo<f32> + Compare<&'static str>,
+  <T as InputIter>::Item: AsChar,
+  <T as InputIter>::IterElem: Clone,
+  T: InputTakeAtPosition,
+  <T as InputTakeAtPosition>::Item: AsChar,
+  T: AsBytes,
+  T: for<'a> Compare<&'a [u8]>,
 {
-  match ::lexical_core::parse_partial(input.as_bytes()) {
-    Ok((value, processed)) => {
-      if processed == input.input_len() {
-        Err(Err::Incomplete(Needed::Unknown))
-      } else {
-        Ok((input.slice(processed..), value))
-      }
-    },
-    Err(_) => Err(Err::Error(E::from_error_kind(input, ErrorKind::Float)))
+  /*
+  let (i, (sign, integer, fraction, exponent)) = recognize_float_parts(input)?;
+
+  let mut float: f32 = minimal_lexical::parse_float(
+    integer.as_bytes().iter(),
+    fraction.as_bytes().iter(),
+    exponent,
+  );
+  if !sign {
+    float = -float;
+  }
+
+  Ok((i, float))
+  */
+  let (i, s) = recognize_float_or_exceptions(input)?;
+  match s.parse_to() {
+    Some(f) => (Ok((i, f))),
+    None => Err(crate::Err::Error(E::from_error_kind(
+      i,
+      crate::error::ErrorKind::Float,
+    ))),
   }
 }
 
-/// Recognizes floating point number in a byte string and returns a f64
+/// Recognizes floating point number in text format and returns a f64.
 ///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if it reaches the end of input
+/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
+///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
-/// use nom::number::streaming::double;
+/// use nom::number::complete::double;
 ///
 /// let parser = |s| {
 ///   double(s)
 /// };
 ///
-/// assert_eq!(parser("11e-1;"), Ok((";", 1.1)));
-/// assert_eq!(parser("123E-02;"), Ok((";", 1.23)));
-/// assert_eq!(parser("123K-01"), Ok(("K-01", 123.0)));
-/// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Char))));
-/// ```
-#[cfg(not(feature = "lexical"))]
-pub fn double<T, E:ParseError<T>>(input: T) -> IResult<T, f64, E>
-where
-  T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
-  T: Clone + Offset,
-  T: InputIter + InputLength + crate::traits::ParseTo<f64>,
-  <T as InputIter>::Item: AsChar,
-  T: InputTakeAtPosition,
-  <T as InputTakeAtPosition>::Item: AsChar
-{
-  match recognize_float(input) {
-    Err(e) => Err(e),
-    Ok((i, s)) => match s.parse_to() {
-      Some(n) => Ok((i, n)),
-      None =>  Err(Err::Error(E::from_error_kind(i, ErrorKind::Float)))
-    }
-  }
-}
-
-/// Recognizes floating point number in a byte string and returns a f64
-///
-/// *streaming version*: will return `Err(nom::Err::Incomplete(_))` if it reaches the end of input
-/// ```rust
-/// # use nom::{Err, error::ErrorKind, Needed};
-/// # use nom::Needed::Size;
-/// use nom::number::streaming::double;
-///
-/// let parser = |s| {
-///   double(s)
-/// };
-///
-/// assert_eq!(parser("11e-1;"), Ok((";", 1.1)));
-/// assert_eq!(parser("123E-02;"), Ok((";", 1.23)));
+/// assert_eq!(parser("11e-1"), Ok(("", 1.1)));
+/// assert_eq!(parser("123E-02"), Ok(("", 1.23)));
 /// assert_eq!(parser("123K-01"), Ok(("K-01", 123.0)));
 /// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Float))));
 /// ```
-///
-/// this function uses the lexical-core crate for float parsing by default, you
-/// can deactivate it by removing the "lexical" feature
-#[cfg(feature = "lexical")]
-pub fn double<T, E:ParseError<T>>(input: T) -> IResult<T, f64, E>
+pub fn double<T, E: ParseError<T>>(input: T) -> IResult<T, f64, E>
 where
-  T: crate::traits::AsBytes + InputLength + Slice<RangeFrom<usize>>,
+  T: Slice<RangeFrom<usize>> + Slice<RangeTo<usize>>,
+  T: Clone + Offset,
+  T: InputIter + InputLength + InputTake + crate::traits::ParseTo<f64> + Compare<&'static str>,
+  <T as InputIter>::Item: AsChar,
+  <T as InputIter>::IterElem: Clone,
+  T: InputTakeAtPosition,
+  <T as InputTakeAtPosition>::Item: AsChar,
+  T: AsBytes,
+  T: for<'a> Compare<&'a [u8]>,
 {
-  match ::lexical_core::parse_partial(input.as_bytes()) {
-    Ok((value, processed)) => {
-      if processed == input.input_len() {
-        Err(Err::Incomplete(Needed::Unknown))
-      } else {
-        Ok((input.slice(processed..), value))
-      }
-    },
-    Err(_) => Err(Err::Error(E::from_error_kind(input, ErrorKind::Float)))
+  /*
+  let (i, (sign, integer, fraction, exponent)) = recognize_float_parts(input)?;
+
+  let mut float: f64 = minimal_lexical::parse_float(
+    integer.as_bytes().iter(),
+    fraction.as_bytes().iter(),
+    exponent,
+  );
+  if !sign {
+    float = -float;
+  }
+
+  Ok((i, float))
+  */
+  let (i, s) = recognize_float_or_exceptions(input)?;
+  match s.parse_to() {
+    Some(f) => (Ok((i, f))),
+    None => Err(crate::Err::Error(E::from_error_kind(
+      i,
+      crate::error::ErrorKind::Float,
+    ))),
   }
 }
 
 #[cfg(test)]
 mod tests {
   use super::*;
-  use crate::internal::{Err, Needed};
   use crate::error::ErrorKind;
+  use crate::internal::{Err, Needed};
+  use proptest::prelude::*;
 
   macro_rules! assert_parse(
     ($left: expr, $right: expr) => {
@@ -929,129 +1648,281 @@
 
   #[test]
   fn i8_tests() {
-    assert_parse!(be_i8(&[0x00]), Ok((&b""[..], 0)));
-    assert_parse!(be_i8(&[0x7f]), Ok((&b""[..], 127)));
-    assert_parse!(be_i8(&[0xff]), Ok((&b""[..], -1)));
-    assert_parse!(be_i8(&[0x80]), Ok((&b""[..], -128)));
+    assert_parse!(be_i8(&[0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(be_i8(&[0x7f][..]), Ok((&b""[..], 127)));
+    assert_parse!(be_i8(&[0xff][..]), Ok((&b""[..], -1)));
+    assert_parse!(be_i8(&[0x80][..]), Ok((&b""[..], -128)));
+    assert_parse!(be_i8(&[][..]), Err(Err::Incomplete(Needed::new(1))));
   }
 
   #[test]
   fn i16_tests() {
-    assert_parse!(be_i16(&[0x00, 0x00]), Ok((&b""[..], 0)));
-    assert_parse!(be_i16(&[0x7f, 0xff]), Ok((&b""[..], 32_767_i16)));
-    assert_parse!(be_i16(&[0xff, 0xff]), Ok((&b""[..], -1)));
-    assert_parse!(be_i16(&[0x80, 0x00]), Ok((&b""[..], -32_768_i16)));
+    assert_parse!(be_i16(&[0x00, 0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(be_i16(&[0x7f, 0xff][..]), Ok((&b""[..], 32_767_i16)));
+    assert_parse!(be_i16(&[0xff, 0xff][..]), Ok((&b""[..], -1)));
+    assert_parse!(be_i16(&[0x80, 0x00][..]), Ok((&b""[..], -32_768_i16)));
+    assert_parse!(be_i16(&[][..]), Err(Err::Incomplete(Needed::new(2))));
+    assert_parse!(be_i16(&[0x00][..]), Err(Err::Incomplete(Needed::new(1))));
   }
 
   #[test]
   fn u24_tests() {
-    assert_parse!(be_u24(&[0x00, 0x00, 0x00]), Ok((&b""[..], 0)));
-    assert_parse!(be_u24(&[0x00, 0xFF, 0xFF]), Ok((&b""[..], 65_535_u32)));
-    assert_parse!(be_u24(&[0x12, 0x34, 0x56]), Ok((&b""[..], 1_193_046_u32)));
+    assert_parse!(be_u24(&[0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(be_u24(&[0x00, 0xFF, 0xFF][..]), Ok((&b""[..], 65_535_u32)));
+    assert_parse!(
+      be_u24(&[0x12, 0x34, 0x56][..]),
+      Ok((&b""[..], 1_193_046_u32))
+    );
+    assert_parse!(be_u24(&[][..]), Err(Err::Incomplete(Needed::new(3))));
+    assert_parse!(be_u24(&[0x00][..]), Err(Err::Incomplete(Needed::new(2))));
+    assert_parse!(
+      be_u24(&[0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(1)))
+    );
   }
 
   #[test]
   fn i24_tests() {
-    assert_parse!(be_i24(&[0xFF, 0xFF, 0xFF]), Ok((&b""[..], -1_i32)));
-    assert_parse!(be_i24(&[0xFF, 0x00, 0x00]), Ok((&b""[..], -65_536_i32)));
-    assert_parse!(be_i24(&[0xED, 0xCB, 0xAA]), Ok((&b""[..], -1_193_046_i32)));
+    assert_parse!(be_i24(&[0xFF, 0xFF, 0xFF][..]), Ok((&b""[..], -1_i32)));
+    assert_parse!(be_i24(&[0xFF, 0x00, 0x00][..]), Ok((&b""[..], -65_536_i32)));
+    assert_parse!(
+      be_i24(&[0xED, 0xCB, 0xAA][..]),
+      Ok((&b""[..], -1_193_046_i32))
+    );
+    assert_parse!(be_i24(&[][..]), Err(Err::Incomplete(Needed::new(3))));
+    assert_parse!(be_i24(&[0x00][..]), Err(Err::Incomplete(Needed::new(2))));
+    assert_parse!(
+      be_i24(&[0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(1)))
+    );
   }
 
   #[test]
   fn i32_tests() {
-    assert_parse!(be_i32(&[0x00, 0x00, 0x00, 0x00]), Ok((&b""[..], 0)));
+    assert_parse!(be_i32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)));
     assert_parse!(
-      be_i32(&[0x7f, 0xff, 0xff, 0xff]),
+      be_i32(&[0x7f, 0xff, 0xff, 0xff][..]),
       Ok((&b""[..], 2_147_483_647_i32))
     );
-    assert_parse!(be_i32(&[0xff, 0xff, 0xff, 0xff]), Ok((&b""[..], -1)));
+    assert_parse!(be_i32(&[0xff, 0xff, 0xff, 0xff][..]), Ok((&b""[..], -1)));
     assert_parse!(
-      be_i32(&[0x80, 0x00, 0x00, 0x00]),
+      be_i32(&[0x80, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], -2_147_483_648_i32))
     );
+    assert_parse!(be_i32(&[][..]), Err(Err::Incomplete(Needed::new(4))));
+    assert_parse!(be_i32(&[0x00][..]), Err(Err::Incomplete(Needed::new(3))));
+    assert_parse!(
+      be_i32(&[0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(2)))
+    );
+    assert_parse!(
+      be_i32(&[0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(1)))
+    );
   }
 
   #[test]
   fn i64_tests() {
     assert_parse!(
-      be_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      be_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], 0))
     );
     assert_parse!(
-      be_i64(&[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
+      be_i64(&[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]),
       Ok((&b""[..], 9_223_372_036_854_775_807_i64))
     );
     assert_parse!(
-      be_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
+      be_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]),
       Ok((&b""[..], -1))
     );
     assert_parse!(
-      be_i64(&[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      be_i64(&[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], -9_223_372_036_854_775_808_i64))
     );
+    assert_parse!(be_i64(&[][..]), Err(Err::Incomplete(Needed::new(8))));
+    assert_parse!(be_i64(&[0x00][..]), Err(Err::Incomplete(Needed::new(7))));
+    assert_parse!(
+      be_i64(&[0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(6)))
+    );
+    assert_parse!(
+      be_i64(&[0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(5)))
+    );
+    assert_parse!(
+      be_i64(&[0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(4)))
+    );
+    assert_parse!(
+      be_i64(&[0x00, 0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(3)))
+    );
+    assert_parse!(
+      be_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(2)))
+    );
+    assert_parse!(
+      be_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(1)))
+    );
   }
 
   #[test]
   #[cfg(stable_i128)]
   fn i128_tests() {
     assert_parse!(
-      be_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      be_i128(
+        &[
+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+          0x00
+        ][..]
+      ),
       Ok((&b""[..], 0))
     );
     assert_parse!(
-      be_i128(&[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
-      Ok((&b""[..], 170_141_183_460_469_231_731_687_303_715_884_105_727_i128))
+      be_i128(
+        &[
+          0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+          0xff
+        ][..]
+      ),
+      Ok((
+        &b""[..],
+        170_141_183_460_469_231_731_687_303_715_884_105_727_i128
+      ))
     );
     assert_parse!(
-      be_i128(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
+      be_i128(
+        &[
+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+          0xff
+        ][..]
+      ),
       Ok((&b""[..], -1))
     );
     assert_parse!(
-      be_i128(&[0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
-      Ok((&b""[..], -170_141_183_460_469_231_731_687_303_715_884_105_728_i128))
+      be_i128(
+        &[
+          0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+          0x00
+        ][..]
+      ),
+      Ok((
+        &b""[..],
+        -170_141_183_460_469_231_731_687_303_715_884_105_728_i128
+      ))
+    );
+    assert_parse!(be_i128(&[][..]), Err(Err::Incomplete(Needed::new(16))));
+    assert_parse!(be_i128(&[0x00][..]), Err(Err::Incomplete(Needed::new(15))));
+    assert_parse!(
+      be_i128(&[0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(14)))
+    );
+    assert_parse!(
+      be_i128(&[0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(13)))
+    );
+    assert_parse!(
+      be_i128(&[0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(12)))
+    );
+    assert_parse!(
+      be_i128(&[0x00, 0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(11)))
+    );
+    assert_parse!(
+      be_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(10)))
+    );
+    assert_parse!(
+      be_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(9)))
+    );
+    assert_parse!(
+      be_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(8)))
+    );
+    assert_parse!(
+      be_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(7)))
+    );
+    assert_parse!(
+      be_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(6)))
+    );
+    assert_parse!(
+      be_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(5)))
+    );
+    assert_parse!(
+      be_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(4)))
+    );
+    assert_parse!(
+      be_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
+      Err(Err::Incomplete(Needed::new(3)))
+    );
+    assert_parse!(
+      be_i128(
+        &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]
+      ),
+      Err(Err::Incomplete(Needed::new(2)))
+    );
+    assert_parse!(
+      be_i128(
+        &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
+          [..]
+      ),
+      Err(Err::Incomplete(Needed::new(1)))
     );
   }
 
   #[test]
   fn le_i8_tests() {
-    assert_parse!(le_i8(&[0x00]), Ok((&b""[..], 0)));
-    assert_parse!(le_i8(&[0x7f]), Ok((&b""[..], 127)));
-    assert_parse!(le_i8(&[0xff]), Ok((&b""[..], -1)));
-    assert_parse!(le_i8(&[0x80]), Ok((&b""[..], -128)));
+    assert_parse!(le_i8(&[0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(le_i8(&[0x7f][..]), Ok((&b""[..], 127)));
+    assert_parse!(le_i8(&[0xff][..]), Ok((&b""[..], -1)));
+    assert_parse!(le_i8(&[0x80][..]), Ok((&b""[..], -128)));
   }
 
   #[test]
   fn le_i16_tests() {
-    assert_parse!(le_i16(&[0x00, 0x00]), Ok((&b""[..], 0)));
-    assert_parse!(le_i16(&[0xff, 0x7f]), Ok((&b""[..], 32_767_i16)));
-    assert_parse!(le_i16(&[0xff, 0xff]), Ok((&b""[..], -1)));
-    assert_parse!(le_i16(&[0x00, 0x80]), Ok((&b""[..], -32_768_i16)));
+    assert_parse!(le_i16(&[0x00, 0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(le_i16(&[0xff, 0x7f][..]), Ok((&b""[..], 32_767_i16)));
+    assert_parse!(le_i16(&[0xff, 0xff][..]), Ok((&b""[..], -1)));
+    assert_parse!(le_i16(&[0x00, 0x80][..]), Ok((&b""[..], -32_768_i16)));
   }
 
   #[test]
   fn le_u24_tests() {
-    assert_parse!(le_u24(&[0x00, 0x00, 0x00]), Ok((&b""[..], 0)));
-    assert_parse!(le_u24(&[0xFF, 0xFF, 0x00]), Ok((&b""[..], 65_535_u32)));
-    assert_parse!(le_u24(&[0x56, 0x34, 0x12]), Ok((&b""[..], 1_193_046_u32)));
+    assert_parse!(le_u24(&[0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)));
+    assert_parse!(le_u24(&[0xFF, 0xFF, 0x00][..]), Ok((&b""[..], 65_535_u32)));
+    assert_parse!(
+      le_u24(&[0x56, 0x34, 0x12][..]),
+      Ok((&b""[..], 1_193_046_u32))
+    );
   }
 
   #[test]
   fn le_i24_tests() {
-    assert_parse!(le_i24(&[0xFF, 0xFF, 0xFF]), Ok((&b""[..], -1_i32)));
-    assert_parse!(le_i24(&[0x00, 0x00, 0xFF]), Ok((&b""[..], -65_536_i32)));
-    assert_parse!(le_i24(&[0xAA, 0xCB, 0xED]), Ok((&b""[..], -1_193_046_i32)));
+    assert_parse!(le_i24(&[0xFF, 0xFF, 0xFF][..]), Ok((&b""[..], -1_i32)));
+    assert_parse!(le_i24(&[0x00, 0x00, 0xFF][..]), Ok((&b""[..], -65_536_i32)));
+    assert_parse!(
+      le_i24(&[0xAA, 0xCB, 0xED][..]),
+      Ok((&b""[..], -1_193_046_i32))
+    );
   }
 
   #[test]
   fn le_i32_tests() {
-    assert_parse!(le_i32(&[0x00, 0x00, 0x00, 0x00]), Ok((&b""[..], 0)));
+    assert_parse!(le_i32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0)));
     assert_parse!(
-      le_i32(&[0xff, 0xff, 0xff, 0x7f]),
+      le_i32(&[0xff, 0xff, 0xff, 0x7f][..]),
       Ok((&b""[..], 2_147_483_647_i32))
     );
-    assert_parse!(le_i32(&[0xff, 0xff, 0xff, 0xff]), Ok((&b""[..], -1)));
+    assert_parse!(le_i32(&[0xff, 0xff, 0xff, 0xff][..]), Ok((&b""[..], -1)));
     assert_parse!(
-      le_i32(&[0x00, 0x00, 0x00, 0x80]),
+      le_i32(&[0x00, 0x00, 0x00, 0x80][..]),
       Ok((&b""[..], -2_147_483_648_i32))
     );
   }
@@ -1059,19 +1930,19 @@
   #[test]
   fn le_i64_tests() {
     assert_parse!(
-      le_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      le_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], 0))
     );
     assert_parse!(
-      le_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f]),
+      le_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f][..]),
       Ok((&b""[..], 9_223_372_036_854_775_807_i64))
     );
     assert_parse!(
-      le_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
+      le_i64(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff][..]),
       Ok((&b""[..], -1))
     );
     assert_parse!(
-      le_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]),
+      le_i64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80][..]),
       Ok((&b""[..], -9_223_372_036_854_775_808_i64))
     );
   }
@@ -1080,28 +1951,54 @@
   #[cfg(stable_i128)]
   fn le_i128_tests() {
     assert_parse!(
-      le_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      le_i128(
+        &[
+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+          0x00
+        ][..]
+      ),
       Ok((&b""[..], 0))
     );
     assert_parse!(
-      le_i128(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f]),
-      Ok((&b""[..], 170_141_183_460_469_231_731_687_303_715_884_105_727_i128))
+      le_i128(
+        &[
+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+          0x7f
+        ][..]
+      ),
+      Ok((
+        &b""[..],
+        170_141_183_460_469_231_731_687_303_715_884_105_727_i128
+      ))
     );
     assert_parse!(
-      le_i128(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
+      le_i128(
+        &[
+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+          0xff
+        ][..]
+      ),
       Ok((&b""[..], -1))
     );
     assert_parse!(
-      le_i128(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]),
-      Ok((&b""[..], -170_141_183_460_469_231_731_687_303_715_884_105_728_i128))
+      le_i128(
+        &[
+          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+          0x80
+        ][..]
+      ),
+      Ok((
+        &b""[..],
+        -170_141_183_460_469_231_731_687_303_715_884_105_728_i128
+      ))
     );
   }
 
   #[test]
   fn be_f32_tests() {
-    assert_parse!(be_f32(&[0x00, 0x00, 0x00, 0x00]), Ok((&b""[..], 0_f32)));
+    assert_parse!(be_f32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0_f32)));
     assert_parse!(
-      be_f32(&[0x4d, 0x31, 0x1f, 0xd8]),
+      be_f32(&[0x4d, 0x31, 0x1f, 0xd8][..]),
       Ok((&b""[..], 185_728_392_f32))
     );
   }
@@ -1109,20 +2006,20 @@
   #[test]
   fn be_f64_tests() {
     assert_parse!(
-      be_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      be_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], 0_f64))
     );
     assert_parse!(
-      be_f64(&[0x41, 0xa6, 0x23, 0xfb, 0x10, 0x00, 0x00, 0x00]),
+      be_f64(&[0x41, 0xa6, 0x23, 0xfb, 0x10, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], 185_728_392_f64))
     );
   }
 
   #[test]
   fn le_f32_tests() {
-    assert_parse!(le_f32(&[0x00, 0x00, 0x00, 0x00]), Ok((&b""[..], 0_f32)));
+    assert_parse!(le_f32(&[0x00, 0x00, 0x00, 0x00][..]), Ok((&b""[..], 0_f32)));
     assert_parse!(
-      le_f32(&[0xd8, 0x1f, 0x31, 0x4d]),
+      le_f32(&[0xd8, 0x1f, 0x31, 0x4d][..]),
       Ok((&b""[..], 185_728_392_f32))
     );
   }
@@ -1130,11 +2027,11 @@
   #[test]
   fn le_f64_tests() {
     assert_parse!(
-      le_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
+      le_f64(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00][..]),
       Ok((&b""[..], 0_f64))
     );
     assert_parse!(
-      le_f64(&[0x00, 0x00, 0x00, 0x10, 0xfb, 0x23, 0xa6, 0x41]),
+      le_f64(&[0x00, 0x00, 0x00, 0x10, 0xfb, 0x23, 0xa6, 0x41][..]),
       Ok((&b""[..], 185_728_392_f64))
     );
   }
@@ -1156,7 +2053,7 @@
     );
     assert_parse!(hex_u32(&b"ffffffff;"[..]), Ok((&b";"[..], 4_294_967_295)));
     assert_parse!(hex_u32(&b"0x1be2;"[..]), Ok((&b"x1be2;"[..], 0)));
-    assert_parse!(hex_u32(&b"12af"[..]), Err(Err::Incomplete(Needed::Size(1))));
+    assert_parse!(hex_u32(&b"12af"[..]), Err(Err::Incomplete(Needed::new(1))));
   }
 
   #[test]
@@ -1179,6 +2076,7 @@
       "12.34",
       "-1.234E-12",
       "-1.234e-12",
+      "0.00000000000000000087",
     ];
 
     for test in test_cases.drain(..) {
@@ -1200,8 +2098,126 @@
     let remaining_exponent = "-1.234E-";
     assert_parse!(
       recognize_float(remaining_exponent),
-      Err(Err::Incomplete(Needed::Size(1)))
+      Err(Err::Incomplete(Needed::new(1)))
+    );
+
+    let (_i, nan) = float::<_, ()>("NaN").unwrap();
+    assert!(nan.is_nan());
+
+    let (_i, inf) = float::<_, ()>("inf").unwrap();
+    assert!(inf.is_infinite());
+    let (_i, inf) = float::<_, ()>("infinite").unwrap();
+    assert!(inf.is_infinite());
+  }
+
+  #[test]
+  fn configurable_endianness() {
+    use crate::number::Endianness;
+
+    fn be_tst16(i: &[u8]) -> IResult<&[u8], u16> {
+      u16(Endianness::Big)(i)
+    }
+    fn le_tst16(i: &[u8]) -> IResult<&[u8], u16> {
+      u16(Endianness::Little)(i)
+    }
+    assert_eq!(be_tst16(&[0x80, 0x00]), Ok((&b""[..], 32_768_u16)));
+    assert_eq!(le_tst16(&[0x80, 0x00]), Ok((&b""[..], 128_u16)));
+
+    fn be_tst32(i: &[u8]) -> IResult<&[u8], u32> {
+      u32(Endianness::Big)(i)
+    }
+    fn le_tst32(i: &[u8]) -> IResult<&[u8], u32> {
+      u32(Endianness::Little)(i)
+    }
+    assert_eq!(
+      be_tst32(&[0x12, 0x00, 0x60, 0x00]),
+      Ok((&b""[..], 302_014_464_u32))
+    );
+    assert_eq!(
+      le_tst32(&[0x12, 0x00, 0x60, 0x00]),
+      Ok((&b""[..], 6_291_474_u32))
+    );
+
+    fn be_tst64(i: &[u8]) -> IResult<&[u8], u64> {
+      u64(Endianness::Big)(i)
+    }
+    fn le_tst64(i: &[u8]) -> IResult<&[u8], u64> {
+      u64(Endianness::Little)(i)
+    }
+    assert_eq!(
+      be_tst64(&[0x12, 0x00, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
+      Ok((&b""[..], 1_297_142_246_100_992_000_u64))
+    );
+    assert_eq!(
+      le_tst64(&[0x12, 0x00, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
+      Ok((&b""[..], 36_028_874_334_666_770_u64))
+    );
+
+    fn be_tsti16(i: &[u8]) -> IResult<&[u8], i16> {
+      i16(Endianness::Big)(i)
+    }
+    fn le_tsti16(i: &[u8]) -> IResult<&[u8], i16> {
+      i16(Endianness::Little)(i)
+    }
+    assert_eq!(be_tsti16(&[0x00, 0x80]), Ok((&b""[..], 128_i16)));
+    assert_eq!(le_tsti16(&[0x00, 0x80]), Ok((&b""[..], -32_768_i16)));
+
+    fn be_tsti32(i: &[u8]) -> IResult<&[u8], i32> {
+      i32(Endianness::Big)(i)
+    }
+    fn le_tsti32(i: &[u8]) -> IResult<&[u8], i32> {
+      i32(Endianness::Little)(i)
+    }
+    assert_eq!(
+      be_tsti32(&[0x00, 0x12, 0x60, 0x00]),
+      Ok((&b""[..], 1_204_224_i32))
+    );
+    assert_eq!(
+      le_tsti32(&[0x00, 0x12, 0x60, 0x00]),
+      Ok((&b""[..], 6_296_064_i32))
+    );
+
+    fn be_tsti64(i: &[u8]) -> IResult<&[u8], i64> {
+      i64(Endianness::Big)(i)
+    }
+    fn le_tsti64(i: &[u8]) -> IResult<&[u8], i64> {
+      i64(Endianness::Little)(i)
+    }
+    assert_eq!(
+      be_tsti64(&[0x00, 0xFF, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
+      Ok((&b""[..], 71_881_672_479_506_432_i64))
+    );
+    assert_eq!(
+      le_tsti64(&[0x00, 0xFF, 0x60, 0x00, 0x12, 0x00, 0x80, 0x00]),
+      Ok((&b""[..], 36_028_874_334_732_032_i64))
     );
   }
 
+  #[cfg(feature = "std")]
+  fn parse_f64(i: &str) -> IResult<&str, f64, ()> {
+    use crate::traits::ParseTo;
+    match recognize_float(i) {
+      Err(e) => Err(e),
+      Ok((i, s)) => {
+        if s.is_empty() {
+          return Err(Err::Error(()));
+        }
+        match s.parse_to() {
+          Some(n) => Ok((i, n)),
+          None => Err(Err::Error(())),
+        }
+      }
+    }
+  }
+
+  proptest! {
+    #[test]
+    #[cfg(feature = "std")]
+    fn floats(s in "\\PC*") {
+        println!("testing {}", s);
+        let res1 = parse_f64(&s);
+        let res2 = double::<_, ()>(s.as_str());
+        assert_eq!(res1, res2);
+    }
+  }
 }
diff --git a/src/regexp.rs b/src/regexp.rs
deleted file mode 100644
index fd165e1..0000000
--- a/src/regexp.rs
+++ /dev/null
@@ -1,1090 +0,0 @@
-#[doc(hidden)]
-#[macro_export]
-macro_rules! regex (
-  ($re: ident, $s:expr) => (
-    lazy_static! {
-      static ref $re: $crate::lib::regex::Regex = $crate::lib::regex::Regex::new($s).unwrap();
-    }
-  );
-);
-
-#[doc(hidden)]
-#[macro_export]
-macro_rules! regex_bytes (
-  ($re: ident, $s:expr) => (
-    lazy_static! {
-      static ref $re: $crate::lib::regex::bytes::Regex = $crate::lib::regex::bytes::Regex::new($s).unwrap();
-    }
-  );
-);
-
-/// `re_match!(regexp) => &[T] -> IResult<&[T], &[T]>`
-/// Returns the whole input if a match is found
-///
-/// requires the `regexp` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_match (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::InputLength;
-      use $crate::Slice;
-      let re = $crate::lib::regex::Regex::new($re).unwrap();
-      if re.is_match(&$i) {
-        Ok(($i.slice($i.input_len()..), $i))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpMatch)));
-        res
-      }
-    }
-  )
-);
-
-#[cfg(feature = "regexp_macros")]
-/// `re_match_static!(regexp) => &[T] -> IResult<&[T], &[T]>`
-/// Returns the whole input if a match is found. Regular expression calculated at compile time
-///
-/// requires the `regexp_macros` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_match_static (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::InputLength;
-      use $crate::Slice;
-      regex!(RE, $re);
-      if RE.is_match(&$i) {
-        Ok(($i.slice($i.input_len()..), $i))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpMatch)));
-        res
-      }
-    }
-  )
-);
-
-/// `re_bytes_match!(regexp) => &[T] -> IResult<&[T], &[T]>`
-/// Returns the whole input if a match is found
-///
-/// requires the `regexp` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_bytes_match (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::InputLength;
-      use $crate::Slice;
-      let re = $crate::lib::regex::bytes::Regex::new($re).unwrap();
-      if re.is_match(&$i) {
-        Ok(($i.slice($i.input_len()..), $i))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpMatch)));
-        res
-      }
-    }
-  )
-);
-
-#[cfg(feature = "regexp_macros")]
-/// `re_bytes_match_static!(regexp) => &[T] -> IResult<&[T], &[T]>`
-/// Returns the whole input if a match is found. Regular expression calculated at compile time
-///
-/// requires the `regexp_macros` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_bytes_match_static (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::InputLength;
-      use $crate::Slice;
-      regex_bytes!(RE, $re);
-      if RE.is_match(&$i) {
-        Ok(($i.slice($i.input_len()..), $i))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpMatch)));
-        res
-      }
-    }
-  )
-);
-
-/// `re_find!(regexp) => &[T] -> IResult<&[T], &[T]>`
-/// Returns the first match
-///
-/// requires the `regexp` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_find (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      let re = $crate::lib::regex::Regex::new($re).unwrap();
-      if let Some(m) = re.find(&$i) {
-        Ok(($i.slice(m.end()..), $i.slice(m.start()..m.end())))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpFind)));
-        res
-      }
-    }
-  )
-);
-
-#[cfg(feature = "regexp_macros")]
-/// `re_find_static!(regexp) => &[T] -> IResult<&[T], &[T]>`
-/// Returns the first match. Regular expression calculated at compile time
-///
-/// requires the `regexp_macros` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_find_static (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      regex!(RE, $re);
-      if let Some(m) = RE.find(&$i) {
-        Ok(($i.slice(m.end()..), $i.slice(m.start()..m.end())))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpFind)));
-        res
-      }
-    }
-
-  )
-);
-
-/// `re_bytes_find!(regexp) => &[T] -> IResult<&[T], &[T]>`
-/// Returns the first match
-///
-/// requires the `regexp` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_bytes_find (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      let re = $crate::lib::regex::bytes::Regex::new($re).unwrap();
-      if let Some(m) = re.find(&$i) {
-        Ok(($i.slice(m.end()..), $i.slice(m.start()..m.end())))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpFind)));
-        res
-      }
-    }
-  )
-);
-
-#[cfg(feature = "regexp_macros")]
-/// `re_bytes_find!(regexp) => &[T] -> IResult<&[T], &[T]>`
-/// Returns the first match. Regular expression calculated at compile time
-///
-/// requires the `regexp_macros` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_bytes_find_static (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      regex_bytes!(RE, $re);
-      if let Some(m) = RE.find(&$i) {
-        Ok(($i.slice(m.end()..), $i.slice(m.start()..m.end())))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpFind)));
-        res
-      }
-    }
-
-  )
-);
-
-/// `re_matches!(regexp) => &[T] -> IResult<&[T], Vec<&[T]>>`
-/// Returns all the matched parts
-///
-/// requires the `regexp` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_matches (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      let re = $crate::lib::regex::Regex::new($re).unwrap();
-      let v: Vec<_> = re.find_iter(&$i).map(|m| $i.slice(m.start()..m.end())).collect();
-      if v.len() != 0 {
-        let offset = {
-          let end = v.last().unwrap();
-          end.as_ptr() as usize + end.len() - $i.as_ptr() as usize
-        };
-        Ok(($i.slice(offset..), v))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpMatches)));
-        res
-      }
-    }
-  )
-);
-
-#[cfg(feature = "regexp_macros")]
-/// `re_matches_static!(regexp) => &[T] -> IResult<&[T], Vec<&[T]>>`
-/// Returns all the matched parts. Regular expression calculated at compile time
-///
-/// requires the `regexp_macros` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_matches_static (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      regex!(RE, $re);
-      let v: Vec<_> = RE.find_iter(&$i).map(|m| $i.slice(m.start()..m.end())).collect();
-      if v.len() != 0 {
-        let offset = {
-          let end = v.last().unwrap();
-          end.as_ptr() as usize + end.len() - $i.as_ptr() as usize
-        };
-        Ok(($i.slice(offset..), v))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpMatches)));
-        res
-      }
-    }
-  )
-);
-
-/// `re_bytes_matches!(regexp) => &[T] -> IResult<&[T], Vec<&[T]>>`
-/// Returns all the matched parts
-///
-/// requires the `regexp` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_bytes_matches (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      let re = $crate::lib::regex::bytes::Regex::new($re).unwrap();
-      let v: Vec<_> = re.find_iter(&$i).map(|m| $i.slice(m.start()..m.end())).collect();
-      if v.len() != 0 {
-        let offset = {
-          let end = v.last().unwrap();
-          end.as_ptr() as usize + end.len() - $i.as_ptr() as usize
-        };
-        Ok(($i.slice(offset..), v))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpMatches)));
-        res
-      }
-    }
-  )
-);
-
-#[cfg(feature = "regexp_macros")]
-/// `re_bytes_matches_static!(regexp) => &[T] -> IResult<&[T], Vec<&[T]>>`
-/// Returns all the matched parts. Regular expression calculated at compile time
-///
-/// requires the `regexp_macros` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_bytes_matches_static (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      regex_bytes!(RE, $re);
-      let v: Vec<_> = RE.find_iter(&$i).map(|m| $i.slice(m.start()..m.end())).collect();
-      if v.len() != 0 {
-        let offset = {
-          let end = v.last().unwrap();
-          end.as_ptr() as usize + end.len() - $i.as_ptr() as usize
-        };
-        Ok(($i.slice(offset..), v))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpMatches)));
-        res
-      }
-    }
-  )
-);
-
-/// `re_capture!(regexp) => &[T] -> IResult<&[T], Vec<&[T]>>`
-/// Returns the first capture group
-///
-/// requires the `regexp` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_capture (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      let re = $crate::lib::regex::Regex::new($re).unwrap();
-      if let Some(c) = re.captures(&$i) {
-        let v:Vec<_> = c.iter().filter(|el| el.is_some()).map(|el| el.unwrap()).map(|m| $i.slice(m.start()..m.end())).collect();
-        let offset = {
-          let end = v.last().unwrap();
-          end.as_ptr() as usize + end.len() - $i.as_ptr() as usize
-        };
-        Ok(($i.slice(offset..), v))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpCapture)));
-        res
-      }
-    }
-  )
-);
-
-#[cfg(feature = "regexp_macros")]
-/// `re_capture_static!(regexp) => &[T] -> IResult<&[T], Vec<&[T]>>`
-/// Returns the first capture group. Regular expression calculated at compile time
-///
-/// requires the `regexp_macros` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_capture_static (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      regex!(RE, $re);
-      if let Some(c) = RE.captures(&$i) {
-        let v:Vec<_> = c.iter().filter(|el| el.is_some()).map(|el| el.unwrap()).map(|m| $i.slice(m.start()..m.end())).collect();
-        let offset = {
-          let end = v.last().unwrap();
-          end.as_ptr() as usize + end.len() - $i.as_ptr() as usize
-        };
-        Ok(($i.slice(offset..), v))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpCapture)));
-        res
-      }
-    }
-  )
-);
-
-/// `re_bytes_capture!(regexp) => &[T] -> IResult<&[T], Vec<&[T]>>`
-/// Returns the first capture group
-///
-/// requires the `regexp` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_bytes_capture (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      let re = $crate::lib::regex::bytes::Regex::new($re).unwrap();
-      if let Some(c) = re.captures(&$i) {
-        let v:Vec<_> = c.iter().filter(|el| el.is_some()).map(|el| el.unwrap()).map(|m| $i.slice(m.start()..m.end())).collect();
-        let offset = {
-          let end = v.last().unwrap();
-          end.as_ptr() as usize + end.len() - $i.as_ptr() as usize
-        };
-        Ok(($i.slice(offset..), v))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpCapture)));
-        res
-      }
-    }
-  )
-);
-
-#[cfg(feature = "regexp_macros")]
-/// `re_bytes_capture_static!(regexp) => &[T] -> IResult<&[T], Vec<&[T]>>`
-/// Returns the first capture group. Regular expression calculated at compile time
-///
-/// requires the `regexp_macros` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_bytes_capture_static (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      regex_bytes!(RE, $re);
-      if let Some(c) = RE.captures(&$i) {
-        let v:Vec<_> = c.iter().filter(|el| el.is_some()).map(|el| el.unwrap()).map(|m| $i.slice(m.start()..m.end())).collect();
-        let offset = {
-          let end = v.last().unwrap();
-          end.as_ptr() as usize + end.len() - $i.as_ptr() as usize
-        };
-        Ok(($i.slice(offset..), v))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpCapture)));
-        res
-      }
-    }
-  )
-);
-
-/// `re_captures!(regexp) => &[T] -> IResult<&[T], Vec<Vec<&[T]>>>`
-/// Returns all the capture groups
-///
-/// requires the `regexp` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_captures (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      let re = $crate::lib::regex::Regex::new($re).unwrap();
-      let v:Vec<Vec<_>> = re.captures_iter(&$i)
-        .map(|c| c.iter().filter(|el| el.is_some()).map(|el| el.unwrap())
-             .map(|m| $i.slice(m.start()..m.end())).collect()).collect();
-      if v.len() != 0 {
-        let offset = {
-          let end = v.last().unwrap().last().unwrap();
-          end.as_ptr() as usize + end.len() - $i.as_ptr() as usize
-        };
-        Ok(($i.slice(offset..), v))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpCapture)));
-        res
-      }
-    }
-  )
-);
-
-#[cfg(feature = "regexp_macros")]
-/// `re_captures_static!(regexp) => &[T] -> IResult<&[T], Vec<Vec<&[T]>>>`
-/// Returns all the capture groups. Regular expression calculated at compile time
-///
-/// requires the `regexp_macros` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_captures_static (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      regex!(RE, $re);
-      let v:Vec<Vec<_>> = RE.captures_iter(&$i)
-        .map(|c| c.iter().filter(|el| el.is_some()).map(|el| el.unwrap()).map(|m| $i.slice(m.start()..m.end())).collect()).collect();
-      if v.len() != 0 {
-        let offset = {
-          let end = v.last().unwrap().last().unwrap();
-          end.as_ptr() as usize + end.len() - $i.as_ptr() as usize
-        };
-        Ok(($i.slice(offset..), v))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpCapture)));
-        res
-      }
-    }
-  )
-);
-
-/// `re_bytes_captures!(regexp) => &[T] -> IResult<&[T], Vec<Vec<&[T]>>>`
-/// Returns all the capture groups
-///
-/// requires the `regexp` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_bytes_captures (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      let re = $crate::lib::regex::bytes::Regex::new($re).unwrap();
-      let v:Vec<Vec<_>> = re.captures_iter(&$i)
-        .map(|c| c.iter().filter(|el| el.is_some()).map(|el| el.unwrap()).map(|m| $i.slice(m.start()..m.end())).collect()).collect();
-      if v.len() != 0 {
-        let offset = {
-          let end = v.last().unwrap().last().unwrap();
-          end.as_ptr() as usize + end.len() - $i.as_ptr() as usize
-        };
-        Ok(($i.slice(offset..), v))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpCapture)));
-        res
-      }
-    }
-  )
-);
-
-#[cfg(feature = "regexp_macros")]
-/// `re_bytes_captures_static!(regexp) => &[T] -> IResult<&[T], Vec<Vec<&[T]>>>`
-/// Returns all the capture groups. Regular expression calculated at compile time
-///
-/// requires the `regexp_macros` feature
-#[macro_export(local_inner_macros)]
-macro_rules! re_bytes_captures_static (
-  ($i:expr, $re:expr) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::{Err,error::ErrorKind,IResult};
-
-      use $crate::Slice;
-      regex_bytes!(RE, $re);
-      let v:Vec<Vec<_>> = RE.captures_iter(&$i)
-        .map(|c| c.iter().filter(|el| el.is_some()).map(|el| el.unwrap()).map(|m| $i.slice(m.start()..m.end())).collect()).collect();
-      if v.len() != 0 {
-        let offset = {
-          let end = v.last().unwrap().last().unwrap();
-          end.as_ptr() as usize + end.len() - $i.as_ptr() as usize
-        };
-        Ok(($i.slice(offset..), v))
-      } else {
-        let res: IResult<_,_> = Err(Err::Error(error_position!($i, ErrorKind::RegexpCapture)));
-        res
-      }
-    }
-  )
-);
-#[cfg(test)]
-mod tests {
-  #[cfg(feature = "alloc")]
-  use crate::lib::std::vec::Vec;
-  use crate::error::ErrorKind;
-  use crate::internal::Err;
-
-  #[test]
-  fn re_match() {
-    named!(rm<&str,&str>, re_match!(r"^\d{4}-\d{2}-\d{2}"));
-    assert_eq!(rm("2015-09-07"), Ok(("", "2015-09-07")));
-    assert_eq!(
-      rm("blah"),
-      Err(Err::Error(error_position!(
-        &"blah"[..],
-        ErrorKind::RegexpMatch
-      ),))
-    );
-    assert_eq!(rm("2015-09-07blah"), Ok(("", "2015-09-07blah")));
-  }
-
-  #[cfg(feature = "regexp_macros")]
-  #[test]
-  fn re_match_static() {
-    named!(rm<&str,&str>, re_match_static!(r"^\d{4}-\d{2}-\d{2}"));
-    assert_eq!(rm("2015-09-07"), Ok(("", "2015-09-07")));
-    assert_eq!(
-      rm("blah"),
-      Err(Err::Error(error_position!(
-        &"blah"[..],
-        ErrorKind::RegexpMatch
-      ),))
-    );
-    assert_eq!(rm("2015-09-07blah"), Ok(("", "2015-09-07blah")));
-  }
-
-  #[test]
-  fn re_find() {
-    named!(rm<&str,&str>, re_find!(r"^\d{4}-\d{2}-\d{2}"));
-    assert_eq!(rm("2015-09-07"), Ok(("", "2015-09-07")));
-    assert_eq!(
-      rm("blah"),
-      Err(Err::Error(error_position!(
-        &"blah"[..],
-        ErrorKind::RegexpFind
-      ),))
-    );
-    assert_eq!(rm("2015-09-07blah"), Ok(("blah", "2015-09-07")));
-  }
-
-  #[cfg(feature = "regexp_macros")]
-  #[test]
-  fn re_find_static() {
-    named!(rm<&str,&str>, re_find_static!(r"^\d{4}-\d{2}-\d{2}"));
-    assert_eq!(rm("2015-09-07"), Ok(("", "2015-09-07")));
-    assert_eq!(
-      rm("blah"),
-      Err(Err::Error(error_position!(
-        &"blah"[..],
-        ErrorKind::RegexpFind
-      ),))
-    );
-    assert_eq!(rm("2015-09-07blah"), Ok(("blah", "2015-09-07")));
-  }
-
-  #[cfg(feature = "alloc")]
-  #[test]
-  fn re_matches() {
-    named!(rm< &str,Vec<&str> >, re_matches!(r"\d{4}-\d{2}-\d{2}"));
-    assert_eq!(rm("2015-09-07"), Ok(("", vec!["2015-09-07"])));
-    assert_eq!(
-      rm("blah"),
-      Err(Err::Error(error_position!(
-        &"blah"[..],
-        ErrorKind::RegexpMatches
-      )))
-    );
-    assert_eq!(
-      rm("aaa2015-09-07blah2015-09-09pouet"),
-      Ok(("pouet", vec!["2015-09-07", "2015-09-09"]))
-    );
-  }
-
-  #[cfg(feature = "regexp_macros")]
-  #[cfg(feature = "alloc")]
-  #[test]
-  fn re_matches_static() {
-    named!(rm< &str,Vec<&str> >, re_matches_static!(r"\d{4}-\d{2}-\d{2}"));
-    assert_eq!(rm("2015-09-07"), Ok(("", vec!["2015-09-07"])));
-    assert_eq!(
-      rm("blah"),
-      Err(Err::Error(error_position!(
-        &"blah"[..],
-        ErrorKind::RegexpMatches
-      )))
-    );
-    assert_eq!(
-      rm("aaa2015-09-07blah2015-09-09pouet"),
-      Ok(("pouet", vec!["2015-09-07", "2015-09-09"]))
-    );
-  }
-
-  #[cfg(feature = "alloc")]
-  #[test]
-  fn re_capture() {
-    named!(rm< &str,Vec<&str> >, re_capture!(r"([[:alpha:]]+)\s+((\d+).(\d+).(\d+))"));
-    assert_eq!(
-      rm("blah nom 0.3.11pouet"),
-      Ok(("pouet", vec!["nom 0.3.11", "nom", "0.3.11", "0", "3", "11"]))
-    );
-    assert_eq!(
-      rm("blah"),
-      Err(Err::Error(error_position!(
-        &"blah"[..],
-        ErrorKind::RegexpCapture
-      )))
-    );
-    assert_eq!(
-      rm("hello nom 0.3.11 world regex 0.1.41"),
-      Ok((
-        " world regex 0.1.41",
-        vec!["nom 0.3.11", "nom", "0.3.11", "0", "3", "11"]
-      ))
-    );
-  }
-
-  #[cfg(feature = "alloc")]
-  #[cfg(feature = "regexp_macros")]
-  #[test]
-  fn re_capture_static() {
-    named!(rm< &str,Vec<&str> >, re_capture_static!(r"([[:alpha:]]+)\s+((\d+).(\d+).(\d+))"));
-    assert_eq!(
-      rm("blah nom 0.3.11pouet"),
-      Ok(("pouet", vec!["nom 0.3.11", "nom", "0.3.11", "0", "3", "11"]))
-    );
-    assert_eq!(
-      rm("blah"),
-      Err(Err::Error(error_position!(
-        &"blah"[..],
-        ErrorKind::RegexpCapture
-      )))
-    );
-    assert_eq!(
-      rm("hello nom 0.3.11 world regex 0.1.41"),
-      Ok((
-        " world regex 0.1.41",
-        vec!["nom 0.3.11", "nom", "0.3.11", "0", "3", "11"]
-      ))
-    );
-  }
-
-  #[cfg(feature = "alloc")]
-  #[test]
-  fn re_captures() {
-    named!(rm< &str,Vec<Vec<&str>> >, re_captures!(r"([[:alpha:]]+)\s+((\d+).(\d+).(\d+))"));
-    assert_eq!(
-      rm("blah nom 0.3.11pouet"),
-      Ok((
-        "pouet",
-        vec![vec!["nom 0.3.11", "nom", "0.3.11", "0", "3", "11"]]
-      ))
-    );
-    assert_eq!(
-      rm("blah"),
-      Err(Err::Error(error_position!(
-        &"blah"[..],
-        ErrorKind::RegexpCapture
-      )))
-    );
-    assert_eq!(
-      rm("hello nom 0.3.11 world regex 0.1.41 aaa"),
-      Ok((
-        " aaa",
-        vec![
-          vec!["nom 0.3.11", "nom", "0.3.11", "0", "3", "11"],
-          vec!["regex 0.1.41", "regex", "0.1.41", "0", "1", "41"],
-        ]
-      ))
-    );
-  }
-
-  #[cfg(feature = "alloc")]
-  #[cfg(feature = "regexp_macros")]
-  #[test]
-  fn re_captures_static() {
-    named!(rm< &str,Vec<Vec<&str>> >, re_captures_static!(r"([[:alpha:]]+)\s+((\d+).(\d+).(\d+))"));
-    assert_eq!(
-      rm("blah nom 0.3.11pouet"),
-      Ok((
-        "pouet",
-        vec![vec!["nom 0.3.11", "nom", "0.3.11", "0", "3", "11"]]
-      ))
-    );
-    assert_eq!(
-      rm("blah"),
-      Err(Err::Error(error_position!(
-        &"blah"[..],
-        ErrorKind::RegexpCapture
-      )))
-    );
-    assert_eq!(
-      rm("hello nom 0.3.11 world regex 0.1.41 aaa"),
-      Ok((
-        " aaa",
-        vec![
-          vec!["nom 0.3.11", "nom", "0.3.11", "0", "3", "11"],
-          vec!["regex 0.1.41", "regex", "0.1.41", "0", "1", "41"],
-        ]
-      ))
-    );
-  }
-
-  #[test]
-  fn re_bytes_match() {
-    named!(rm, re_bytes_match!(r"^\d{4}-\d{2}-\d{2}"));
-    assert_eq!(rm(&b"2015-09-07"[..]), Ok((&b""[..], &b"2015-09-07"[..])));
-    assert_eq!(
-      rm(&b"blah"[..]),
-      Err(Err::Error(error_position!(
-        &b"blah"[..],
-        ErrorKind::RegexpMatch
-      )))
-    );
-    assert_eq!(
-      rm(&b"2015-09-07blah"[..]),
-      Ok((&b""[..], &b"2015-09-07blah"[..]))
-    );
-  }
-
-  #[cfg(feature = "regexp_macros")]
-  #[test]
-  fn re_bytes_match_static() {
-    named!(rm, re_bytes_match_static!(r"^\d{4}-\d{2}-\d{2}"));
-    assert_eq!(rm(&b"2015-09-07"[..]), Ok((&b""[..], &b"2015-09-07"[..])));
-    assert_eq!(
-      rm(&b"blah"[..]),
-      Err(Err::Error(error_position!(
-        &b"blah"[..],
-        ErrorKind::RegexpMatch
-      )))
-    );
-    assert_eq!(
-      rm(&b"2015-09-07blah"[..]),
-      Ok((&b""[..], &b"2015-09-07blah"[..]))
-    );
-  }
-
-  #[test]
-  fn re_bytes_find() {
-    named!(rm, re_bytes_find!(r"^\d{4}-\d{2}-\d{2}"));
-    assert_eq!(rm(&b"2015-09-07"[..]), Ok((&b""[..], &b"2015-09-07"[..])));
-    assert_eq!(
-      rm(&b"blah"[..]),
-      Err(Err::Error(error_position!(
-        &b"blah"[..],
-        ErrorKind::RegexpFind
-      )))
-    );
-    assert_eq!(
-      rm(&b"2015-09-07blah"[..]),
-      Ok((&b"blah"[..], &b"2015-09-07"[..]))
-    );
-  }
-
-  #[cfg(feature = "regexp_macros")]
-  #[test]
-  fn re_bytes_find_static() {
-    named!(rm, re_bytes_find_static!(r"^\d{4}-\d{2}-\d{2}"));
-    assert_eq!(rm(&b"2015-09-07"[..]), Ok((&b""[..], &b"2015-09-07"[..])));
-    assert_eq!(
-      rm(&b"blah"[..]),
-      Err(Err::Error(error_position!(
-        &b"blah"[..],
-        ErrorKind::RegexpFind
-      )))
-    );
-    assert_eq!(
-      rm(&b"2015-09-07blah"[..]),
-      Ok((&b"blah"[..], &b"2015-09-07"[..]))
-    );
-  }
-
-  #[cfg(feature = "alloc")]
-  #[test]
-  fn re_bytes_matches() {
-    named!(rm<Vec<&[u8]>>, re_bytes_matches!(r"\d{4}-\d{2}-\d{2}"));
-    assert_eq!(
-      rm(&b"2015-09-07"[..]),
-      Ok((&b""[..], vec![&b"2015-09-07"[..]]))
-    );
-    assert_eq!(
-      rm(&b"blah"[..]),
-      Err(Err::Error(error_position!(
-        &b"blah"[..],
-        ErrorKind::RegexpMatches
-      )))
-    );
-    assert_eq!(
-      rm(&b"aaa2015-09-07blah2015-09-09pouet"[..]),
-      Ok((&b"pouet"[..], vec![&b"2015-09-07"[..], &b"2015-09-09"[..]]))
-    );
-  }
-
-  #[cfg(feature = "alloc")]
-  #[cfg(feature = "regexp_macros")]
-  #[test]
-  fn re_bytes_matches_static() {
-    named!(
-      rm<Vec<&[u8]>>,
-      re_bytes_matches_static!(r"\d{4}-\d{2}-\d{2}")
-    );
-    assert_eq!(
-      rm(&b"2015-09-07"[..]),
-      Ok((&b""[..], vec![&b"2015-09-07"[..]]))
-    );
-    assert_eq!(
-      rm(&b"blah"[..]),
-      Err(Err::Error(error_position!(
-        &b"blah"[..],
-        ErrorKind::RegexpMatches
-      )))
-    );
-    assert_eq!(
-      rm(&b"aaa2015-09-07blah2015-09-09pouet"[..]),
-      Ok((&b"pouet"[..], vec![&b"2015-09-07"[..], &b"2015-09-09"[..]]))
-    );
-  }
-
-  #[cfg(feature = "alloc")]
-  #[test]
-  fn re_bytes_capture() {
-    named!(
-      rm<Vec<&[u8]>>,
-      re_bytes_capture!(r"([[:alpha:]]+)\s+((\d+).(\d+).(\d+))")
-    );
-    assert_eq!(
-      rm(&b"blah nom 0.3.11pouet"[..]),
-      Ok((
-        &b"pouet"[..],
-        vec![
-          &b"nom 0.3.11"[..],
-          &b"nom"[..],
-          &b"0.3.11"[..],
-          &b"0"[..],
-          &b"3"[..],
-          &b"11"[..],
-        ]
-      ))
-    );
-    assert_eq!(
-      rm(&b"blah"[..]),
-      Err(Err::Error(error_position!(
-        &b"blah"[..],
-        ErrorKind::RegexpCapture
-      )))
-    );
-    assert_eq!(
-      rm(&b"hello nom 0.3.11 world regex 0.1.41"[..]),
-      Ok((
-        &b" world regex 0.1.41"[..],
-        vec![
-          &b"nom 0.3.11"[..],
-          &b"nom"[..],
-          &b"0.3.11"[..],
-          &b"0"[..],
-          &b"3"[..],
-          &b"11"[..],
-        ]
-      ))
-    );
-  }
-
-  #[cfg(feature = "alloc")]
-  #[cfg(feature = "regexp_macros")]
-  #[test]
-  fn re_bytes_capture_static() {
-    named!(
-      rm<Vec<&[u8]>>,
-      re_bytes_capture_static!(r"([[:alpha:]]+)\s+((\d+).(\d+).(\d+))")
-    );
-    assert_eq!(
-      rm(&b"blah nom 0.3.11pouet"[..]),
-      Ok((
-        &b"pouet"[..],
-        vec![
-          &b"nom 0.3.11"[..],
-          &b"nom"[..],
-          &b"0.3.11"[..],
-          &b"0"[..],
-          &b"3"[..],
-          &b"11"[..],
-        ]
-      ))
-    );
-    assert_eq!(
-      rm(&b"blah"[..]),
-      Err(Err::Error(error_position!(
-        &b"blah"[..],
-        ErrorKind::RegexpCapture
-      )))
-    );
-    assert_eq!(
-      rm(&b"hello nom 0.3.11 world regex 0.1.41"[..]),
-      Ok((
-        &b" world regex 0.1.41"[..],
-        vec![
-          &b"nom 0.3.11"[..],
-          &b"nom"[..],
-          &b"0.3.11"[..],
-          &b"0"[..],
-          &b"3"[..],
-          &b"11"[..],
-        ]
-      ))
-    );
-  }
-
-  #[cfg(feature = "alloc")]
-  #[test]
-  fn re_bytes_captures() {
-    named!(
-      rm<Vec<Vec<&[u8]>>>,
-      re_bytes_captures!(r"([[:alpha:]]+)\s+((\d+).(\d+).(\d+))")
-    );
-    assert_eq!(
-      rm(&b"blah nom 0.3.11pouet"[..]),
-      Ok((
-        &b"pouet"[..],
-        vec![
-          vec![
-            &b"nom 0.3.11"[..],
-            &b"nom"[..],
-            &b"0.3.11"[..],
-            &b"0"[..],
-            &b"3"[..],
-            &b"11"[..],
-          ],
-        ]
-      ))
-    );
-    assert_eq!(
-      rm(&b"blah"[..]),
-      Err(Err::Error(error_position!(
-        &b"blah"[..],
-        ErrorKind::RegexpCapture
-      )))
-    );
-    assert_eq!(
-      rm(&b"hello nom 0.3.11 world regex 0.1.41 aaa"[..]),
-      Ok((
-        &b" aaa"[..],
-        vec![
-          vec![
-            &b"nom 0.3.11"[..],
-            &b"nom"[..],
-            &b"0.3.11"[..],
-            &b"0"[..],
-            &b"3"[..],
-            &b"11"[..],
-          ],
-          vec![
-            &b"regex 0.1.41"[..],
-            &b"regex"[..],
-            &b"0.1.41"[..],
-            &b"0"[..],
-            &b"1"[..],
-            &b"41"[..],
-          ],
-        ]
-      ))
-    );
-  }
-
-  #[cfg(feature = "alloc")]
-  #[cfg(feature = "regexp_macros")]
-  #[test]
-  fn re_bytes_captures_static() {
-    named!(
-      rm<Vec<Vec<&[u8]>>>,
-      re_bytes_captures_static!(r"([[:alpha:]]+)\s+((\d+).(\d+).(\d+))")
-    );
-    assert_eq!(
-      rm(&b"blah nom 0.3.11pouet"[..]),
-      Ok((
-        &b"pouet"[..],
-        vec![
-          vec![
-            &b"nom 0.3.11"[..],
-            &b"nom"[..],
-            &b"0.3.11"[..],
-            &b"0"[..],
-            &b"3"[..],
-            &b"11"[..],
-          ],
-        ]
-      ))
-    );
-    assert_eq!(
-      rm(&b"blah"[..]),
-      Err(Err::Error(error_position!(
-        &b"blah"[..],
-        ErrorKind::RegexpCapture
-      )))
-    );
-    assert_eq!(
-      rm(&b"hello nom 0.3.11 world regex 0.1.41 aaa"[..]),
-      Ok((
-        &b" aaa"[..],
-        vec![
-          vec![
-            &b"nom 0.3.11"[..],
-            &b"nom"[..],
-            &b"0.3.11"[..],
-            &b"0"[..],
-            &b"3"[..],
-            &b"11"[..],
-          ],
-          vec![
-            &b"regex 0.1.41"[..],
-            &b"regex"[..],
-            &b"0.1.41"[..],
-            &b"0"[..],
-            &b"1"[..],
-            &b"41"[..],
-          ],
-        ]
-      ))
-    );
-  }
-}
diff --git a/src/sequence/macros.rs b/src/sequence/macros.rs
deleted file mode 100644
index a5a3351..0000000
--- a/src/sequence/macros.rs
+++ /dev/null
@@ -1,860 +0,0 @@
-/// `tuple!(I->IResult<I,A>, I->IResult<I,B>, ... I->IResult<I,X>) => I -> IResult<I, (A, B, ..., X)>`
-/// chains parsers and assemble the sub results in a tuple.
-///
-/// The input type `I` must implement `nom::InputLength`.
-///
-/// This combinator will count how much data is consumed by every child parser
-/// and take it into account if there is not enough data
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::error::ErrorKind;
-/// # use nom::number::streaming::be_u16;
-/// // the return type depends of the children parsers
-/// named!(parser<&[u8], (u16, &[u8], &[u8]) >,
-///   tuple!(
-///     be_u16 ,
-///     take!(3),
-///     tag!("fg")
-///   )
-/// );
-///
-/// # fn main() {
-/// assert_eq!(
-///   parser(&b"abcdefgh"[..]),
-///   Ok((
-///     &b"h"[..],
-///     (0x6162u16, &b"cde"[..], &b"fg"[..])
-///   ))
-/// );
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! tuple (
-  ($i:expr, $($rest:tt)*) => (
-    {
-      tuple_parser!($i, (), $($rest)*)
-    }
-  );
-);
-
-/// Internal parser, do not use directly
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! tuple_parser (
-  ($i:expr, ($($parsed:tt),*), $e:path, $($rest:tt)*) => (
-    tuple_parser!($i, ($($parsed),*), call!($e), $($rest)*);
-  );
-  ($i:expr, (), $submac:ident!( $($args:tt)* ), $($rest:tt)*) => (
-    {
-      let i_ = $i.clone();
-
-      ( $submac!(i_, $($args)*) ).and_then(|(i,o)| {
-        let i_ = i.clone();
-        tuple_parser!(i_, (o), $($rest)*)
-      })
-    }
-  );
-  ($i:expr, ($($parsed:tt)*), $submac:ident!( $($args:tt)* ), $($rest:tt)*) => (
-    {
-      let i_ = $i.clone();
-
-      ( $submac!(i_, $($args)*) ).and_then(|(i,o)| {
-        let i_ = i.clone();
-        tuple_parser!(i_, ($($parsed)* , o), $($rest)*)
-      })
-    }
-  );
-  ($i:expr, ($($parsed:tt),*), $e:path) => (
-    tuple_parser!($i, ($($parsed),*), call!($e));
-  );
-  ($i:expr, (), $submac:ident!( $($args:tt)* )) => (
-    {
-      let i_ = $i.clone();
-      ( $submac!(i_, $($args)*) ).map(|(i,o)| (i, (o)))
-    }
-  );
-  ($i:expr, ($($parsed:expr),*), $submac:ident!( $($args:tt)* )) => (
-    {
-      let i_ = $i.clone();
-      ( $submac!(i_, $($args)*) ).map(|(i,o)| (i, ($($parsed),* , o)))
-    }
-  );
-  ($i:expr, ($($parsed:expr),*)) => (
-    {
-      $crate::lib::std::result::Result::Ok(($i, ($($parsed),*)))
-    }
-  );
-);
-
-/// `pair!(I -> IResult<I,O>, I -> IResult<I,P>) => I -> IResult<I, (O,P)>`
-/// pair returns a tuple of the results of its two child parsers of both succeed
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # use nom::character::complete::{alpha1, digit1};
-/// named!(parser<&str, (&str, &str)>, pair!(alpha1, digit1));
-///
-/// # fn main() {
-/// assert_eq!(parser("abc123"), Ok(("", ("abc", "123"))));
-/// assert_eq!(parser("123abc"), Err(Err::Error(("123abc", ErrorKind::Alpha))));
-/// assert_eq!(parser("abc;123"), Err(Err::Error((";123", ErrorKind::Digit))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! pair(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    pair!($i, |i| $submac!(i, $($args)*), |i| $submac2!(i, $($args2)*))
-  );
-
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    pair!($i, |i| $submac!(i, $($args)*), $g);
-  );
-
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    pair!($i, $f, |i| $submac!(i, $($args)*));
-  );
-
-  ($i:expr, $f:expr, $g:expr) => (
-    $crate::sequence::pairc($i, $f, $g)
-  );
-);
-
-/// `separated_pair!(I -> IResult<I,O>, I -> IResult<I, T>, I -> IResult<I,P>) => I -> IResult<I, (O,P)>`
-/// separated_pair(X,sep,Y) returns a tuple of its first and third child parsers
-/// if all 3 succeed
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # use nom::character::complete::{alpha1, digit1};
-/// named!(parser<&str, (&str, &str)>, separated_pair!(alpha1, char!(','), digit1));
-///
-/// # fn main() {
-/// assert_eq!(parser("abc,123"), Ok(("", ("abc", "123"))));
-/// assert_eq!(parser("123,abc"), Err(Err::Error(("123,abc", ErrorKind::Alpha))));
-/// assert_eq!(parser("abc;123"), Err(Err::Error((";123", ErrorKind::Char))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! separated_pair(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $($rest:tt)*) => (
-    separated_pair!($i, |i| $submac!(i, $($args)*), $($rest)*)
-  );
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* ), $($rest:tt)*) => (
-    separated_pair!($i, $f, |i| $submac!(i, $($args)*), $($rest)*)
-  );
-  ($i:expr, $f:expr, $g:expr, $submac:ident!( $($args:tt)* )) => (
-    separated_pair!($i, $f, $g, |i| $submac!(i, $($args)*))
-  );
-  ($i:expr, $f:expr, $g:expr, $h:expr) => (
-    $crate::sequence::separated_pairc($i, $f, $g, $h)
-  );
-);
-
-/// `preceded!(I -> IResult<I,T>, I -> IResult<I,O>) => I -> IResult<I, O>`
-/// preceded returns the result of its second parser if both succeed
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # use nom::character::complete::{alpha1};
-/// named!(parser<&str, &str>, preceded!(char!('-'), alpha1));
-///
-/// # fn main() {
-/// assert_eq!(parser("-abc"), Ok(("", "abc")));
-/// assert_eq!(parser("abc"), Err(Err::Error(("abc", ErrorKind::Char))));
-/// assert_eq!(parser("-123"), Err(Err::Error(("123", ErrorKind::Alpha))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! preceded(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    preceded!($i, |i| $submac!(i, $($args)*), |i| $submac2!(i, $($args2)*))
-  );
-
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    preceded!($i, |i| $submac!(i, $($args)*), $g);
-  );
-
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    preceded!($i, $f, |i| $submac!(i, $($args)*));
-  );
-
-  ($i:expr, $f:expr, $g:expr) => (
-    $crate::sequence::precededc($i, $f, $g)
-  );
-);
-
-/// `terminated!(I -> IResult<I,O>, I -> IResult<I,T>) => I -> IResult<I, O>`
-/// terminated returns the result of its first parser if both succeed
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::Err;
-/// # use nom::error::ErrorKind;
-/// # use nom::character::complete::{alpha1};
-/// named!(parser<&str, &str>, terminated!(alpha1, char!(';')));
-///
-/// # fn main() {
-/// assert_eq!(parser("abc;"), Ok(("", "abc")));
-/// assert_eq!(parser("abc,"), Err(Err::Error((",", ErrorKind::Char))));
-/// assert_eq!(parser("123;"), Err(Err::Error(("123;", ErrorKind::Alpha))));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! terminated(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    terminated!($i, |i| $submac!(i, $($args)*), |i| $submac2!(i, $($args2)*))
-  );
-
-  ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    terminated!($i, |i| $submac!(i, $($args)*), $g);
-  );
-
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    terminated!($i, $f, |i| $submac!(i, $($args)*));
-  );
-
-  ($i:expr, $f:expr, $g:expr) => (
-    $crate::sequence::terminatedc($i, $f, $g)
-  );
-);
-
-/// `delimited!(I -> IResult<I,T>, I -> IResult<I,O>, I -> IResult<I,U>) => I -> IResult<I, O>`
-/// delimited(opening, X, closing) returns X
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::character::complete::{alpha1};
-/// named!(parens,
-///     delimited!(
-///         tag!("("),
-///         alpha1,
-///         tag!(")")
-///     )
-/// );
-///
-/// # fn main() {
-/// let input = &b"(test)"[..];
-/// assert_eq!(parens(input), Ok((&b""[..], &b"test"[..])));
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! delimited(
-  ($i:expr, $submac:ident!( $($args:tt)* ), $($rest:tt)*) => (
-    delimited!($i, |i| $submac!(i, $($args)*), $($rest)*)
-  );
-  ($i:expr, $f:expr, $submac:ident!( $($args:tt)* ), $($rest:tt)*) => (
-    delimited!($i, $f, |i| $submac!(i, $($args)*), $($rest)*)
-  );
-  ($i:expr, $f:expr, $g:expr, $submac:ident!( $($args:tt)* )) => (
-    delimited!($i, $f, $g, |i| $submac!(i, $($args)*))
-  );
-  ($i:expr, $f:expr, $g:expr, $h:expr) => (
-    $crate::sequence::delimitedc($i, $f, $g, $h)
-  );
-);
-
-/// `do_parse!(I->IResult<I,A> >> I->IResult<I,B> >> ... I->IResult<I,X> , ( O ) ) => I -> IResult<I, O>`
-/// do_parse applies sub parsers in a sequence.
-/// it can store intermediary results and make them available
-/// for later parsers
-///
-/// The input type `I` must implement `nom::InputLength`.
-///
-/// This combinator will count how much data is consumed by every child parser
-/// and take it into account if there is not enough data
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # use nom::{Err,Needed};
-/// use nom::number::streaming::be_u8;
-///
-/// // this parser implements a common pattern in binary formats,
-/// // the TAG-LENGTH-VALUE, where you first recognize a specific
-/// // byte slice, then the next bytes indicate the length of
-/// // the data, then you take that slice and return it
-/// //
-/// // here, we match the tag 42, take the length in the next byte
-/// // and store it in `length`, then use `take!` with `length`
-/// // to obtain the subslice that we store in `bytes`, then return
-/// // `bytes`
-/// // you can use other macro combinators inside do_parse (like the `tag`
-/// // one here), or a function (like `be_u8` here), but you cannot use a
-/// // module path (like `nom::be_u8`) there, because of limitations in macros
-/// named!(tag_length_value,
-///   do_parse!(
-///     tag!( &[ 42u8 ][..] ) >>
-///     length: be_u8         >>
-///     bytes:  take!(length) >>
-///     (bytes)
-///   )
-/// );
-///
-/// # fn main() {
-/// let a: Vec<u8>        = vec!(42, 2, 3, 4, 5);
-/// let result_a: Vec<u8> = vec!(3, 4);
-/// let rest_a: Vec<u8>   = vec!(5);
-/// assert_eq!(tag_length_value(&a[..]), Ok((&rest_a[..], &result_a[..])));
-///
-/// // here, the length is 5, but there are only 3 bytes afterwards (3, 4 and 5),
-/// // so the parser will tell you that you need 7 bytes: one for the tag,
-/// // one for the length, then 5 bytes
-/// let b: Vec<u8>     = vec!(42, 5, 3, 4, 5);
-/// assert_eq!(tag_length_value(&b[..]), Err(Err::Incomplete(Needed::Size(5))));
-/// # }
-/// ```
-///
-/// the result is a tuple, so you can return multiple sub results, like
-/// this:
-/// `do_parse!(I->IResult<I,A> >> I->IResult<I,B> >> ... I->IResult<I,X> , ( O, P ) ) => I -> IResult<I, (O,P)>`
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// use nom::number::streaming::be_u8;
-/// named!(tag_length_value<(u8, &[u8])>,
-///   do_parse!(
-///     tag!( &[ 42u8 ][..] ) >>
-///     length: be_u8         >>
-///     bytes:  take!(length) >>
-///     (length, bytes)
-///   )
-/// );
-///
-/// # fn main() {
-/// # }
-/// ```
-///
-#[macro_export(local_inner_macros)]
-macro_rules! do_parse (
-  (__impl $i:expr, ( $($rest:expr),* )) => (
-    $crate::lib::std::result::Result::Ok(($i, ( $($rest),* )))
-  );
-
-  (__impl $i:expr, $field:ident : $submac:ident!( $($args:tt)* ) ) => (
-    do_parse!(__impl $i, $submac!( $($args)* ))
-  );
-
-  (__impl $i:expr, $submac:ident!( $($args:tt)* ) ) => (
-    nom_compile_error!("do_parse is missing the return value. A do_parse call must end
-      with a return value between parenthesis, as follows:
-
-      do_parse!(
-        a: tag!(\"abcd\") >>
-        b: tag!(\"efgh\") >>
-
-        ( Value { a: a, b: b } )
-    ");
-  );
-
-  (__impl $i:expr, $field:ident : $submac:ident!( $($args:tt)* ) ~ $($rest:tt)* ) => (
-    nom_compile_error!("do_parse uses >> as separator, not ~");
-  );
-  (__impl $i:expr, $submac:ident!( $($args:tt)* ) ~ $($rest:tt)* ) => (
-    nom_compile_error!("do_parse uses >> as separator, not ~");
-  );
-  (__impl $i:expr, $field:ident : $e:ident ~ $($rest:tt)*) => (
-    do_parse!(__impl $i, $field: call!($e) ~ $($rest)*);
-  );
-  (__impl $i:expr, $e:ident ~ $($rest:tt)*) => (
-    do_parse!(__impl $i, call!($e) ~ $($rest)*);
-  );
-
-  (__impl $i:expr, $e:ident >> $($rest:tt)*) => (
-    do_parse!(__impl $i, call!($e) >> $($rest)*);
-  );
-  (__impl $i:expr, $submac:ident!( $($args:tt)* ) >> $($rest:tt)*) => (
-    {
-      use $crate::lib::std::result::Result::*;
-
-      let i_ = $i.clone();
-      match $submac!(i_, $($args)*) {
-        Err(e) => Err(e),
-        Ok((i,_))     => {
-          let i_ = i.clone();
-          do_parse!(__impl i_, $($rest)*)
-        },
-      }
-    }
-  );
-
-  (__impl $i:expr, $field:ident : $e:ident >> $($rest:tt)*) => (
-    do_parse!(__impl $i, $field: call!($e) >> $($rest)*);
-  );
-
-  (__impl $i:expr, $field:ident : $submac:ident!( $($args:tt)* ) >> $($rest:tt)*) => (
-    {
-      use $crate::lib::std::result::Result::*;
-
-      let i_ = $i.clone();
-      match  $submac!(i_, $($args)*) {
-        Err(e) => Err(e),
-        Ok((i,o))     => {
-          let $field = o;
-          let i_ = i.clone();
-          do_parse!(__impl i_, $($rest)*)
-        },
-      }
-    }
-  );
-
-  // ending the chain
-  (__impl $i:expr, $e:ident >> ( $($rest:tt)* )) => (
-    do_parse!(__impl $i, call!($e) >> ( $($rest)* ));
-  );
-
-  (__impl $i:expr, $submac:ident!( $($args:tt)* ) >> ( $($rest:tt)* )) => ({
-    use $crate::lib::std::result::Result::*;
-
-    match $submac!($i, $($args)*) {
-      Err(e) => Err(e),
-      Ok((i,_))     => {
-        do_parse!(__finalize i, $($rest)*)
-      },
-    }
-  });
-
-  (__impl $i:expr, $field:ident : $e:ident >> ( $($rest:tt)* )) => (
-    do_parse!(__impl $i, $field: call!($e) >> ( $($rest)* ) );
-  );
-
-  (__impl $i:expr, $field:ident : $submac:ident!( $($args:tt)* ) >> ( $($rest:tt)* )) => ({
-    use $crate::lib::std::result::Result::*;
-
-    match $submac!($i, $($args)*) {
-      Err(e) => Err(e),
-      Ok((i,o))     => {
-        let $field = o;
-        do_parse!(__finalize i, $($rest)*)
-      },
-    }
-  });
-
-  (__finalize $i:expr, ( $o: expr )) => ({
-    use $crate::lib::std::result::Result::Ok;
-    Ok(($i, $o))
-  });
-
-  (__finalize $i:expr, ( $($rest:tt)* )) => ({
-    use $crate::lib::std::result::Result::Ok;
-    Ok(($i, ( $($rest)* )))
-  });
-
-  ($i:expr, $($rest:tt)*) => (
-    {
-      do_parse!(__impl $i, $($rest)*)
-    }
-  );
-  ($submac:ident!( $($args:tt)* ) >> $($rest:tt)* ) => (
-    nom_compile_error!("if you are using do_parse outside of a named! macro, you must
-        pass the input data as first argument, like this:
-
-        let res = do_parse!(input,
-          a: tag!(\"abcd\") >>
-          b: tag!(\"efgh\") >>
-          ( Value { a: a, b: b } )
-        );");
-  );
-  ($e:ident! >> $($rest:tt)* ) => (
-    do_parse!( call!($e) >> $($rest)*);
-  );
-);
-
-#[doc(hidden)]
-#[macro_export]
-macro_rules! nom_compile_error (
-  (( $($args:tt)* )) => ( compile_error!($($args)*) );
-);
-
-#[cfg(test)]
-mod tests {
-  use crate::internal::{Err, IResult, Needed};
-  use crate::number::streaming::be_u16;
-  use crate::error::ErrorKind;
-
-  // reproduce the tag and take macros, because of module import order
-  macro_rules! tag (
-    ($i:expr, $inp: expr) => (
-      {
-        #[inline(always)]
-        fn as_bytes<T: $crate::AsBytes>(b: &T) -> &[u8] {
-          b.as_bytes()
-        }
-
-        let expected = $inp;
-        let bytes    = as_bytes(&expected);
-
-        tag_bytes!($i,bytes)
-      }
-    );
-  );
-
-  macro_rules! tag_bytes (
-    ($i:expr, $bytes: expr) => (
-      {
-        use $crate::lib::std::cmp::min;
-
-        let len = $i.len();
-        let blen = $bytes.len();
-        let m   = min(len, blen);
-        let reduced = &$i[..m];
-        let b       = &$bytes[..m];
-
-        let res: IResult<_,_,_> = if reduced != b {
-          Err($crate::Err::Error(error_position!($i, $crate::error::ErrorKind::Tag)))
-        } else if m < blen {
-          Err($crate::Err::Incomplete(Needed::Size(blen)))
-        } else {
-          Ok((&$i[blen..], reduced))
-        };
-        res
-      }
-    );
-  );
-
-  macro_rules! take (
-    ($i:expr, $count:expr) => (
-      {
-        let cnt = $count as usize;
-        let res:IResult<&[u8],&[u8],_> = if $i.len() < cnt {
-          Err($crate::Err::Incomplete(Needed::Size(cnt)))
-        } else {
-          Ok((&$i[cnt..],&$i[0..cnt]))
-        };
-        res
-      }
-    );
-  );
-
-  #[derive(PartialEq, Eq, Debug)]
-  struct B {
-    a: u8,
-    b: u8,
-  }
-
-  #[derive(PartialEq, Eq, Debug)]
-  struct C {
-    a: u8,
-    b: Option<u8>,
-  }
-
-  /*FIXME: convert code examples to new error management
-  use util::{add_error_pattern, error_to_list, print_error};
-
-  #[cfg(feature = "std")]
-  #[cfg_attr(rustfmt, rustfmt_skip)]
-  fn error_to_string<P: Clone + PartialEq>(e: &Context<P, u32>) -> &'static str {
-    let v: Vec<(P, ErrorKind<u32>)> = error_to_list(e);
-    // do it this way if you can use slice patterns
-    //match &v[..] {
-    //  [ErrorKind::Custom(42), ErrorKind::Tag]                         => "missing `ijkl` tag",
-    //  [ErrorKind::Custom(42), ErrorKind::Custom(128), ErrorKind::Tag] => "missing `mnop` tag after `ijkl`",
-    //  _            => "unrecognized error"
-    //}
-
-    let collected: Vec<ErrorKind<u32>> = v.iter().map(|&(_, ref e)| e.clone()).collect();
-    if &collected[..] == [ErrorKind::Custom(42), ErrorKind::Tag] {
-      "missing `ijkl` tag"
-    } else if &collected[..] == [ErrorKind::Custom(42), ErrorKind::Custom(128), ErrorKind::Tag] {
-      "missing `mnop` tag after `ijkl`"
-    } else {
-      "unrecognized error"
-    }
-  }
-
-  // do it this way if you can use box patterns
-  //use $crate::lib::std::str;
-  //fn error_to_string(e:Err) -> String
-  //  match e {
-  //    NodePosition(ErrorKind::Custom(42), i1, box Position(ErrorKind::Tag, i2)) => {
-  //      format!("missing `ijkl` tag, found '{}' instead", str::from_utf8(i2).unwrap())
-  //    },
-  //    NodePosition(ErrorKind::Custom(42), i1, box NodePosition(ErrorKind::Custom(128), i2,  box Position(ErrorKind::Tag, i3))) => {
-  //      format!("missing `mnop` tag after `ijkl`, found '{}' instead", str::from_utf8(i3).unwrap())
-  //    },
-  //    _ => "unrecognized error".to_string()
-  //  }
-  //}
-  */
-
-  #[cfg_attr(rustfmt, rustfmt_skip)]
-  #[allow(unused_variables)]
-  #[test]
-  fn add_err() {
-    named!(err_test,
-      preceded!(
-        tag!("efgh"),
-        add_return_error!(
-          //ErrorKind::Custom(42u32),
-          ErrorKind::Char,
-          do_parse!(
-                 tag!("ijkl")                                     >>
-            //res: add_return_error!(ErrorKind::Custom(128u32), tag!("mnop")) >>
-            res: add_return_error!(ErrorKind::Eof, tag!("mnop")) >>
-            (res)
-          )
-        )
-      )
-    );
-    let a = &b"efghblah"[..];
-    let b = &b"efghijklblah"[..];
-    let c = &b"efghijklmnop"[..];
-
-    let blah = &b"blah"[..];
-
-    let res_a = err_test(a);
-    let res_b = err_test(b);
-    let res_c = err_test(c);
-    assert_eq!(res_a,
-               Err(Err::Error(error_node_position!(blah,
-                                                   //ErrorKind::Custom(42u32),
-                                                   ErrorKind::Eof,
-                                                   error_position!(blah, ErrorKind::Tag)))));
-    //assert_eq!(res_b, Err(Err::Error(error_node_position!(&b"ijklblah"[..], ErrorKind::Custom(42u32),
-    //  error_node_position!(blah, ErrorKind::Custom(128u32), error_position!(blah, ErrorKind::Tag))))));
-    assert_eq!(res_b, Err(Err::Error(error_node_position!(&b"ijklblah"[..], ErrorKind::Eof,
-      error_node_position!(blah, ErrorKind::Eof, error_position!(blah, ErrorKind::Tag))))));
-    assert_eq!(res_c, Ok((&b""[..], &b"mnop"[..])));
-  }
-
-  #[cfg_attr(rustfmt, rustfmt_skip)]
-  #[test]
-  fn complete() {
-    named!(err_test,
-      do_parse!(
-             tag!("ijkl")            >>
-        res: complete!(tag!("mnop")) >>
-        (res)
-      )
-    );
-    let a = &b"ijklmn"[..];
-
-    let res_a = err_test(a);
-    assert_eq!(res_a,
-               Err(Err::Error(error_position!(&b"mn"[..], ErrorKind::Complete))));
-  }
-
-  #[test]
-  fn pair() {
-    named!(tag_abc, tag!("abc"));
-    named!(tag_def, tag!("def"));
-    named!( pair_abc_def<&[u8],(&[u8], &[u8])>, pair!(tag_abc, tag_def) );
-
-    assert_eq!(pair_abc_def(&b"abcdefghijkl"[..]), Ok((&b"ghijkl"[..], (&b"abc"[..], &b"def"[..]))));
-    assert_eq!(pair_abc_def(&b"ab"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(pair_abc_def(&b"abcd"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(
-      pair_abc_def(&b"xxx"[..]),
-      Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
-    );
-    assert_eq!(
-      pair_abc_def(&b"xxxdef"[..]),
-      Err(Err::Error(error_position!(&b"xxxdef"[..], ErrorKind::Tag)))
-    );
-    assert_eq!(
-      pair_abc_def(&b"abcxxx"[..]),
-      Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
-    );
-  }
-
-  #[test]
-  fn separated_pair() {
-    named!(tag_abc, tag!("abc"));
-    named!(tag_def, tag!("def"));
-    named!(tag_separator, tag!(","));
-    named!( sep_pair_abc_def<&[u8],(&[u8], &[u8])>, separated_pair!(tag_abc, tag_separator, tag_def) );
-
-    assert_eq!(
-      sep_pair_abc_def(&b"abc,defghijkl"[..]),
-      Ok((&b"ghijkl"[..], (&b"abc"[..], &b"def"[..])))
-    );
-    assert_eq!(sep_pair_abc_def(&b"ab"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(sep_pair_abc_def(&b"abc,d"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(
-      sep_pair_abc_def(&b"xxx"[..]),
-      Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
-    );
-    assert_eq!(
-      sep_pair_abc_def(&b"xxx,def"[..]),
-      Err(Err::Error(error_position!(&b"xxx,def"[..], ErrorKind::Tag)))
-    );
-    assert_eq!(
-      sep_pair_abc_def(&b"abc,xxx"[..]),
-      Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
-    );
-  }
-
-  #[test]
-  fn preceded() {
-    named!(tag_abcd, tag!("abcd"));
-    named!(tag_efgh, tag!("efgh"));
-    named!( preceded_abcd_efgh<&[u8], &[u8]>, preceded!(tag_abcd, tag_efgh) );
-
-    assert_eq!(preceded_abcd_efgh(&b"abcdefghijkl"[..]), Ok((&b"ijkl"[..], &b"efgh"[..])));
-    assert_eq!(preceded_abcd_efgh(&b"ab"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(preceded_abcd_efgh(&b"abcde"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(
-      preceded_abcd_efgh(&b"xxx"[..]),
-      Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
-    );
-    assert_eq!(
-      preceded_abcd_efgh(&b"xxxxdef"[..]),
-      Err(Err::Error(error_position!(&b"xxxxdef"[..], ErrorKind::Tag)))
-    );
-    assert_eq!(
-      preceded_abcd_efgh(&b"abcdxxx"[..]),
-      Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
-    );
-  }
-
-  #[test]
-  fn terminated() {
-    named!(tag_abcd, tag!("abcd"));
-    named!(tag_efgh, tag!("efgh"));
-    named!( terminated_abcd_efgh<&[u8], &[u8]>, terminated!(tag_abcd, tag_efgh) );
-
-    assert_eq!(terminated_abcd_efgh(&b"abcdefghijkl"[..]), Ok((&b"ijkl"[..], &b"abcd"[..])));
-    assert_eq!(terminated_abcd_efgh(&b"ab"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(terminated_abcd_efgh(&b"abcde"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(
-      terminated_abcd_efgh(&b"xxx"[..]),
-      Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
-    );
-    assert_eq!(
-      terminated_abcd_efgh(&b"xxxxdef"[..]),
-      Err(Err::Error(error_position!(&b"xxxxdef"[..], ErrorKind::Tag)))
-    );
-    assert_eq!(
-      terminated_abcd_efgh(&b"abcdxxxx"[..]),
-      Err(Err::Error(error_position!(&b"xxxx"[..], ErrorKind::Tag)))
-    );
-  }
-
-  #[test]
-  fn delimited() {
-    named!(tag_abc, tag!("abc"));
-    named!(tag_def, tag!("def"));
-    named!(tag_ghi, tag!("ghi"));
-    named!( delimited_abc_def_ghi<&[u8], &[u8]>, delimited!(tag_abc, tag_def, tag_ghi) );
-
-    assert_eq!(delimited_abc_def_ghi(&b"abcdefghijkl"[..]), Ok((&b"jkl"[..], &b"def"[..])));
-    assert_eq!(delimited_abc_def_ghi(&b"ab"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(delimited_abc_def_ghi(&b"abcde"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(delimited_abc_def_ghi(&b"abcdefgh"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(
-      delimited_abc_def_ghi(&b"xxx"[..]),
-      Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
-    );
-    assert_eq!(
-      delimited_abc_def_ghi(&b"xxxdefghi"[..]),
-      Err(Err::Error(error_position!(&b"xxxdefghi"[..], ErrorKind::Tag),))
-    );
-    assert_eq!(
-      delimited_abc_def_ghi(&b"abcxxxghi"[..]),
-      Err(Err::Error(error_position!(&b"xxxghi"[..], ErrorKind::Tag)))
-    );
-    assert_eq!(
-      delimited_abc_def_ghi(&b"abcdefxxx"[..]),
-      Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
-    );
-  }
-
-  #[test]
-  fn tuple_test() {
-    named!(tuple_3<&[u8], (u16, &[u8], &[u8]) >,
-    tuple!( be_u16 , take!(3), tag!("fg") ) );
-
-    assert_eq!(tuple_3(&b"abcdefgh"[..]), Ok((&b"h"[..], (0x6162u16, &b"cde"[..], &b"fg"[..]))));
-    assert_eq!(tuple_3(&b"abcd"[..]), Err(Err::Incomplete(Needed::Size(3))));
-    assert_eq!(tuple_3(&b"abcde"[..]), Err(Err::Incomplete(Needed::Size(2))));
-    assert_eq!(
-      tuple_3(&b"abcdejk"[..]),
-      Err(Err::Error(error_position!(&b"jk"[..], ErrorKind::Tag)))
-    );
-  }
-
-  #[test]
-  fn do_parse() {
-    fn ret_int1(i: &[u8]) -> IResult<&[u8], u8> {
-      Ok((i, 1))
-    };
-    fn ret_int2(i: &[u8]) -> IResult<&[u8], u8> {
-      Ok((i, 2))
-    };
-
-    //trace_macros!(true);
-    named!(do_parser<&[u8], (u8, u8)>,
-      do_parse!(
-        tag!("abcd")       >>
-        opt!(tag!("abcd")) >>
-        aa: ret_int1       >>
-        tag!("efgh")       >>
-        bb: ret_int2       >>
-        tag!("efgh")       >>
-        (aa, bb)
-      )
-    );
-    //named!(do_parser<&[u8], (u8, u8)>,
-    //  do_parse!(
-    //    tag!("abcd") >> aa: ret_int1 >> tag!("efgh") >> bb: ret_int2 >> tag!("efgh") >> (aa, bb)
-    //  )
-    //);
-
-    //trace_macros!(false);
-
-    assert_eq!(do_parser(&b"abcdabcdefghefghX"[..]), Ok((&b"X"[..], (1, 2))));
-    assert_eq!(do_parser(&b"abcdefghefghX"[..]), Ok((&b"X"[..], (1, 2))));
-    assert_eq!(do_parser(&b"abcdab"[..]), Err(Err::Incomplete(Needed::Size(4))));
-    assert_eq!(do_parser(&b"abcdefghef"[..]), Err(Err::Incomplete(Needed::Size(4))));
-  }
-
-  #[cfg_attr(rustfmt, rustfmt_skip)]
-  #[test]
-  fn do_parse_dependency() {
-    use crate::number::streaming::be_u8;
-
-    named!(length_value,
-      do_parse!(
-        length: be_u8         >>
-        bytes:  take!(length) >>
-        (bytes)
-      )
-    );
-
-    let a = [2u8, 3, 4, 5];
-    let res_a = [3u8, 4];
-    assert_eq!(length_value(&a[..]), Ok((&a[3..], &res_a[..])));
-    let b = [5u8, 3, 4, 5];
-    assert_eq!(length_value(&b[..]), Err(Err::Incomplete(Needed::Size(5))));
-  }
-
-  /*
-  named!(does_not_compile,
-    do_parse!(
-      length: be_u8         >>
-      bytes:  take!(length)
-    )
-  );
-  named!(does_not_compile_either,
-    do_parse!(
-      length: be_u8         ~
-      bytes:  take!(length) ~
-      ( () )
-    )
-  );
-  fn still_does_not_compile() {
-    let data = b"abcd";
-
-    let res = do_parse!(
-      tag!("abcd") >>
-      tag!("efgh") >>
-      ( () )
-    );
-  }
-  */
-}
diff --git a/src/sequence/mod.rs b/src/sequence/mod.rs
index a0eafb9..100c63f 100644
--- a/src/sequence/mod.rs
+++ b/src/sequence/mod.rs
@@ -1,10 +1,10 @@
-//! combinators applying parsers in sequence
+//! Combinators applying parsers in sequence
 
-#[macro_use]
-mod macros;
+#[cfg(test)]
+mod tests;
 
-use crate::internal::IResult;
 use crate::error::ParseError;
+use crate::internal::{IResult, Parser};
 
 /// Gets an object from the first parser,
 /// then gets another object from the second parser.
@@ -12,120 +12,102 @@
 /// # Arguments
 /// * `first` The first parser to apply.
 /// * `second` The second parser to apply.
+///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
 /// use nom::sequence::pair;
 /// use nom::bytes::complete::tag;
 ///
-/// let parser = pair(tag("abc"), tag("efg"));
+/// let mut parser = pair(tag("abc"), tag("efg"));
 ///
 /// assert_eq!(parser("abcefg"), Ok(("", ("abc", "efg"))));
 /// assert_eq!(parser("abcefghij"), Ok(("hij", ("abc", "efg"))));
 /// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
 /// assert_eq!(parser("123"), Err(Err::Error(("123", ErrorKind::Tag))));
 /// ```
-pub fn pair<I, O1, O2, E: ParseError<I>, F, G>(first: F, second: G) -> impl Fn(I) -> IResult<I, (O1, O2), E>
+pub fn pair<I, O1, O2, E: ParseError<I>, F, G>(
+  mut first: F,
+  mut second: G,
+) -> impl FnMut(I) -> IResult<I, (O1, O2), E>
 where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
+  F: Parser<I, O1, E>,
+  G: Parser<I, O2, E>,
 {
   move |input: I| {
-    let (input, o1) = first(input)?;
-    second(input).map(|(i, o2)| (i, (o1, o2)))
+    let (input, o1) = first.parse(input)?;
+    second.parse(input).map(|(i, o2)| (i, (o1, o2)))
   }
 }
 
-// this implementation is used for type inference issues in macros
-#[doc(hidden)]
-pub fn pairc<I, O1, O2, E: ParseError<I>, F, G>(input: I, first: F, second: G) -> IResult<I, (O1, O2), E>
-where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
-{
-  pair(first, second)(input)
-}
-
 /// Matches an object from the first parser and discards it,
 /// then gets an object from the second parser.
 ///
 /// # Arguments
 /// * `first` The opening parser.
 /// * `second` The second parser to get object.
+///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
 /// use nom::sequence::preceded;
 /// use nom::bytes::complete::tag;
 ///
-/// let parser = preceded(tag("abc"), tag("efg"));
+/// let mut parser = preceded(tag("abc"), tag("efg"));
 ///
 /// assert_eq!(parser("abcefg"), Ok(("", "efg")));
 /// assert_eq!(parser("abcefghij"), Ok(("hij", "efg")));
 /// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
 /// assert_eq!(parser("123"), Err(Err::Error(("123", ErrorKind::Tag))));
 /// ```
-pub fn preceded<I, O1, O2, E: ParseError<I>, F, G>(first: F, second: G) -> impl Fn(I) -> IResult<I, O2, E>
+pub fn preceded<I, O1, O2, E: ParseError<I>, F, G>(
+  mut first: F,
+  mut second: G,
+) -> impl FnMut(I) -> IResult<I, O2, E>
 where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
+  F: Parser<I, O1, E>,
+  G: Parser<I, O2, E>,
 {
   move |input: I| {
-    let (input, _) = first(input)?;
-    second(input)
+    let (input, _) = first.parse(input)?;
+    second.parse(input)
   }
 }
 
-// this implementation is used for type inference issues in macros
-#[doc(hidden)]
-pub fn precededc<I, O1, O2, E: ParseError<I>, F, G>(input: I, first: F, second: G) -> IResult<I, O2, E>
-where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
-{
-  preceded(first, second)(input)
-}
-
 /// Gets an object from the first parser,
 /// then matches an object from the second parser and discards it.
 ///
 /// # Arguments
 /// * `first` The first parser to apply.
 /// * `second` The second parser to match an object.
+///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
 /// use nom::sequence::terminated;
 /// use nom::bytes::complete::tag;
 ///
-/// let parser = terminated(tag("abc"), tag("efg"));
+/// let mut parser = terminated(tag("abc"), tag("efg"));
 ///
 /// assert_eq!(parser("abcefg"), Ok(("", "abc")));
 /// assert_eq!(parser("abcefghij"), Ok(("hij", "abc")));
 /// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
 /// assert_eq!(parser("123"), Err(Err::Error(("123", ErrorKind::Tag))));
 /// ```
-pub fn terminated<I, O1, O2, E: ParseError<I>, F, G>(first: F, second: G) -> impl Fn(I) -> IResult<I, O1, E>
+pub fn terminated<I, O1, O2, E: ParseError<I>, F, G>(
+  mut first: F,
+  mut second: G,
+) -> impl FnMut(I) -> IResult<I, O1, E>
 where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
+  F: Parser<I, O1, E>,
+  G: Parser<I, O2, E>,
 {
   move |input: I| {
-    let (input, o1) = first(input)?;
-    second(input).map(|(i, _)| (i, o1))
+    let (input, o1) = first.parse(input)?;
+    second.parse(input).map(|(i, _)| (i, o1))
   }
 }
 
-// this implementation is used for type inference issues in macros
-#[doc(hidden)]
-pub fn terminatedc<I, O1, O2, E: ParseError<I>, F, G>(input: I, first: F, second: G) -> IResult<I, O1, E>
-where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
-{
-  terminated(first, second)(input)
-}
-
 /// Gets an object from the first parser,
 /// then matches an object from the sep_parser and discards it,
 /// then gets another object from the second parser.
@@ -134,100 +116,90 @@
 /// * `first` The first parser to apply.
 /// * `sep` The separator parser to apply.
 /// * `second` The second parser to apply.
+///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
 /// use nom::sequence::separated_pair;
 /// use nom::bytes::complete::tag;
 ///
-/// let parser = separated_pair(tag("abc"), tag("|"), tag("efg"));
+/// let mut parser = separated_pair(tag("abc"), tag("|"), tag("efg"));
 ///
 /// assert_eq!(parser("abc|efg"), Ok(("", ("abc", "efg"))));
 /// assert_eq!(parser("abc|efghij"), Ok(("hij", ("abc", "efg"))));
 /// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
 /// assert_eq!(parser("123"), Err(Err::Error(("123", ErrorKind::Tag))));
 /// ```
-pub fn separated_pair<I, O1, O2, O3, E: ParseError<I>, F, G, H>(first: F, sep: G, second: H) -> impl Fn(I) -> IResult<I, (O1, O3), E>
+pub fn separated_pair<I, O1, O2, O3, E: ParseError<I>, F, G, H>(
+  mut first: F,
+  mut sep: G,
+  mut second: H,
+) -> impl FnMut(I) -> IResult<I, (O1, O3), E>
 where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
-  H: Fn(I) -> IResult<I, O3, E>,
+  F: Parser<I, O1, E>,
+  G: Parser<I, O2, E>,
+  H: Parser<I, O3, E>,
 {
   move |input: I| {
-    let (input, o1) = first(input)?;
-    let (input, _) = sep(input)?;
-    second(input).map(|(i, o2)| (i, (o1, o2)))
+    let (input, o1) = first.parse(input)?;
+    let (input, _) = sep.parse(input)?;
+    second.parse(input).map(|(i, o2)| (i, (o1, o2)))
   }
 }
 
-// this implementation is used for type inference issues in macros
-#[doc(hidden)]
-pub fn separated_pairc<I, O1, O2, O3, E: ParseError<I>, F, G, H>(input: I, first: F, sep: G, second: H) -> IResult<I, (O1, O3), E>
-where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
-  H: Fn(I) -> IResult<I, O3, E>,
-{
-  separated_pair(first, sep, second)(input)
-}
-
-/// Matches an object from the first parser,
-/// then gets an object from the sep_parser,
-/// then matches another object from the second parser.
+/// Matches an object from the first parser and discards it,
+/// then gets an object from the second parser,
+/// and finally matches an object from the third parser and discards it.
 ///
 /// # Arguments
-/// * `first` The first parser to apply.
-/// * `sep` The separator parser to apply.
+/// * `first` The first parser to apply and discard.
 /// * `second` The second parser to apply.
+/// * `third` The third parser to apply and discard.
+///
 /// ```rust
 /// # use nom::{Err, error::ErrorKind, Needed};
 /// # use nom::Needed::Size;
 /// use nom::sequence::delimited;
 /// use nom::bytes::complete::tag;
 ///
-/// let parser = delimited(tag("abc"), tag("|"), tag("efg"));
+/// let mut parser = delimited(tag("("), tag("abc"), tag(")"));
 ///
-/// assert_eq!(parser("abc|efg"), Ok(("", "|")));
-/// assert_eq!(parser("abc|efghij"), Ok(("hij", "|")));
+/// assert_eq!(parser("(abc)"), Ok(("", "abc")));
+/// assert_eq!(parser("(abc)def"), Ok(("def", "abc")));
 /// assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));
 /// assert_eq!(parser("123"), Err(Err::Error(("123", ErrorKind::Tag))));
 /// ```
-pub fn delimited<I, O1, O2, O3, E: ParseError<I>, F, G, H>(first: F, sep: G, second: H) -> impl Fn(I) -> IResult<I, O2, E>
+pub fn delimited<I, O1, O2, O3, E: ParseError<I>, F, G, H>(
+  mut first: F,
+  mut second: G,
+  mut third: H,
+) -> impl FnMut(I) -> IResult<I, O2, E>
 where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
-  H: Fn(I) -> IResult<I, O3, E>,
+  F: Parser<I, O1, E>,
+  G: Parser<I, O2, E>,
+  H: Parser<I, O3, E>,
 {
   move |input: I| {
-    let (input, _) = first(input)?;
-    let (input, o2) = sep(input)?;
-    second(input).map(|(i, _)| (i, o2))
+    let (input, _) = first.parse(input)?;
+    let (input, o2) = second.parse(input)?;
+    third.parse(input).map(|(i, _)| (i, o2))
   }
 }
 
-// this implementation is used for type inference issues in macros
-#[doc(hidden)]
-pub fn delimitedc<I, O1, O2, O3, E: ParseError<I>, F, G, H>(input: I, first: F, sep: G, second: H) -> IResult<I, O2, E>
-where
-  F: Fn(I) -> IResult<I, O1, E>,
-  G: Fn(I) -> IResult<I, O2, E>,
-  H: Fn(I) -> IResult<I, O3, E>,
-{
-  delimited(first, sep, second)(input)
-}
-
-/// helper trait for the tuple combinator
+/// Helper trait for the tuple combinator.
 ///
-/// this trait is implemented for tuples of parsers of up to 21 elements
-pub trait Tuple<I,O,E> {
-  /// parses the input and returns a tuple of results of each parser
-  fn parse(&self, input: I) -> IResult<I,O,E>;
+/// This trait is implemented for tuples of parsers of up to 21 elements.
+pub trait Tuple<I, O, E> {
+  /// Parses the input and returns a tuple of results of each parser.
+  fn parse(&mut self, input: I) -> IResult<I, O, E>;
 }
 
-impl<Input, Output, Error: ParseError<Input>, F: Fn(Input) -> IResult<Input, Output, Error> > Tuple<Input, (Output,), Error> for (F,) {
-   fn parse(&self, input: Input) -> IResult<Input,(Output,),Error> {
-     self.0(input).map(|(i,o)| (i, (o,)))
-   }
+impl<Input, Output, Error: ParseError<Input>, F: Parser<Input, Output, Error>>
+  Tuple<Input, (Output,), Error> for (F,)
+{
+  fn parse(&mut self, input: Input) -> IResult<Input, (Output,), Error> {
+    self.0.parse(input).map(|(i, o)| (i, (o,)))
+  }
 }
 
 macro_rules! tuple_trait(
@@ -248,10 +220,10 @@
   ($($name:ident $ty: ident),+) => (
     impl<
       Input: Clone, $($ty),+ , Error: ParseError<Input>,
-      $($name: Fn(Input) -> IResult<Input, $ty, Error>),+
+      $($name: Parser<Input, $ty, Error>),+
     > Tuple<Input, ( $($ty),+ ), Error> for ( $($name),+ ) {
 
-      fn parse(&self, input: Input) -> IResult<Input, ( $($ty),+ ), Error> {
+      fn parse(&mut self, input: Input) -> IResult<Input, ( $($ty),+ ), Error> {
         tuple_trait_inner!(0, self, input, (), $($name)+)
 
       }
@@ -261,17 +233,17 @@
 
 macro_rules! tuple_trait_inner(
   ($it:tt, $self:expr, $input:expr, (), $head:ident $($id:ident)+) => ({
-    let (i, o) = $self.$it($input.clone())?;
+    let (i, o) = $self.$it.parse($input.clone())?;
 
     succ!($it, tuple_trait_inner!($self, i, ( o ), $($id)+))
   });
   ($it:tt, $self:expr, $input:expr, ($($parsed:tt)*), $head:ident $($id:ident)+) => ({
-    let (i, o) = $self.$it($input.clone())?;
+    let (i, o) = $self.$it.parse($input.clone())?;
 
     succ!($it, tuple_trait_inner!($self, i, ($($parsed)* , o), $($id)+))
   });
   ($it:tt, $self:expr, $input:expr, ($($parsed:tt)*), $head:ident) => ({
-    let (i, o) = $self.$it($input.clone())?;
+    let (i, o) = $self.$it.parse($input.clone())?;
 
     Ok((i, ($($parsed)* , o)))
   });
@@ -280,34 +252,19 @@
 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);
 
-/// applies 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};
 /// use nom::sequence::tuple;
 /// use nom::character::complete::{alpha1, digit1};
-/// let parser = tuple((alpha1, digit1, alpha1));
+/// let mut parser = tuple((alpha1, digit1, alpha1));
 ///
 /// assert_eq!(parser("abc123def"), Ok(("", ("abc", "123", "def"))));
 /// assert_eq!(parser("123def"), Err(Err::Error(("123def", ErrorKind::Alpha))));
 /// ```
-pub fn tuple<I: Clone, O, E: ParseError<I>, List: Tuple<I,O,E>>(l: List)  -> impl Fn(I) -> IResult<I, O, E> {
-  move |i: I| {
-    l.parse(i)
-  }
-}
-
-#[cfg(test)]
-mod tests {
-  use super::*;
-
-  #[test]
-  fn single_element_tuples() {
-    use crate::character::complete::{alpha1, digit1};
-    use crate::{Err, error::ErrorKind};
-
-    let parser = tuple((alpha1,));
-    assert_eq!(parser("abc123def"), Ok(("123def", ("abc",))));
-    assert_eq!(parser("123def"), Err(Err::Error(("123def", ErrorKind::Alpha))));
-  }
+pub fn tuple<I, O, E: ParseError<I>, List: Tuple<I, O, E>>(
+  mut l: List,
+) -> impl FnMut(I) -> IResult<I, O, E> {
+  move |i: I| l.parse(i)
 }
diff --git a/src/sequence/tests.rs b/src/sequence/tests.rs
new file mode 100644
index 0000000..201579b
--- /dev/null
+++ b/src/sequence/tests.rs
@@ -0,0 +1,274 @@
+use super::*;
+use crate::bytes::streaming::{tag, take};
+use crate::error::ErrorKind;
+use crate::internal::{Err, IResult, Needed};
+use crate::number::streaming::be_u16;
+
+#[test]
+fn single_element_tuples() {
+  use crate::character::complete::alpha1;
+  use crate::{error::ErrorKind, Err};
+
+  let mut parser = tuple((alpha1,));
+  assert_eq!(parser("abc123def"), Ok(("123def", ("abc",))));
+  assert_eq!(
+    parser("123def"),
+    Err(Err::Error(("123def", ErrorKind::Alpha)))
+  );
+}
+
+#[derive(PartialEq, Eq, Debug)]
+struct B {
+  a: u8,
+  b: u8,
+}
+
+#[derive(PartialEq, Eq, Debug)]
+struct C {
+  a: u8,
+  b: Option<u8>,
+}
+
+/*FIXME: convert code examples to new error management
+use util::{add_error_pattern, error_to_list, print_error};
+
+#[cfg(feature = "std")]
+#[rustfmt::skip]
+fn error_to_string<P: Clone + PartialEq>(e: &Context<P, u32>) -> &'static str {
+  let v: Vec<(P, ErrorKind<u32>)> = error_to_list(e);
+  // do it this way if you can use slice patterns
+  //match &v[..] {
+  //  [ErrorKind::Custom(42), ErrorKind::Tag]                         => "missing `ijkl` tag",
+  //  [ErrorKind::Custom(42), ErrorKind::Custom(128), ErrorKind::Tag] => "missing `mnop` tag after `ijkl`",
+  //  _            => "unrecognized error"
+  //}
+
+  let collected: Vec<ErrorKind<u32>> = v.iter().map(|&(_, ref e)| e.clone()).collect();
+  if &collected[..] == [ErrorKind::Custom(42), ErrorKind::Tag] {
+    "missing `ijkl` tag"
+  } else if &collected[..] == [ErrorKind::Custom(42), ErrorKind::Custom(128), ErrorKind::Tag] {
+    "missing `mnop` tag after `ijkl`"
+  } else {
+    "unrecognized error"
+  }
+}
+
+// do it this way if you can use box patterns
+//use $crate::lib::std::str;
+//fn error_to_string(e:Err) -> String
+//  match e {
+//    NodePosition(ErrorKind::Custom(42), i1, box Position(ErrorKind::Tag, i2)) => {
+//      format!("missing `ijkl` tag, found '{}' instead", str::from_utf8(i2).unwrap())
+//    },
+//    NodePosition(ErrorKind::Custom(42), i1, box NodePosition(ErrorKind::Custom(128), i2,  box Position(ErrorKind::Tag, i3))) => {
+//      format!("missing `mnop` tag after `ijkl`, found '{}' instead", str::from_utf8(i3).unwrap())
+//    },
+//    _ => "unrecognized error".to_string()
+//  }
+//}
+*/
+
+#[test]
+fn complete() {
+  use crate::bytes::complete::tag;
+  fn err_test(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    let (i, _) = tag("ijkl")(i)?;
+    tag("mnop")(i)
+  }
+  let a = &b"ijklmn"[..];
+
+  let res_a = err_test(a);
+  assert_eq!(
+    res_a,
+    Err(Err::Error(error_position!(&b"mn"[..], ErrorKind::Tag)))
+  );
+}
+
+#[test]
+fn pair_test() {
+  fn pair_abc_def(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
+    pair(tag("abc"), tag("def"))(i)
+  }
+
+  assert_eq!(
+    pair_abc_def(&b"abcdefghijkl"[..]),
+    Ok((&b"ghijkl"[..], (&b"abc"[..], &b"def"[..])))
+  );
+  assert_eq!(
+    pair_abc_def(&b"ab"[..]),
+    Err(Err::Incomplete(Needed::new(1)))
+  );
+  assert_eq!(
+    pair_abc_def(&b"abcd"[..]),
+    Err(Err::Incomplete(Needed::new(2)))
+  );
+  assert_eq!(
+    pair_abc_def(&b"xxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    pair_abc_def(&b"xxxdef"[..]),
+    Err(Err::Error(error_position!(&b"xxxdef"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    pair_abc_def(&b"abcxxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
+  );
+}
+
+#[test]
+fn separated_pair_test() {
+  fn sep_pair_abc_def(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
+    separated_pair(tag("abc"), tag(","), tag("def"))(i)
+  }
+
+  assert_eq!(
+    sep_pair_abc_def(&b"abc,defghijkl"[..]),
+    Ok((&b"ghijkl"[..], (&b"abc"[..], &b"def"[..])))
+  );
+  assert_eq!(
+    sep_pair_abc_def(&b"ab"[..]),
+    Err(Err::Incomplete(Needed::new(1)))
+  );
+  assert_eq!(
+    sep_pair_abc_def(&b"abc,d"[..]),
+    Err(Err::Incomplete(Needed::new(2)))
+  );
+  assert_eq!(
+    sep_pair_abc_def(&b"xxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    sep_pair_abc_def(&b"xxx,def"[..]),
+    Err(Err::Error(error_position!(&b"xxx,def"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    sep_pair_abc_def(&b"abc,xxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
+  );
+}
+
+#[test]
+fn preceded_test() {
+  fn preceded_abcd_efgh(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    preceded(tag("abcd"), tag("efgh"))(i)
+  }
+
+  assert_eq!(
+    preceded_abcd_efgh(&b"abcdefghijkl"[..]),
+    Ok((&b"ijkl"[..], &b"efgh"[..]))
+  );
+  assert_eq!(
+    preceded_abcd_efgh(&b"ab"[..]),
+    Err(Err::Incomplete(Needed::new(2)))
+  );
+  assert_eq!(
+    preceded_abcd_efgh(&b"abcde"[..]),
+    Err(Err::Incomplete(Needed::new(3)))
+  );
+  assert_eq!(
+    preceded_abcd_efgh(&b"xxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    preceded_abcd_efgh(&b"xxxxdef"[..]),
+    Err(Err::Error(error_position!(&b"xxxxdef"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    preceded_abcd_efgh(&b"abcdxxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
+  );
+}
+
+#[test]
+fn terminated_test() {
+  fn terminated_abcd_efgh(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    terminated(tag("abcd"), tag("efgh"))(i)
+  }
+
+  assert_eq!(
+    terminated_abcd_efgh(&b"abcdefghijkl"[..]),
+    Ok((&b"ijkl"[..], &b"abcd"[..]))
+  );
+  assert_eq!(
+    terminated_abcd_efgh(&b"ab"[..]),
+    Err(Err::Incomplete(Needed::new(2)))
+  );
+  assert_eq!(
+    terminated_abcd_efgh(&b"abcde"[..]),
+    Err(Err::Incomplete(Needed::new(3)))
+  );
+  assert_eq!(
+    terminated_abcd_efgh(&b"xxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    terminated_abcd_efgh(&b"xxxxdef"[..]),
+    Err(Err::Error(error_position!(&b"xxxxdef"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    terminated_abcd_efgh(&b"abcdxxxx"[..]),
+    Err(Err::Error(error_position!(&b"xxxx"[..], ErrorKind::Tag)))
+  );
+}
+
+#[test]
+fn delimited_test() {
+  fn delimited_abc_def_ghi(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    delimited(tag("abc"), tag("def"), tag("ghi"))(i)
+  }
+
+  assert_eq!(
+    delimited_abc_def_ghi(&b"abcdefghijkl"[..]),
+    Ok((&b"jkl"[..], &b"def"[..]))
+  );
+  assert_eq!(
+    delimited_abc_def_ghi(&b"ab"[..]),
+    Err(Err::Incomplete(Needed::new(1)))
+  );
+  assert_eq!(
+    delimited_abc_def_ghi(&b"abcde"[..]),
+    Err(Err::Incomplete(Needed::new(1)))
+  );
+  assert_eq!(
+    delimited_abc_def_ghi(&b"abcdefgh"[..]),
+    Err(Err::Incomplete(Needed::new(1)))
+  );
+  assert_eq!(
+    delimited_abc_def_ghi(&b"xxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    delimited_abc_def_ghi(&b"xxxdefghi"[..]),
+    Err(Err::Error(error_position!(
+      &b"xxxdefghi"[..],
+      ErrorKind::Tag
+    ),))
+  );
+  assert_eq!(
+    delimited_abc_def_ghi(&b"abcxxxghi"[..]),
+    Err(Err::Error(error_position!(&b"xxxghi"[..], ErrorKind::Tag)))
+  );
+  assert_eq!(
+    delimited_abc_def_ghi(&b"abcdefxxx"[..]),
+    Err(Err::Error(error_position!(&b"xxx"[..], ErrorKind::Tag)))
+  );
+}
+
+#[test]
+fn tuple_test() {
+  fn tuple_3(i: &[u8]) -> IResult<&[u8], (u16, &[u8], &[u8])> {
+    tuple((be_u16, take(3u8), tag("fg")))(i)
+  }
+
+  assert_eq!(
+    tuple_3(&b"abcdefgh"[..]),
+    Ok((&b"h"[..], (0x6162u16, &b"cde"[..], &b"fg"[..])))
+  );
+  assert_eq!(tuple_3(&b"abcd"[..]), Err(Err::Incomplete(Needed::new(1))));
+  assert_eq!(tuple_3(&b"abcde"[..]), Err(Err::Incomplete(Needed::new(2))));
+  assert_eq!(
+    tuple_3(&b"abcdejk"[..]),
+    Err(Err::Error(error_position!(&b"jk"[..], ErrorKind::Tag)))
+  );
+}
diff --git a/src/str.rs b/src/str.rs
index 71fb1a4..1a8b8ba 100644
--- a/src/str.rs
+++ b/src/str.rs
@@ -1,21 +1,24 @@
 #[cfg(test)]
 mod test {
-  use crate::{Err, error::ErrorKind, IResult};
+  #[cfg(feature = "alloc")]
+  use crate::{branch::alt, bytes::complete::tag_no_case, combinator::recognize, multi::many1};
+  use crate::{
+    bytes::complete::{is_a, is_not, tag, take, take_till, take_until},
+    error::{self, ErrorKind},
+    Err, IResult,
+  };
 
   #[test]
   fn tagtr_succeed() {
     const INPUT: &str = "Hello World!";
     const TAG: &str = "Hello";
     fn test(input: &str) -> IResult<&str, &str> {
-      tag!(input, TAG)
+      tag(TAG)(input)
     }
 
     match test(INPUT) {
       Ok((extra, output)) => {
-        assert!(
-          extra == " World!",
-          "Parser `tag` consumed leftover input."
-        );
+        assert!(extra == " World!", "Parser `tag` consumed leftover input.");
         assert!(
           output == TAG,
           "Parser `tag` doesn't return the tag it matched on success. \
@@ -34,10 +37,12 @@
 
   #[test]
   fn tagtr_incomplete() {
+    use crate::bytes::streaming::tag;
+
     const INPUT: &str = "Hello";
     const TAG: &str = "Hello World!";
 
-    let res: IResult<_,_,(_, ErrorKind)> = tag!(INPUT, TAG);
+    let res: IResult<_, _, error::Error<_>> = tag(TAG)(INPUT);
     match res {
       Err(Err::Incomplete(_)) => (),
       other => {
@@ -55,7 +60,7 @@
     const INPUT: &str = "Hello World!";
     const TAG: &str = "Random"; // TAG must be closer than INPUT.
 
-    let res: IResult<_,_,(_, ErrorKind)> = tag!(INPUT, TAG);
+    let res: IResult<_, _, error::Error<_>> = tag(TAG)(INPUT);
     match res {
       Err(Err::Error(_)) => (),
       other => {
@@ -73,7 +78,7 @@
     const CONSUMED: &str = "βèƒôřèÂßÇ";
     const LEFTOVER: &str = "áƒƭèř";
 
-    let res: IResult<_,_,(_, ErrorKind)> = take!(INPUT, 9);
+    let res: IResult<_, _, error::Error<_>> = take(9_usize)(INPUT);
     match res {
       Ok((extra, output)) => {
         assert!(
@@ -83,7 +88,7 @@
         );
         assert!(
           output == CONSUMED,
-          "Parser `take_s` doens't return the string it consumed on success. Expected `{}`, got `{}`.",
+          "Parser `take_s` doesn't return the string it consumed on success. Expected `{}`, got `{}`.",
           CONSUMED,
           output
         );
@@ -103,7 +108,7 @@
     const CONSUMED: &str = "βèƒôřè";
     const LEFTOVER: &str = "ÂßÇ∂áƒƭèř";
 
-    let res: IResult<_,_,(_, ErrorKind)> = take_until!(INPUT, FIND);
+    let res: IResult<_, _, (_, ErrorKind)> = take_until(FIND)(INPUT);
     match res {
       Ok((extra, output)) => {
         assert!(
@@ -115,7 +120,7 @@
         assert!(
           output == CONSUMED,
           "Parser `take_until`\
-           doens't return the string it consumed on success. Expected `{}`, got `{}`.",
+           doesn't return the string it consumed on success. Expected `{}`, got `{}`.",
           CONSUMED,
           output
         );
@@ -130,9 +135,11 @@
 
   #[test]
   fn take_s_incomplete() {
+    use crate::bytes::streaming::take;
+
     const INPUT: &str = "βèƒôřèÂßÇá";
 
-    let res: IResult<_,_,(_, ErrorKind)> = take!(INPUT, 13);
+    let res: IResult<_, _, (_, ErrorKind)> = take(13_usize)(INPUT);
     match res {
       Err(Err::Incomplete(_)) => (),
       other => panic!(
@@ -151,28 +158,36 @@
 
   #[test]
   fn take_while() {
-    named!(f<&str,&str>, take_while!(is_alphabetic));
+    use crate::bytes::streaming::take_while;
+
+    fn f(i: &str) -> IResult<&str, &str> {
+      take_while(is_alphabetic)(i)
+    }
     let a = "";
     let b = "abcd";
     let c = "abcd123";
     let d = "123";
 
-    assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(f(&b[..]), Err(Err::Incomplete(Needed::Size(1))));
+    assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::new(1))));
+    assert_eq!(f(&b[..]), Err(Err::Incomplete(Needed::new(1))));
     assert_eq!(f(&c[..]), Ok((&d[..], &b[..])));
     assert_eq!(f(&d[..]), Ok((&d[..], &a[..])));
   }
 
   #[test]
   fn take_while1() {
-    named!(f<&str,&str>, take_while1!(is_alphabetic));
+    use crate::bytes::streaming::take_while1;
+
+    fn f(i: &str) -> IResult<&str, &str> {
+      take_while1(is_alphabetic)(i)
+    }
     let a = "";
     let b = "abcd";
     let c = "abcd123";
     let d = "123";
 
-    assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::Size(1))));
-    assert_eq!(f(&b[..]), Err(Err::Incomplete(Needed::Size(1))));
+    assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::new(1))));
+    assert_eq!(f(&b[..]), Err(Err::Incomplete(Needed::new(1))));
     assert_eq!(f(&c[..]), Ok((&"123"[..], &b[..])));
     assert_eq!(
       f(&d[..]),
@@ -189,7 +204,7 @@
       c == 'á'
     }
     fn test(input: &str) -> IResult<&str, &str> {
-      take_till!(input, till_s)
+      take_till(till_s)(input)
     }
     match test(INPUT) {
       Ok((extra, output)) => {
@@ -215,6 +230,8 @@
 
   #[test]
   fn take_while_succeed_none() {
+    use crate::bytes::complete::take_while;
+
     const INPUT: &str = "βèƒôřèÂßÇáƒƭèř";
     const CONSUMED: &str = "";
     const LEFTOVER: &str = "βèƒôřèÂßÇáƒƭèř";
@@ -222,7 +239,7 @@
       c == '9'
     }
     fn test(input: &str) -> IResult<&str, &str> {
-      take_while!(input, while_s)
+      take_while(while_s)(input)
     }
     match test(INPUT) {
       Ok((extra, output)) => {
@@ -253,7 +270,7 @@
     const CONSUMED: &str = "βèƒôřèÂßÇ";
     const LEFTOVER: &str = "áƒƭèř";
     fn test(input: &str) -> IResult<&str, &str> {
-      is_not!(input, AVOID)
+      is_not(AVOID)(input)
     }
     match test(INPUT) {
       Ok((extra, output)) => {
@@ -264,7 +281,7 @@
         );
         assert!(
           output == CONSUMED,
-          "Parser `is_not` doens't return the string it consumed on success. Expected `{}`, got `{}`.",
+          "Parser `is_not` doesn't return the string it consumed on success. Expected `{}`, got `{}`.",
           CONSUMED,
           output
         );
@@ -279,14 +296,24 @@
 
   #[test]
   fn take_while_succeed_some() {
+    use crate::bytes::complete::take_while;
+
     const INPUT: &str = "βèƒôřèÂßÇáƒƭèř";
     const CONSUMED: &str = "βèƒôřèÂßÇ";
     const LEFTOVER: &str = "áƒƭèř";
     fn while_s(c: char) -> bool {
-      c == 'β' || c == 'è' || c == 'ƒ' || c == 'ô' || c == 'ř' || c == 'è' || c == 'Â' || c == 'ß' || c == 'Ç'
+      c == 'β'
+        || c == 'è'
+        || c == 'ƒ'
+        || c == 'ô'
+        || c == 'ř'
+        || c == 'è'
+        || c == 'Â'
+        || c == 'ß'
+        || c == 'Ç'
     }
     fn test(input: &str) -> IResult<&str, &str> {
-      take_while!(input, while_s)
+      take_while(while_s)(input)
     }
     match test(INPUT) {
       Ok((extra, output)) => {
@@ -315,7 +342,7 @@
     const INPUT: &str = "βèƒôřèÂßÇáƒƭèř";
     const AVOID: &str = "βúçƙ¥";
     fn test(input: &str) -> IResult<&str, &str> {
-      is_not!(input, AVOID)
+      is_not(AVOID)(input)
     }
     match test(INPUT) {
       Err(Err::Error(_)) => (),
@@ -328,14 +355,24 @@
 
   #[test]
   fn take_while1_succeed() {
+    use crate::bytes::complete::take_while1;
+
     const INPUT: &str = "βèƒôřèÂßÇáƒƭèř";
     const CONSUMED: &str = "βèƒôřèÂßÇ";
     const LEFTOVER: &str = "áƒƭèř";
     fn while1_s(c: char) -> bool {
-      c == 'β' || c == 'è' || c == 'ƒ' || c == 'ô' || c == 'ř' || c == 'è' || c == 'Â' || c == 'ß' || c == 'Ç'
+      c == 'β'
+        || c == 'è'
+        || c == 'ƒ'
+        || c == 'ô'
+        || c == 'ř'
+        || c == 'è'
+        || c == 'Â'
+        || c == 'ß'
+        || c == 'Ç'
     }
     fn test(input: &str) -> IResult<&str, &str> {
-      take_while1!(input, while1_s)
+      take_while1(while1_s)(input)
     }
     match test(INPUT) {
       Ok((extra, output)) => {
@@ -361,10 +398,12 @@
 
   #[test]
   fn take_until_incomplete() {
+    use crate::bytes::streaming::take_until;
+
     const INPUT: &str = "βèƒôřè";
     const FIND: &str = "βèƒôřèÂßÇ";
 
-    let res: IResult<_,_,(_, ErrorKind)> = take_until!(INPUT, FIND);
+    let res: IResult<_, _, (_, ErrorKind)> = take_until(FIND)(INPUT);
     match res {
       Err(Err::Incomplete(_)) => (),
       other => panic!(
@@ -382,7 +421,7 @@
     const CONSUMED: &str = "βèƒôřèÂßÇ";
     const LEFTOVER: &str = "áƒƭèř";
     fn test(input: &str) -> IResult<&str, &str> {
-      is_a!(input, MATCH)
+      is_a(MATCH)(input)
     }
     match test(INPUT) {
       Ok((extra, output)) => {
@@ -393,7 +432,7 @@
         );
         assert!(
           output == CONSUMED,
-          "Parser `is_a` doens't return the string it consumed on success. Expected `{}`, got `{}`.",
+          "Parser `is_a` doesn't return the string it consumed on success. Expected `{}`, got `{}`.",
           CONSUMED,
           output
         );
@@ -408,12 +447,14 @@
 
   #[test]
   fn take_while1_fail() {
+    use crate::bytes::complete::take_while1;
+
     const INPUT: &str = "βèƒôřèÂßÇáƒƭèř";
     fn while1_s(c: char) -> bool {
       c == '9'
     }
     fn test(input: &str) -> IResult<&str, &str> {
-      take_while1!(input, while1_s)
+      take_while1(while1_s)(input)
     }
     match test(INPUT) {
       Err(Err::Error(_)) => (),
@@ -430,7 +471,7 @@
     const INPUT: &str = "βèƒôřèÂßÇáƒƭèř";
     const MATCH: &str = "Ûñℓúçƙ¥";
     fn test(input: &str) -> IResult<&str, &str> {
-      is_a!(input, MATCH)
+      is_a(MATCH)(input)
     }
     match test(INPUT) {
       Err(Err::Error(_)) => (),
@@ -443,10 +484,12 @@
 
   #[test]
   fn take_until_error() {
+    use crate::bytes::streaming::take_until;
+
     const INPUT: &str = "βèƒôřèÂßÇáƒƭèř";
     const FIND: &str = "Ráñδô₥";
 
-    let res: IResult<_,_,(_, ErrorKind)> = take_until!(INPUT, FIND);
+    let res: IResult<_, _, (_, ErrorKind)> = take_until(FIND)(INPUT);
     match res {
       Err(Err::Incomplete(_)) => (),
       other => panic!(
@@ -463,7 +506,9 @@
     let a = "aabbab";
     let b = "ababcd";
 
-    named!(f <&str,&str>, recognize!(many1!(complete!(alt!( tag!("a") | tag!("b") )))));
+    fn f(i: &str) -> IResult<&str, &str> {
+      recognize(many1(alt((tag("a"), tag("b")))))(i)
+    }
 
     assert_eq!(f(&a[..]), Ok((&a[6..], &a[..])));
     assert_eq!(f(&b[..]), Ok((&b[4..], &b[..4])));
@@ -471,9 +516,9 @@
 
   #[test]
   fn utf8_indexing() {
-    named!(dot(&str) -> &str,
-        tag!(".")
-      );
+    fn dot(i: &str) -> IResult<&str, &str> {
+      tag(".")(i)
+    }
 
     let _ = dot("點");
   }
@@ -481,14 +526,11 @@
   #[cfg(feature = "alloc")]
   #[test]
   fn case_insensitive() {
-    named!(test<&str,&str>, tag_no_case!("ABcd"));
+    fn test(i: &str) -> IResult<&str, &str> {
+      tag_no_case("ABcd")(i)
+    }
     assert_eq!(test("aBCdefgh"), Ok(("efgh", "aBCd")));
     assert_eq!(test("abcdefgh"), Ok(("efgh", "abcd")));
     assert_eq!(test("ABCDefgh"), Ok(("efgh", "ABCD")));
-
-    named!(test2<&str,&str>, tag_no_case!("ABcd"));
-    assert_eq!(test2("aBCdefgh"), Ok(("efgh", "aBCd")));
-    assert_eq!(test2("abcdefgh"), Ok(("efgh", "abcd")));
-    assert_eq!(test2("ABCDefgh"), Ok(("efgh", "ABCD")));
   }
 }
diff --git a/src/traits.rs b/src/traits.rs
index afd16ba..3c3053e 100644
--- a/src/traits.rs
+++ b/src/traits.rs
@@ -1,25 +1,22 @@
 //! Traits input types have to implement to work with nom combinators
-//!
+use crate::error::{ErrorKind, ParseError};
 use crate::internal::{Err, IResult, Needed};
-use crate::error::{ParseError, ErrorKind};
+use crate::lib::std::iter::{Copied, Enumerate};
 use crate::lib::std::ops::{Range, RangeFrom, RangeFull, RangeTo};
-use crate::lib::std::iter::Enumerate;
 use crate::lib::std::slice::Iter;
-use crate::lib::std::iter::Map;
-use crate::lib::std::str::Chars;
-use crate::lib::std::str::CharIndices;
-use crate::lib::std::str::FromStr;
 use crate::lib::std::str::from_utf8;
-use memchr;
+use crate::lib::std::str::CharIndices;
+use crate::lib::std::str::Chars;
+use crate::lib::std::str::FromStr;
 
 #[cfg(feature = "alloc")]
 use crate::lib::std::string::String;
 #[cfg(feature = "alloc")]
 use crate::lib::std::vec::Vec;
 
-/// abstract method to calculate the input length
+/// Abstract method to calculate the input length
 pub trait InputLength {
-  /// calculates the input length, as indicated by its name,
+  /// Calculates the input length, as indicated by its name,
   /// and the name of the trait itself
   fn input_len(&self) -> usize;
 }
@@ -47,9 +44,9 @@
   }
 }
 
-/// useful functions to calculate the offset between slices and show a hexdump of a slice
+/// Useful functions to calculate the offset between slices and show a hexdump of a slice
 pub trait Offset {
-  /// offset between the first byte of self and the first byte of the argument
+  /// Offset between the first byte of self and the first byte of the argument
   fn offset(&self, second: &Self) -> usize;
 }
 
@@ -91,14 +88,14 @@
 
 /// Helper trait for types that can be viewed as a byte slice
 pub trait AsBytes {
-  /// casts the input type to a byte slice
+  /// Casts the input type to a byte slice
   fn as_bytes(&self) -> &[u8];
 }
 
 impl<'a> AsBytes for &'a str {
   #[inline(always)]
   fn as_bytes(&self) -> &[u8] {
-    <str as AsBytes>::as_bytes(self)
+    (*self).as_bytes()
   }
 }
 
@@ -150,27 +147,27 @@
     30 31 32
 }
 
-/// transforms common types to a char for basic token parsing
+/// Transforms common types to a char for basic token parsing
 pub trait AsChar {
   /// makes a char from self
   fn as_char(self) -> char;
 
-  /// tests that self is an alphabetic character
+  /// Tests that self is an alphabetic character
   ///
-  /// warning: for `&str` it recognizes alphabetic
+  /// Warning: for `&str` it recognizes alphabetic
   /// characters outside of the 52 ASCII letters
   fn is_alpha(self) -> bool;
 
-  /// tests that self is an alphabetic character
+  /// Tests that self is an alphabetic character
   /// or a decimal digit
   fn is_alphanum(self) -> bool;
-  /// tests that self is a decimal digit
+  /// Tests that self is a decimal digit
   fn is_dec_digit(self) -> bool;
-  /// tests that self is an hex digit
+  /// Tests that self is an hex digit
   fn is_hex_digit(self) -> bool;
-  /// tests that self is an octal digit
+  /// Tests that self is an octal digit
   fn is_oct_digit(self) -> bool;
-  /// gets the len in bytes for self
+  /// Gets the len in bytes for self
   fn len(self) -> usize;
 }
 
@@ -193,7 +190,9 @@
   }
   #[inline]
   fn is_hex_digit(self) -> bool {
-    (self >= 0x30 && self <= 0x39) || (self >= 0x41 && self <= 0x46) || (self >= 0x61 && self <= 0x66)
+    (self >= 0x30 && self <= 0x39)
+      || (self >= 0x41 && self <= 0x46)
+      || (self >= 0x61 && self <= 0x66)
   }
   #[inline]
   fn is_oct_digit(self) -> bool {
@@ -223,7 +222,9 @@
   }
   #[inline]
   fn is_hex_digit(self) -> bool {
-    (*self >= 0x30 && *self <= 0x39) || (*self >= 0x41 && *self <= 0x46) || (*self >= 0x61 && *self <= 0x66)
+    (*self >= 0x30 && *self <= 0x39)
+      || (*self >= 0x41 && *self <= 0x46)
+      || (*self >= 0x61 && *self <= 0x66)
   }
   #[inline]
   fn is_oct_digit(self) -> bool {
@@ -297,48 +298,44 @@
   }
 }
 
-/// abstracts common iteration operations on the input type
+/// Abstracts common iteration operations on the input type
 pub trait InputIter {
-  /// the current input type is a sequence of that `Item` type.
+  /// The current input type is a sequence of that `Item` type.
   ///
-  /// example: `u8` for `&[u8]` or `char` for &str`
+  /// Example: `u8` for `&[u8]` or `char` for `&str`
   type Item;
-  /// an iterator over the input type, producing the item and its position
+  /// An iterator over the input type, producing the item and its position
   /// for use with [Slice]. If we're iterating over `&str`, the position
   /// corresponds to the byte index of the character
   type Iter: Iterator<Item = (usize, Self::Item)>;
 
-  /// an iterator over the input type, producing the item
+  /// An iterator over the input type, producing the item
   type IterElem: Iterator<Item = Self::Item>;
 
-  /// returns an iterator over the elements and their byte offsets
+  /// Returns an iterator over the elements and their byte offsets
   fn iter_indices(&self) -> Self::Iter;
-  /// returns an iterator over the elements
+  /// Returns an iterator over the elements
   fn iter_elements(&self) -> Self::IterElem;
-  /// finds the byte position of the element
+  /// Finds the byte position of the element
   fn position<P>(&self, predicate: P) -> Option<usize>
   where
     P: Fn(Self::Item) -> bool;
-  /// get the byte offset from the element's position in the stream
-  fn slice_index(&self, count: usize) -> Option<usize>;
+  /// Get the byte offset from the element's position in the stream
+  fn slice_index(&self, count: usize) -> Result<usize, Needed>;
 }
 
-/// abstracts slicing operations
+/// Abstracts slicing operations
 pub trait InputTake: Sized {
-  /// returns a slice of `count` bytes. panics if count > length
+  /// Returns a slice of `count` bytes. panics if count > length
   fn take(&self, count: usize) -> Self;
-  /// split the stream at the `count` byte offset. panics if count > length
+  /// Split the stream at the `count` byte offset. panics if count > length
   fn take_split(&self, count: usize) -> (Self, Self);
 }
 
-fn star(r_u8: &u8) -> u8 {
-  *r_u8
-}
-
 impl<'a> InputIter for &'a [u8] {
   type Item = u8;
   type Iter = Enumerate<Self::IterElem>;
-  type IterElem = Map<Iter<'a, Self::Item>, fn(&u8) -> u8>;
+  type IterElem = Copied<Iter<'a, u8>>;
 
   #[inline]
   fn iter_indices(&self) -> Self::Iter {
@@ -346,7 +343,7 @@
   }
   #[inline]
   fn iter_elements(&self) -> Self::IterElem {
-    self.iter().map(star)
+    self.iter().copied()
   }
   #[inline]
   fn position<P>(&self, predicate: P) -> Option<usize>
@@ -356,11 +353,11 @@
     self.iter().position(|b| predicate(*b))
   }
   #[inline]
-  fn slice_index(&self, count: usize) -> Option<usize> {
+  fn slice_index(&self, count: usize) -> Result<usize, Needed> {
     if self.len() >= count {
-      Some(count)
+      Ok(count)
     } else {
-      None
+      Err(Needed::new(count - self.len()))
     }
   }
 }
@@ -401,18 +398,18 @@
     None
   }
   #[inline]
-  fn slice_index(&self, count: usize) -> Option<usize> {
+  fn slice_index(&self, count: usize) -> Result<usize, Needed> {
     let mut cnt = 0;
     for (index, _) in self.char_indices() {
       if cnt == count {
-        return Some(index);
+        return Ok(index);
       }
       cnt += 1;
     }
     if cnt == count {
-      return Some(self.len());
+      return Ok(self.len());
     }
-    None
+    Err(Needed::Unknown)
   }
 }
 
@@ -425,68 +422,82 @@
   // return byte index
   #[inline]
   fn take_split(&self, count: usize) -> (Self, Self) {
-    (&self[count..], &self[..count])
+    let (prefix, suffix) = self.split_at(count);
+    (suffix, prefix)
   }
 }
 
-/// Dummy trait used for default implementations (currently only used for `InputTakeAtPosition`).
+/// Dummy trait used for default implementations (currently only used for `InputTakeAtPosition` and `Compare`).
 ///
 /// When implementing a custom input type, it is possible to use directly the
-/// default implementation: if the input type implements `InputLength`, `InputIter`,
+/// default implementation: If the input type implements `InputLength`, `InputIter`,
 /// `InputTake` and `Clone`, you can implement `UnspecializedInput` and get
-/// a default version of `InputTakeAtPosition`.
+/// a default version of `InputTakeAtPosition` and `Compare`.
 ///
 /// For performance reasons, you might want to write a custom implementation of
 /// `InputTakeAtPosition` (like the one for `&[u8]`).
 pub trait UnspecializedInput {}
 
-/// methods to take as much input as possible until the provided function returns true for the current element
+/// Methods to take as much input as possible until the provided function returns true for the current element.
 ///
-/// a large part of nom's basic parsers are built using this trait
+/// A large part of nom's basic parsers are built using this trait.
 pub trait InputTakeAtPosition: Sized {
-  /// the current input type is a sequence of that `Item` type.
+  /// The current input type is a sequence of that `Item` type.
   ///
-  /// example: `u8` for `&[u8]` or `char` for &str`
+  /// Example: `u8` for `&[u8]` or `char` for `&str`
   type Item;
 
-  /// looks for the first element of the input type for which the condition returns true,
-  /// and returns the input up to this position
+  /// Looks for the first element of the input type for which the condition returns true,
+  /// and returns the input up to this position.
   ///
-  /// *streaming version*: if no element is found matching the condition, this will return `Incomplete`
+  /// *streaming version*: If no element is found matching the condition, this will return `Incomplete`
   fn split_at_position<P, E: ParseError<Self>>(&self, predicate: P) -> IResult<Self, Self, E>
   where
     P: Fn(Self::Item) -> bool;
 
-  /// looks for the first element of the input type for which the condition returns true
-  /// and returns the input up to this position
+  /// Looks for the first element of the input type for which the condition returns true
+  /// and returns the input up to this position.
   ///
-  /// fails if the produced slice is empty
+  /// Fails if the produced slice is empty.
   ///
-  /// *streaming version*: if no element is found matching the condition, this will return `Incomplete`
-  fn split_at_position1<P, E: ParseError<Self>>(&self, predicate: P, e: ErrorKind) -> IResult<Self, Self, E>
+  /// *streaming version*: If no element is found matching the condition, this will return `Incomplete`
+  fn split_at_position1<P, E: ParseError<Self>>(
+    &self,
+    predicate: P,
+    e: ErrorKind,
+  ) -> IResult<Self, Self, E>
   where
     P: Fn(Self::Item) -> bool;
 
-  /// looks for the first element of the input type for which the condition returns true,
-  /// and returns the input up to this position
+  /// Looks for the first element of the input type for which the condition returns true,
+  /// and returns the input up to this position.
   ///
-  /// *complete version*: if no element is found matching the condition, this will return the whole input
-  fn split_at_position_complete<P, E: ParseError<Self>>(&self, predicate: P) -> IResult<Self, Self, E>
+  /// *complete version*: If no element is found matching the condition, this will return the whole input
+  fn split_at_position_complete<P, E: ParseError<Self>>(
+    &self,
+    predicate: P,
+  ) -> IResult<Self, Self, E>
   where
     P: Fn(Self::Item) -> bool;
 
-  /// looks for the first element of the input type for which the condition returns true
-  /// and returns the input up to this position
+  /// Looks for the first element of the input type for which the condition returns true
+  /// and returns the input up to this position.
   ///
-  /// fails if the produced slice is empty
+  /// Fails if the produced slice is empty.
   ///
-  /// *complete version*: if no element is found matching the condition, this will return the whole input
-  fn split_at_position1_complete<P, E: ParseError<Self>>(&self, predicate: P, e: ErrorKind) -> IResult<Self, Self, E>
+  /// *complete version*: If no element is found matching the condition, this will return the whole input
+  fn split_at_position1_complete<P, E: ParseError<Self>>(
+    &self,
+    predicate: P,
+    e: ErrorKind,
+  ) -> IResult<Self, Self, E>
   where
     P: Fn(Self::Item) -> bool;
 }
 
-impl<T: InputLength + InputIter + InputTake + Clone + UnspecializedInput> InputTakeAtPosition for T {
+impl<T: InputLength + InputIter + InputTake + Clone + UnspecializedInput> InputTakeAtPosition
+  for T
+{
   type Item = <T as InputIter>::Item;
 
   fn split_at_position<P, E: ParseError<Self>>(&self, predicate: P) -> IResult<Self, Self, E>
@@ -495,36 +506,53 @@
   {
     match self.position(predicate) {
       Some(n) => Ok(self.take_split(n)),
-      None => Err(Err::Incomplete(Needed::Size(1))),
+      None => Err(Err::Incomplete(Needed::new(1))),
     }
   }
 
-  fn split_at_position1<P, E: ParseError<Self>>(&self, predicate: P, e: ErrorKind) -> IResult<Self, Self, E>
+  fn split_at_position1<P, E: ParseError<Self>>(
+    &self,
+    predicate: P,
+    e: ErrorKind,
+  ) -> IResult<Self, Self, E>
   where
     P: Fn(Self::Item) -> bool,
   {
     match self.position(predicate) {
       Some(0) => Err(Err::Error(E::from_error_kind(self.clone(), e))),
       Some(n) => Ok(self.take_split(n)),
-      None => Err(Err::Incomplete(Needed::Size(1))),
+      None => Err(Err::Incomplete(Needed::new(1))),
     }
   }
 
-  fn split_at_position_complete<P, E: ParseError<Self>>(&self, predicate: P) -> IResult<Self, Self, E>
-    where P: Fn(Self::Item) -> bool {
+  fn split_at_position_complete<P, E: ParseError<Self>>(
+    &self,
+    predicate: P,
+  ) -> IResult<Self, Self, E>
+  where
+    P: Fn(Self::Item) -> bool,
+  {
     match self.split_at_position(predicate) {
       Err(Err::Incomplete(_)) => Ok(self.take_split(self.input_len())),
       res => res,
     }
   }
 
-  fn split_at_position1_complete<P, E: ParseError<Self>>(&self, predicate: P, e: ErrorKind) -> IResult<Self, Self, E>
-    where P: Fn(Self::Item) -> bool {
+  fn split_at_position1_complete<P, E: ParseError<Self>>(
+    &self,
+    predicate: P,
+    e: ErrorKind,
+  ) -> IResult<Self, Self, E>
+  where
+    P: Fn(Self::Item) -> bool,
+  {
     match self.split_at_position1(predicate, e) {
-      Err(Err::Incomplete(_)) => if self.input_len() == 0 {
-        Err(Err::Error(E::from_error_kind(self.clone(), e)))
-      } else {
-        Ok(self.take_split(self.input_len()))
+      Err(Err::Incomplete(_)) => {
+        if self.input_len() == 0 {
+          Err(Err::Error(E::from_error_kind(self.clone(), e)))
+        } else {
+          Ok(self.take_split(self.input_len()))
+        }
       }
       res => res,
     }
@@ -538,43 +566,58 @@
   where
     P: Fn(Self::Item) -> bool,
   {
-    match (0..self.len()).find(|b| predicate(self[*b])) {
-      Some(i) => Ok((&self[i..], &self[..i])),
-      None => Err(Err::Incomplete(Needed::Size(1))),
+    match self.iter().position(|c| predicate(*c)) {
+      Some(i) => Ok(self.take_split(i)),
+      None => Err(Err::Incomplete(Needed::new(1))),
     }
   }
 
-  fn split_at_position1<P, E: ParseError<Self>>(&self, predicate: P, e: ErrorKind) -> IResult<Self, Self, E>
+  fn split_at_position1<P, E: ParseError<Self>>(
+    &self,
+    predicate: P,
+    e: ErrorKind,
+  ) -> IResult<Self, Self, E>
   where
     P: Fn(Self::Item) -> bool,
   {
-    match (0..self.len()).find(|b| predicate(self[*b])) {
+    match self.iter().position(|c| predicate(*c)) {
       Some(0) => Err(Err::Error(E::from_error_kind(self, e))),
-      Some(i) => Ok((&self[i..], &self[..i])),
-      None => Err(Err::Incomplete(Needed::Size(1))),
+      Some(i) => Ok(self.take_split(i)),
+      None => Err(Err::Incomplete(Needed::new(1))),
     }
   }
 
-  fn split_at_position_complete<P, E: ParseError<Self>>(&self, predicate: P) -> IResult<Self, Self, E>
-    where P: Fn(Self::Item) -> bool {
-    match (0..self.len()).find(|b| predicate(self[*b])) {
-      Some(i) => Ok((&self[i..], &self[..i])),
+  fn split_at_position_complete<P, E: ParseError<Self>>(
+    &self,
+    predicate: P,
+  ) -> IResult<Self, Self, E>
+  where
+    P: Fn(Self::Item) -> bool,
+  {
+    match self.iter().position(|c| predicate(*c)) {
+      Some(i) => Ok(self.take_split(i)),
       None => Ok(self.take_split(self.input_len())),
     }
   }
 
-  fn split_at_position1_complete<P, E: ParseError<Self>>(&self, predicate: P, e: ErrorKind) -> IResult<Self, Self, E>
-    where P: Fn(Self::Item) -> bool {
-    match (0..self.len()).find(|b| predicate(self[*b])) {
+  fn split_at_position1_complete<P, E: ParseError<Self>>(
+    &self,
+    predicate: P,
+    e: ErrorKind,
+  ) -> IResult<Self, Self, E>
+  where
+    P: Fn(Self::Item) -> bool,
+  {
+    match self.iter().position(|c| predicate(*c)) {
       Some(0) => Err(Err::Error(E::from_error_kind(self, e))),
-      Some(i) => Ok((&self[i..], &self[..i])),
+      Some(i) => Ok(self.take_split(i)),
       None => {
-        if self.len() == 0 {
+        if self.is_empty() {
           Err(Err::Error(E::from_error_kind(self, e)))
         } else {
           Ok(self.take_split(self.input_len()))
         }
-      },
+      }
     }
   }
 }
@@ -587,72 +630,110 @@
     P: Fn(Self::Item) -> bool,
   {
     match self.find(predicate) {
-      Some(i) => Ok((&self[i..], &self[..i])),
-      None => Err(Err::Incomplete(Needed::Size(1))),
+      // find() returns a byte index that is already in the slice at a char boundary
+      Some(i) => unsafe { Ok((self.get_unchecked(i..), self.get_unchecked(..i))) },
+      None => Err(Err::Incomplete(Needed::new(1))),
     }
   }
 
-  fn split_at_position1<P, E: ParseError<Self>>(&self, predicate: P, e: ErrorKind) -> IResult<Self, Self, E>
+  fn split_at_position1<P, E: ParseError<Self>>(
+    &self,
+    predicate: P,
+    e: ErrorKind,
+  ) -> IResult<Self, Self, E>
   where
     P: Fn(Self::Item) -> bool,
   {
     match self.find(predicate) {
       Some(0) => Err(Err::Error(E::from_error_kind(self, e))),
-      Some(i) => Ok((&self[i..], &self[..i])),
-      None => Err(Err::Incomplete(Needed::Size(1))),
+      // find() returns a byte index that is already in the slice at a char boundary
+      Some(i) => unsafe { Ok((self.get_unchecked(i..), self.get_unchecked(..i))) },
+      None => Err(Err::Incomplete(Needed::new(1))),
     }
   }
 
-  fn split_at_position_complete<P, E: ParseError<Self>>(&self, predicate: P) -> IResult<Self, Self, E>
-    where P: Fn(Self::Item) -> bool {
+  fn split_at_position_complete<P, E: ParseError<Self>>(
+    &self,
+    predicate: P,
+  ) -> IResult<Self, Self, E>
+  where
+    P: Fn(Self::Item) -> bool,
+  {
     match self.find(predicate) {
-      Some(i) => Ok((&self[i..], &self[..i])),
-      None =>  Ok(self.take_split(self.input_len()))
-    }
-  }
-
-  fn split_at_position1_complete<P, E: ParseError<Self>>(&self, predicate: P, e: ErrorKind) -> IResult<Self, Self, E>
-    where P: Fn(Self::Item) -> bool {
-    match self.find(predicate) {
-      Some(0) => Err(Err::Error(E::from_error_kind(self, e))),
-      Some(i) => Ok((&self[i..], &self[..i])),
-      None => {
-        if self.len() == 0 {
-          Err(Err::Error(E::from_error_kind(self, e)))
-        } else {
-          Ok(self.take_split(self.input_len()))
-        }
+      // find() returns a byte index that is already in the slice at a char boundary
+      Some(i) => unsafe { Ok((self.get_unchecked(i..), self.get_unchecked(..i))) },
+      // the end of slice is a char boundary
+      None => unsafe {
+        Ok((
+          self.get_unchecked(self.len()..),
+          self.get_unchecked(..self.len()),
+        ))
       },
     }
   }
+
+  fn split_at_position1_complete<P, E: ParseError<Self>>(
+    &self,
+    predicate: P,
+    e: ErrorKind,
+  ) -> IResult<Self, Self, E>
+  where
+    P: Fn(Self::Item) -> bool,
+  {
+    match self.find(predicate) {
+      Some(0) => Err(Err::Error(E::from_error_kind(self, e))),
+      // find() returns a byte index that is already in the slice at a char boundary
+      Some(i) => unsafe { Ok((self.get_unchecked(i..), self.get_unchecked(..i))) },
+      None => {
+        if self.is_empty() {
+          Err(Err::Error(E::from_error_kind(self, e)))
+        } else {
+          // the end of slice is a char boundary
+          unsafe {
+            Ok((
+              self.get_unchecked(self.len()..),
+              self.get_unchecked(..self.len()),
+            ))
+          }
+        }
+      }
+    }
+  }
 }
 
-/// indicates wether a comparison was successful, an error, or
+/// Indicates whether a comparison was successful, an error, or
 /// if more data was needed
 #[derive(Debug, PartialEq)]
 pub enum CompareResult {
-  /// comparison was successful
+  /// Comparison was successful
   Ok,
-  /// we need more data to be sure
+  /// We need more data to be sure
   Incomplete,
-  /// comparison failed
+  /// Comparison failed
   Error,
 }
 
-/// abstracts comparison operations
+/// Abstracts comparison operations
 pub trait Compare<T> {
-  /// compares self to another value for equality
+  /// Compares self to another value for equality
   fn compare(&self, t: T) -> CompareResult;
-  /// compares self to another value for equality
+  /// Compares self to another value for equality
   /// independently of the case.
   ///
-  /// warning: for `&str`, the comparison is done
+  /// Warning: for `&str`, the comparison is done
   /// by lowercasing both strings and comparing
   /// the result. This is a temporary solution until
   /// a better one appears
   fn compare_no_case(&self, t: T) -> CompareResult;
 }
 
+fn lowercase_byte(c: u8) -> u8 {
+  match c {
+    b'A'..=b'Z' => c - b'A' + b'a',
+    _ => c,
+  }
+}
+
 impl<'a, 'b> Compare<&'b [u8]> for &'a [u8] {
   #[inline(always)]
   fn compare(&self, t: &'b [u8]) -> CompareResult {
@@ -688,19 +769,53 @@
 
   #[inline(always)]
   fn compare_no_case(&self, t: &'b [u8]) -> CompareResult {
-    let len = self.len();
-    let blen = t.len();
-    let m = if len < blen { len } else { blen };
-    let reduced = &self[..m];
-    let other = &t[..m];
-
-    if !reduced.iter().zip(other).all(|(a, b)| match (*a, *b) {
-      (0..=64, 0..=64) | (91..=96, 91..=96) | (123..=255, 123..=255) => a == b,
-      (65..=90, 65..=90) | (97..=122, 97..=122) | (65..=90, 97..=122) | (97..=122, 65..=90) => *a | 0b00_10_00_00 == *b | 0b00_10_00_00,
-      _ => false,
-    }) {
+    if self
+      .iter()
+      .zip(t)
+      .any(|(a, b)| lowercase_byte(*a) != lowercase_byte(*b))
+    {
       CompareResult::Error
-    } else if m < blen {
+    } else if self.len() < t.len() {
+      CompareResult::Incomplete
+    } else {
+      CompareResult::Ok
+    }
+  }
+}
+
+impl<
+    T: InputLength + InputIter<Item = u8> + InputTake + UnspecializedInput,
+    O: InputLength + InputIter<Item = u8> + InputTake,
+  > Compare<O> for T
+{
+  #[inline(always)]
+  fn compare(&self, t: O) -> CompareResult {
+    let pos = self
+      .iter_elements()
+      .zip(t.iter_elements())
+      .position(|(a, b)| a != b);
+
+    match pos {
+      Some(_) => CompareResult::Error,
+      None => {
+        if self.input_len() >= t.input_len() {
+          CompareResult::Ok
+        } else {
+          CompareResult::Incomplete
+        }
+      }
+    }
+  }
+
+  #[inline(always)]
+  fn compare_no_case(&self, t: O) -> CompareResult {
+    if self
+      .iter_elements()
+      .zip(t.iter_elements())
+      .any(|(a, b)| lowercase_byte(a) != lowercase_byte(b))
+    {
+      CompareResult::Error
+    } else if self.input_len() < t.input_len() {
       CompareResult::Incomplete
     } else {
       CompareResult::Ok
@@ -722,18 +837,7 @@
 impl<'a, 'b> Compare<&'b str> for &'a str {
   #[inline(always)]
   fn compare(&self, t: &'b str) -> CompareResult {
-    let pos = self.chars().zip(t.chars()).position(|(a, b)| a != b);
-
-    match pos {
-      Some(_) => CompareResult::Error,
-      None => {
-        if self.len() >= t.len() {
-          CompareResult::Ok
-        } else {
-          CompareResult::Incomplete
-        }
-      }
-    }
+    self.as_bytes().compare(t.as_bytes())
   }
 
   //FIXME: this version is too simple and does not use the current locale
@@ -742,7 +846,7 @@
     let pos = self
       .chars()
       .zip(t.chars())
-      .position(|(a, b)| a.to_lowercase().zip(b.to_lowercase()).any(|(a, b)| a != b));
+      .position(|(a, b)| a.to_lowercase().ne(b.to_lowercase()));
 
     match pos {
       Some(_) => CompareResult::Error,
@@ -757,9 +861,20 @@
   }
 }
 
-/// look for a token in self
+impl<'a, 'b> Compare<&'b [u8]> for &'a str {
+  #[inline(always)]
+  fn compare(&self, t: &'b [u8]) -> CompareResult {
+    AsBytes::as_bytes(self).compare(t)
+  }
+  #[inline(always)]
+  fn compare_no_case(&self, t: &'b [u8]) -> CompareResult {
+    AsBytes::as_bytes(self).compare_no_case(t)
+  }
+}
+
+/// Look for a token in self
 pub trait FindToken<T> {
-  /// returns true if self contains the token
+  /// Returns true if self contains the token
   fn find_token(&self, token: T) -> bool;
 }
 
@@ -777,7 +892,7 @@
 
 impl<'a, 'b> FindToken<&'a u8> for &'b [u8] {
   fn find_token(&self, token: &u8) -> bool {
-    memchr::memchr(*token, self).is_some()
+    self.find_token(*token)
   }
 }
 
@@ -789,66 +904,53 @@
 
 impl<'a> FindToken<char> for &'a [u8] {
   fn find_token(&self, token: char) -> bool {
-    for i in self.iter() {
-      if token as u8 == *i {
-        return true;
-      }
-    }
-    false
+    self.iter().any(|i| *i == token as u8)
   }
 }
 
 impl<'a> FindToken<char> for &'a str {
   fn find_token(&self, token: char) -> bool {
-    for i in self.chars() {
-      if token == i {
-        return true;
-      }
-    }
-    false
+    self.chars().any(|i| i == token)
   }
 }
 
-/// look for a substring in self
+/// Look for a substring in self
 pub trait FindSubstring<T> {
-  /// returns the byte position of the substring if it is found
+  /// Returns the byte position of the substring if it is found
   fn find_substring(&self, substr: T) -> Option<usize>;
 }
 
 impl<'a, 'b> FindSubstring<&'b [u8]> for &'a [u8] {
   fn find_substring(&self, substr: &'b [u8]) -> Option<usize> {
-    let substr_len = substr.len();
+    if substr.len() > self.len() {
+      return None;
+    }
 
-    if substr_len == 0 {
+    let (&substr_first, substr_rest) = match substr.split_first() {
+      Some(split) => split,
       // an empty substring is found at position 0
       // This matches the behavior of str.find("").
-      Some(0)
-    } else if substr_len == 1 {
-      memchr::memchr(substr[0], self)
-    } else if substr_len > self.len() {
-      None
-    } else {
-      let max = self.len() - substr_len;
-      let mut offset = 0;
-      let mut haystack = &self[..];
+      None => return Some(0),
+    };
 
-      while let Some(position) = memchr::memchr(substr[0], haystack) {
-        offset += position;
+    if substr_rest.is_empty() {
+      return memchr::memchr(substr_first, self);
+    }
 
-        if offset > max {
-          return None;
-        }
+    let mut offset = 0;
+    let haystack = &self[..self.len() - substr_rest.len()];
 
-        if &haystack[position..position + substr_len] == substr {
-          return Some(offset);
-        }
-
-        haystack = &haystack[position + 1..];
-        offset += 1;
+    while let Some(position) = memchr::memchr(substr_first, &haystack[offset..]) {
+      offset += position;
+      let next_offset = offset + 1;
+      if &self[next_offset..][..substr_rest.len()] == substr_rest {
+        return Some(offset);
       }
 
-      None
+      offset = next_offset;
     }
+
+    None
   }
 }
 
@@ -865,10 +967,10 @@
   }
 }
 
-/// used to integrate str's parse() method
+/// Used to integrate `str`'s `parse()` method
 pub trait ParseTo<R> {
-  /// succeeds if `parse()` succeeded. The byte slice implementation
-  /// will first convert it to a &str, then apply the `parse()` function
+  /// Succeeds if `parse()` succeeded. The byte slice implementation
+  /// will first convert it to a `&str`, then apply the `parse()` function
   fn parse_to(&self) -> Option<R>;
 }
 
@@ -884,50 +986,50 @@
   }
 }
 
-/// slicing operations using ranges
+/// Slicing operations using ranges.
 ///
-/// this trait is loosely based on
+/// This trait is loosely based on
 /// `Index`, but can actually return
 /// something else than a `&[T]` or `&str`
 pub trait Slice<R> {
-  /// slices self according to the range argument
+  /// Slices self according to the range argument
   fn slice(&self, range: R) -> Self;
 }
 
 macro_rules! impl_fn_slice {
-    ( $ty:ty ) => {
-        fn slice(&self, range:$ty) -> Self {
-            &self[range]
-        }
+  ( $ty:ty ) => {
+    fn slice(&self, range: $ty) -> Self {
+      &self[range]
     }
+  };
 }
 
 macro_rules! slice_range_impl {
-    ( [ $for_type:ident ], $ty:ty ) => {
-        impl<'a, $for_type> Slice<$ty> for &'a [$for_type] {
-            impl_fn_slice!( $ty );
-        }
-    };
-    ( $for_type:ty, $ty:ty ) => {
-        impl<'a> Slice<$ty> for &'a $for_type {
-            impl_fn_slice!( $ty );
-        }
+  ( [ $for_type:ident ], $ty:ty ) => {
+    impl<'a, $for_type> Slice<$ty> for &'a [$for_type] {
+      impl_fn_slice!($ty);
     }
+  };
+  ( $for_type:ty, $ty:ty ) => {
+    impl<'a> Slice<$ty> for &'a $for_type {
+      impl_fn_slice!($ty);
+    }
+  };
 }
 
 macro_rules! slice_ranges_impl {
-    ( [ $for_type:ident ] ) => {
-        slice_range_impl! {[$for_type], Range<usize>}
-        slice_range_impl! {[$for_type], RangeTo<usize>}
-        slice_range_impl! {[$for_type], RangeFrom<usize>}
-        slice_range_impl! {[$for_type], RangeFull}
-    };
-    ( $for_type:ty ) => {
-        slice_range_impl! {$for_type, Range<usize>}
-        slice_range_impl! {$for_type, RangeTo<usize>}
-        slice_range_impl! {$for_type, RangeFrom<usize>}
-        slice_range_impl! {$for_type, RangeFull}
-    }
+  ( [ $for_type:ident ] ) => {
+    slice_range_impl! {[$for_type], Range<usize>}
+    slice_range_impl! {[$for_type], RangeTo<usize>}
+    slice_range_impl! {[$for_type], RangeFrom<usize>}
+    slice_range_impl! {[$for_type], RangeFull}
+  };
+  ( $for_type:ty ) => {
+    slice_range_impl! {$for_type, Range<usize>}
+    slice_range_impl! {$for_type, RangeTo<usize>}
+    slice_range_impl! {$for_type, RangeFrom<usize>}
+    slice_range_impl! {$for_type, RangeFull}
+  };
 }
 
 slice_ranges_impl! {str}
@@ -950,6 +1052,29 @@
         }
       }
 
+      impl<'a> InputIter for &'a [u8; $N] {
+        type Item = u8;
+        type Iter = Enumerate<Self::IterElem>;
+        type IterElem = Copied<Iter<'a, u8>>;
+
+        fn iter_indices(&self) -> Self::Iter {
+          (&self[..]).iter_indices()
+        }
+
+        fn iter_elements(&self) -> Self::IterElem {
+          (&self[..]).iter_elements()
+        }
+
+        fn position<P>(&self, predicate: P) -> Option<usize>
+          where P: Fn(Self::Item) -> bool {
+          (&self[..]).position(predicate)
+        }
+
+        fn slice_index(&self, count: usize) -> Result<usize, Needed> {
+          (&self[..]).slice_index(count)
+        }
+      }
+
       impl<'a> Compare<[u8; $N]> for &'a [u8] {
         #[inline(always)]
         fn compare(&self, t: [u8; $N]) -> CompareResult {
@@ -982,7 +1107,7 @@
 
       impl<'a> FindToken<&'a u8> for [u8; $N] {
         fn find_token(&self, token: &u8) -> bool {
-          memchr::memchr(*token, &self[..]).is_some()
+          self.find_token(*token)
         }
       }
     )+
@@ -996,21 +1121,20 @@
     30 31 32
 }
 
-/// abstracts something which can extend an `Extend`
-/// used to build modified input slices in `escaped_transform`
+/// Abstracts something which can extend an `Extend`.
+/// Used to build modified input slices in `escaped_transform`
 pub trait ExtendInto {
-
-  /// the current input type is a sequence of that `Item` type.
+  /// The current input type is a sequence of that `Item` type.
   ///
-  /// example: `u8` for `&[u8]` or `char` for &str`
+  /// Example: `u8` for `&[u8]` or `char` for `&str`
   type Item;
 
-  /// the type that will be produced
-  type Extender: Extend<Self::Item>;
+  /// The type that will be produced
+  type Extender;
 
-  /// create a new `Extend` of the correct type
+  /// Create a new `Extend` of the correct type
   fn new_builder(&self) -> Self::Extender;
-  /// accumulate the input into an accumulator
+  /// Accumulate the input into an accumulator
   fn extend_into(&self, acc: &mut Self::Extender);
 }
 
@@ -1040,11 +1164,10 @@
   }
   #[inline]
   fn extend_into(&self, acc: &mut Vec<u8>) {
-    acc.extend(self.iter().cloned());
+    acc.extend_from_slice(self);
   }
 }
 
-
 #[cfg(feature = "alloc")]
 impl ExtendInto for str {
   type Item = char;
@@ -1090,9 +1213,9 @@
   }
 }
 
-/// Helper trait to convert numbers to usize
+/// Helper trait to convert numbers to usize.
 ///
-/// by default, usize implements `From<u8>` and `From<u16>` but not
+/// By default, usize implements `From<u8>` and `From<u16>` but not
 /// `From<u32>` and `From<u64>` because that would be invalid on some
 /// platforms. This trait implements the conversion for platforms
 /// with 32 and 64 bits pointer platforms
@@ -1138,9 +1261,9 @@
   }
 }
 
-/// equivalent From implementation to avoid orphan rules in bits parsers
+/// Equivalent From implementation to avoid orphan rules in bits parsers
 pub trait ErrorConvert<E> {
-  /// transform to another error type
+  /// Transform to another error type
   fn convert(self) -> E;
 }
 
@@ -1156,6 +1279,122 @@
   }
 }
 
+use crate::error;
+impl<I> ErrorConvert<error::Error<I>> for error::Error<(I, usize)> {
+  fn convert(self) -> error::Error<I> {
+    error::Error {
+      input: self.input.0,
+      code: self.code,
+    }
+  }
+}
+
+impl<I> ErrorConvert<error::Error<(I, usize)>> for error::Error<I> {
+  fn convert(self) -> error::Error<(I, usize)> {
+    error::Error {
+      input: (self.input, 0),
+      code: self.code,
+    }
+  }
+}
+
+#[cfg(feature = "alloc")]
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+impl<I> ErrorConvert<error::VerboseError<I>> for error::VerboseError<(I, usize)> {
+  fn convert(self) -> error::VerboseError<I> {
+    error::VerboseError {
+      errors: self.errors.into_iter().map(|(i, e)| (i.0, e)).collect(),
+    }
+  }
+}
+
+#[cfg(feature = "alloc")]
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
+impl<I> ErrorConvert<error::VerboseError<(I, usize)>> for error::VerboseError<I> {
+  fn convert(self) -> error::VerboseError<(I, usize)> {
+    error::VerboseError {
+      errors: self.errors.into_iter().map(|(i, e)| ((i, 0), e)).collect(),
+    }
+  }
+}
+
+#[cfg(feature = "std")]
+#[cfg_attr(feature = "docsrs", doc(cfg(feature = "std")))]
+/// Helper trait to show a byte slice as a hex dump
+pub trait HexDisplay {
+  /// Converts the value of `self` to a hex dump, returning the owned
+  /// `String`.
+  fn to_hex(&self, chunk_size: usize) -> String;
+
+  /// Converts the value of `self` to a hex dump beginning at `from` address, returning the owned
+  /// `String`.
+  fn to_hex_from(&self, chunk_size: usize, from: usize) -> String;
+}
+
+#[cfg(feature = "std")]
+static CHARS: &[u8] = b"0123456789abcdef";
+
+#[cfg(feature = "std")]
+impl HexDisplay for [u8] {
+  #[allow(unused_variables)]
+  fn to_hex(&self, chunk_size: usize) -> String {
+    self.to_hex_from(chunk_size, 0)
+  }
+
+  #[allow(unused_variables)]
+  fn to_hex_from(&self, chunk_size: usize, from: usize) -> String {
+    let mut v = Vec::with_capacity(self.len() * 3);
+    let mut i = from;
+    for chunk in self.chunks(chunk_size) {
+      let s = format!("{:08x}", i);
+      for &ch in s.as_bytes().iter() {
+        v.push(ch);
+      }
+      v.push(b'\t');
+
+      i += chunk_size;
+
+      for &byte in chunk {
+        v.push(CHARS[(byte >> 4) as usize]);
+        v.push(CHARS[(byte & 0xf) as usize]);
+        v.push(b' ');
+      }
+      if chunk_size > chunk.len() {
+        for j in 0..(chunk_size - chunk.len()) {
+          v.push(b' ');
+          v.push(b' ');
+          v.push(b' ');
+        }
+      }
+      v.push(b'\t');
+
+      for &byte in chunk {
+        if (byte >= 32 && byte <= 126) || byte >= 128 {
+          v.push(byte);
+        } else {
+          v.push(b'.');
+        }
+      }
+      v.push(b'\n');
+    }
+
+    String::from_utf8_lossy(&v[..]).into_owned()
+  }
+}
+
+#[cfg(feature = "std")]
+impl HexDisplay for str {
+  #[allow(unused_variables)]
+  fn to_hex(&self, chunk_size: usize) -> String {
+    self.to_hex_from(chunk_size, 0)
+  }
+
+  #[allow(unused_variables)]
+  fn to_hex_from(&self, chunk_size: usize, from: usize) -> String {
+    self.as_bytes().to_hex_from(chunk_size, from)
+  }
+}
+
 #[cfg(test)]
 mod tests {
   use super::*;
diff --git a/src/util.rs b/src/util.rs
deleted file mode 100644
index 488bbfb..0000000
--- a/src/util.rs
+++ /dev/null
@@ -1,214 +0,0 @@
-#[cfg(feature = "std")]
-use crate::internal::IResult;
-#[cfg(feature = "std")]
-use std::fmt::Debug;
-
-#[cfg(feature = "std")]
-/// Helper trait to show a byte slice as a hex dump
-pub trait HexDisplay {
-  /// Converts the value of `self` to a hex dump, returning the owned
-  /// string.
-  fn to_hex(&self, chunk_size: usize) -> String;
-
-  /// Converts the value of `self` to a hex dump beginning at `from` address, returning the owned
-  /// string.
-  fn to_hex_from(&self, chunk_size: usize, from: usize) -> String;
-}
-
-#[cfg(feature = "std")]
-static CHARS: &'static [u8] = b"0123456789abcdef";
-
-#[cfg(feature = "std")]
-impl HexDisplay for [u8] {
-  #[allow(unused_variables)]
-  fn to_hex(&self, chunk_size: usize) -> String {
-    self.to_hex_from(chunk_size, 0)
-  }
-
-  #[allow(unused_variables)]
-  fn to_hex_from(&self, chunk_size: usize, from: usize) -> String {
-    let mut v = Vec::with_capacity(self.len() * 3);
-    let mut i = from;
-    for chunk in self.chunks(chunk_size) {
-      let s = format!("{:08x}", i);
-      for &ch in s.as_bytes().iter() {
-        v.push(ch);
-      }
-      v.push(b'\t');
-
-      i += chunk_size;
-
-      for &byte in chunk {
-        v.push(CHARS[(byte >> 4) as usize]);
-        v.push(CHARS[(byte & 0xf) as usize]);
-        v.push(b' ');
-      }
-      if chunk_size > chunk.len() {
-        for j in 0..(chunk_size - chunk.len()) {
-          v.push(b' ');
-          v.push(b' ');
-          v.push(b' ');
-        }
-      }
-      v.push(b'\t');
-
-      for &byte in chunk {
-        if (byte >= 32 && byte <= 126) || byte >= 128 {
-          v.push(byte);
-        } else {
-          v.push(b'.');
-        }
-      }
-      v.push(b'\n');
-    }
-
-    String::from_utf8_lossy(&v[..]).into_owned()
-  }
-}
-
-#[cfg(feature = "std")]
-impl HexDisplay for str {
-  #[allow(unused_variables)]
-  fn to_hex(&self, chunk_size: usize) -> String {
-    self.to_hex_from(chunk_size, 0)
-  }
-
-  #[allow(unused_variables)]
-  fn to_hex_from(&self, chunk_size: usize, from: usize) -> String {
-    self.as_bytes().to_hex_from(chunk_size, from)
-  }
-}
-
-#[doc(hidden)]
-#[macro_export]
-macro_rules! nom_line (
-  () => (line!());
-);
-
-#[doc(hidden)]
-#[macro_export]
-macro_rules! nom_println (
-  ($($args:tt)*) => (println!($($args)*));
-);
-
-#[doc(hidden)]
-#[macro_export]
-macro_rules! nom_stringify (
-  ($($args:tt)*) => (stringify!($($args)*));
-);
-
-
-/// Prints a message if the parser fails
-///
-/// The message prints the `Error` or `Incomplete`
-/// and the parser's calling code
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///    named!(f, dbg!( tag!( "abcd" ) ) );
-///
-///    let a = &b"efgh"[..];
-///
-///    // Will print the following message:
-///    // Error(Position(0, [101, 102, 103, 104])) at l.5 by ' tag ! ( "abcd" ) '
-///    f(a);
-/// # }
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! dbg (
-  ($i: expr, $submac:ident!( $($args:tt)* )) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      let l = nom_line!();
-      match $submac!($i, $($args)*) {
-        Err(e) => {
-          nom_println!("Err({:?}) at l.{} by ' {} '", e, l, nom_stringify!($submac!($($args)*)));
-          Err(e)
-        },
-        a => a,
-      }
-    }
-  );
-
-  ($i:expr, $f:ident) => (
-      dbg!($i, call!($f));
-  );
-);
-
-/// Prints a message and the input if the parser fails
-///
-/// The message prints the `Error` or `Incomplete`
-/// and the parser's calling code.
-///
-/// It also displays the input in hexdump format
-///
-/// ```rust
-/// use nom::{IResult, dbg_dmp, bytes::complete::tag};
-///
-/// fn f(i: &[u8]) -> IResult<&[u8], &[u8]> {
-///   dbg_dmp(tag("abcd"), "tag")(i)
-/// }
-///
-///   let a = &b"efghijkl"[..];
-///
-/// // Will print the following message:
-/// // Error(Position(0, [101, 102, 103, 104, 105, 106, 107, 108])) at l.5 by ' tag ! ( "abcd" ) '
-/// // 00000000        65 66 67 68 69 6a 6b 6c         efghijkl
-/// f(a);
-/// ```
-#[cfg(feature = "std")]
-pub fn dbg_dmp<'a, F, O, E: Debug>(f: F, context: &'static str) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], O, E>
-  where F: Fn(&'a [u8]) -> IResult<&'a [u8], O, E> {
-  move |i: &'a [u8]| {
-      match f(i) {
-        Err(e) => {
-          println!("{}: Error({:?}) at:\n{}", context, e, i.to_hex(8));
-          Err(e)
-        },
-        a => a,
-      }
-  }
-}
-
-/// Prints a message and the input if the parser fails
-///
-/// The message prints the `Error` or `Incomplete`
-/// and the parser's calling code.
-///
-/// It also displays the input in hexdump format
-///
-/// ```ignore
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-///    named!(f, dbg_dmp!( tag!( "abcd" ) ) );
-///
-///    let a = &b"efghijkl"[..];
-///
-///    // Will print the following message:
-///    // Error(Position(0, [101, 102, 103, 104, 105, 106, 107, 108])) at l.5 by ' tag ! ( "abcd" ) '
-///    // 00000000        65 66 67 68 69 6a 6b 6c         efghijkl
-///    f(a);
-/// # }
-#[macro_export(local_inner_macros)]
-#[cfg(feature = "std")]
-macro_rules! dbg_dmp (
-  ($i: expr, $submac:ident!( $($args:tt)* )) => (
-    {
-      use $crate::HexDisplay;
-      let l = nom_line!();
-      match $submac!($i, $($args)*) {
-        Err(e) => {
-          nom_println!("Error({:?}) at l.{} by ' {} '\n{}", e, l, nom_stringify!($submac!($($args)*)), $i.to_hex(8));
-          Err(e)
-        },
-        a => a,
-      }
-    }
-  );
-
-  ($i:expr, $f:ident) => (
-      dbg_dmp!($i, call!($f));
-  );
-);
-
diff --git a/src/whitespace.rs b/src/whitespace.rs
deleted file mode 100644
index 9ed3f55..0000000
--- a/src/whitespace.rs
+++ /dev/null
@@ -1,1077 +0,0 @@
-//! Support for whitespace delimited formats
-//!
-//! a lot of textual formats allows spaces and other
-//! types of separators between tokens. Handling it
-//! manually with nom means wrapping all parsers
-//! like this:
-//!
-//! ```ignore
-//! named!(token, delimited!(space, tk, space));
-//! ```
-//!
-//! To ease the development of such parsers, you
-//! can use the whitespace parsing facility, which works
-//! as follows:
-//!
-//! ```
-//! # #[macro_use] extern crate nom;
-//! # fn main() {
-//! named!(tuple<&[u8], (&[u8], &[u8]) >,
-//!   ws!(tuple!( take!(3), tag!("de") ))
-//! );
-//!
-//! assert_eq!(
-//!   tuple(&b" \t abc de fg"[..]),
-//!  Ok((&b"fg"[..], (&b"abc"[..], &b"de"[..])))
-//! );
-//! # }
-//! ```
-//!
-//! The `ws!` combinator will modify the parser to
-//! intersperse space parsers everywhere. By default,
-//! it will consume the following characters: `" \t\r\n"`.
-//!
-//! If you want to modify that behaviour, you can make
-//! your own whitespace wrapper. As an example, if
-//! you don't want to consume ends of lines, only
-//! spaces and tabs, you can do it like this:
-//!
-//! ```
-//! # #[macro_use] extern crate nom;
-//! named!(pub space, eat_separator!(&b" \t"[..]));
-//!
-//! #[macro_export]
-//! macro_rules! sp (
-//!   ($i:expr, $($args:tt)*) => (
-//!     {
-//!       use nom::Err;
-//!
-//!       match sep!($i, space, $($args)*) {
-//!         Err(e) => Err(e),
-//!         Ok((i1,o))    => {
-//!           match space(i1) {
-//!             Err(e) => Err(Err::convert(e)),
-//!             Ok((i2,_))    => Ok((i2, o))
-//!           }
-//!         }
-//!       }
-//!     }
-//!   )
-//! );
-//!
-//! # fn main() {
-//! named!(tuple<&[u8], (&[u8], &[u8]) >,
-//!   sp!(tuple!( take!(3), tag!("de") ))
-//! );
-//!
-//! assert_eq!(
-//!   tuple(&b" \t abc de fg"[..]),
-//!  Ok((&b"fg"[..], (&b"abc"[..], &b"de"[..])))
-//! );
-//! # }
-//! ```
-//!
-//! This combinator works by replacing each combinator with
-//! a version that supports wrapping with separator parsers.
-//! It will not support the combinators you wrote in your
-//! own code. You can still manually wrap them with the separator
-//! you want, or you can copy the macros defined in src/whitespace.rs
-//! and modify them to support a new combinator:
-//!
-//! * copy the combinator's code here, add the _sep suffix
-//! * add the `$separator:expr` as second argument
-//! * wrap any sub parsers with sep!($separator, $submac!($($args)*))
-//! * reference it in the definition of `sep!` as follows:
-//!
-//! ```ignore
-//!  ($i:expr,  $separator:path, my_combinator ! ($($rest:tt)*) ) => {
-//!    wrap_sep!($i,
-//!      $separator,
-//!      my_combinator_sep!($separator, $($rest)*)
-//!    )
-//!  };
-//! ```
-//!
-
-/// applies the separator parser before the other parser
-#[macro_export(local_inner_macros)]
-macro_rules! wrap_sep (
-  ($i:expr, $separator:expr, $submac:ident!( $($args:tt)* )) => ({
-    use $crate::lib::std::result::Result::*;
-    use $crate::{Err,IResult};
-
-    fn unify_types<I,O,P,E>(_: &IResult<I,O,E>, _: &IResult<I,P,E>) {}
-
-    let sep_res = ($separator)($i);
-    match sep_res {
-      Ok((i1,_))    => {
-        let res = $submac!(i1, $($args)*);
-        unify_types(&sep_res, &res);
-        res
-      },
-      Err(e) => Err(Err::convert(e)),
-    }
-  });
-  ($i:expr, $separator:expr, $f:expr) => (
-    wrap_sep!($i, $separator, call!($f))
-  );
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! pair_sep (
-  ($i:expr, $separator:path, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    tuple!(
-      $i,
-      sep!($separator, $submac!($($args)*)),
-      sep!($separator, $submac2!($($args2)*))
-    )
-  );
-  ($i:expr, $separator:path, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    pair_sep!($i, $separator, $submac!($($args)*), call!($g));
-  );
-  ($i:expr, $separator:path, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    pair_sep!($i, $separator, call!($f), $submac!($($args)*));
-  );
-  ($i:expr, $separator:path, $f:expr, $g:expr) => (
-    pair_sep!($i, $separator, call!($f), call!($g));
-  );
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! delimited_sep (
-  ($i:expr, $separator:path, $submac1:ident!( $($args1:tt)* ), $($rest:tt)+) => ({
-    use $crate::lib::std::result::Result::*;
-
-    match tuple_sep!($i, $separator, (), $submac1!($($args1)*), $($rest)+) {
-      Err(e) => Err(e),
-      Ok((remaining, (_,o,_))) => {
-        Ok((remaining, o))
-      }
-    }
-  });
-  ($i:expr, $separator:path, $f:expr, $($rest:tt)+) => (
-    delimited_sep!($i, $separator, call!($f), $($rest)+);
-  );
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! separated_pair_sep (
-  ($i:expr, $separator:path, $submac1:ident!( $($args1:tt)* ), $($rest:tt)+) => ({
-    use $crate::lib::std::result::Result::*;
-
-    match tuple_sep!($i, $separator, (), $submac1!($($args1)*), $($rest)+) {
-      Err(e) => Err(e),
-      Ok((remaining, (o1,_,o2))) => {
-        Ok((remaining, (o1,o2)))
-      }
-    }
-  });
-  ($i:expr, $separator:path, $f:expr, $($rest:tt)+) => (
-    separated_pair_sep!($i, $separator, call!($f), $($rest)+);
-  );
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! preceded_sep (
-  ($i:expr, $separator:path, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => ({
-    use $crate::lib::std::result::Result::*;
-
-    match pair_sep!($i, $separator, $submac!($($args)*), $submac2!($($args2)*)) {
-      Err(e) => Err(e),
-      Ok((remaining, (_,o))) => {
-        Ok((remaining, o))
-      }
-    }
-  });
-  ($i:expr, $separator:path, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    preceded_sep!($i, $separator, $submac!($($args)*), call!($g));
-  );
-  ($i:expr, $separator:path, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    preceded_sep!($i, $separator, call!($f), $submac!($($args)*));
-  );
-  ($i:expr, $separator:path, $f:expr, $g:expr) => (
-    preceded_sep!($i, $separator, call!($f), call!($g));
-  );
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! terminated_sep (
-  ($i:expr, $separator:path, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => ({
-    use $crate::lib::std::result::Result::*;
-
-    match pair_sep!($i, $separator, $submac!($($args)*), $submac2!($($args2)*)) {
-      Err(e) => Err(e),
-      Ok((remaining, (o,_))) => {
-        Ok((remaining, o))
-      }
-    }
-  });
-  ($i:expr, $separator:path, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    terminated_sep!($i, $separator, $submac!($($args)*), call!($g));
-  );
-  ($i:expr, $separator:path, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    terminated_sep!($i, $separator, call!($f), $submac!($($args)*));
-  );
-  ($i:expr, $separator:path, $f:expr, $g:expr) => (
-    terminated_sep!($i, $separator, call!($f), call!($g));
-  );
-);
-
-/// Internal parser, do not use directly
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! tuple_sep (
-  ($i:expr, $separator:path, ($($parsed:tt),*), $e:path, $($rest:tt)*) => (
-    tuple_sep!($i, $separator, ($($parsed),*), call!($e), $($rest)*);
-  );
-  ($i:expr, $separator:path, (), $submac:ident!( $($args:tt)* ), $($rest:tt)*) => (
-    {
-      use $crate::lib::std::result::Result::*;
-
-      match sep!($i, $separator, $submac!($($args)*)) {
-        Err(e) => Err(e),
-        Ok((i,o))     => {
-          tuple_sep!(i, $separator, (o), $($rest)*)
-        }
-      }
-    }
-  );
-  ($i:expr, $separator:path, ($($parsed:tt)*), $submac:ident!( $($args:tt)* ), $($rest:tt)*) => (
-    {
-      use $crate::lib::std::result::Result::*;
-
-      match sep!($i, $separator, $submac!($($args)*)) {
-        Err(e) => Err(e),
-        Ok((i,o))     => {
-          tuple_sep!(i, $separator, ($($parsed)* , o), $($rest)*)
-        }
-      }
-    }
-  );
-  ($i:expr, $separator:path, ($($parsed:tt),*), $e:path) => (
-    tuple_sep!($i, $separator, ($($parsed),*), call!($e));
-  );
-  ($i:expr, $separator:path, (), $submac:ident!( $($args:tt)* )) => (
-    {
-      use $crate::lib::std::result::Result::*;
-
-      match sep!($i, $separator, $submac!($($args)*)) {
-        Err(e) => Err(e),
-        Ok((i,o))     => {
-          Ok((i, (o)))
-        }
-      }
-    }
-  );
-  ($i:expr, $separator:path, ($($parsed:expr),*), $submac:ident!( $($args:tt)* )) => (
-    {
-      use $crate::lib::std::result::Result::*;
-
-      match sep!($i, $separator, $submac!($($args)*)) {
-        Err(e) => Err(e),
-        Ok((i,o))     => {
-          Ok((i, ($($parsed),* , o)))
-        }
-      }
-    }
-  );
-  ($i:expr, $separator:path, ($($parsed:expr),*)) => (
-    {
-      ::sts::result::Result::Ok(($i, ($($parsed),*)))
-    }
-  );
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! do_parse_sep (
-  (__impl $i:expr, $separator:path, ( $($rest:expr),* )) => (
-    $crate::lib::std::result::Result::Ok(($i, ( $($rest),* )))
-  );
-
-  (__impl $i:expr, $separator:path, $e:ident >> $($rest:tt)*) => (
-    do_parse_sep!(__impl $i, $separator, call!($e) >> $($rest)*);
-  );
-  (__impl $i:expr, $separator:path, $submac:ident!( $($args:tt)* ) >> $($rest:tt)*) => (
-    {
-      use $crate::lib::std::result::Result::*;
-
-      match sep!($i, $separator, $submac!($($args)*)) {
-        Err(e) => Err(e),
-        Ok((i,_))     => {
-          do_parse_sep!(__impl i, $separator, $($rest)*)
-        },
-      }
-    }
-  );
-
-  (__impl $i:expr, $separator:path, $field:ident : $e:ident >> $($rest:tt)*) => (
-    do_parse_sep!(__impl $i, $separator, $field: call!($e) >> $($rest)*);
-  );
-
-  (__impl $i:expr, $separator:path, $field:ident : $submac:ident!( $($args:tt)* ) >> $($rest:tt)*) => (
-    {
-      use $crate::lib::std::result::Result::*;
-
-      match sep!($i, $separator, $submac!($($args)*)) {
-        Err(e) => Err(e),
-        Ok((i,o))     => {
-          let $field = o;
-          do_parse_sep!(__impl i, $separator, $($rest)*)
-        },
-      }
-    }
-  );
-
-  // ending the chain
-  (__impl $i:expr, $separator:path, $e:ident >> ( $($rest:tt)* )) => (
-    do_parse_sep!(__impl $i, $separator, call!($e) >> ( $($rest)* ));
-  );
-
-  (__impl $i:expr, $separator:path, $submac:ident!( $($args:tt)* ) >> ( $($rest:tt)* )) => ({
-    use $crate::lib::std::result::Result::*;
-
-    match sep!($i, $separator, $submac!($($args)*)) {
-      Err(e) => Err(e),
-      Ok((i,_))     => {
-        Ok((i, ( $($rest)* )))
-      },
-    }
-  });
-
-  (__impl $i:expr, $separator:path, $field:ident : $e:ident >> ( $($rest:tt)* )) => (
-    do_parse_sep!(__impl $i, $separator, $field: call!($e) >> ( $($rest)* ) );
-  );
-
-  (__impl $i:expr, $separator:path, $field:ident : $submac:ident!( $($args:tt)* ) >> ( $($rest:tt)* )) => ({
-    use $crate::lib::std::result::Result::*;
-
-    match sep!($i, $separator, $submac!($($args)*)) {
-      Err(e) => Err(e),
-      Ok((i,o))     => {
-        let $field = o;
-        Ok((i, ( $($rest)* )))
-      },
-    }
-  });
-
-  ($i:expr, $separator:path, $($rest:tt)*) => (
-    {
-      do_parse_sep!(__impl $i, $separator, $($rest)*)
-    }
-  );
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! permutation_sep (
-  ($i:expr, $separator:path, $($rest:tt)*) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::lib::std::option::Option::*;
-      use $crate::{Err,error::ErrorKind};
-
-      let mut res    = permutation_init!((), $($rest)*);
-      let mut input  = $i;
-      let mut error  = None;
-      let mut needed = None;
-
-      loop {
-        let mut all_done = true;
-        permutation_iterator_sep!(0, input, $separator, all_done, needed, res, $($rest)*);
-
-        //if we reach that part, it means none of the parsers were able to read anything
-        if !all_done {
-          //FIXME: should wrap the error returned by the child parser
-          error = Option::Some(error_position!(input, ErrorKind::Permutation));
-        }
-        break;
-      }
-
-      if let Some(need) = needed {
-        Err(Err::convert(need))
-      } else {
-        if let Some(unwrapped_res) = { permutation_unwrap!(0, (), res, $($rest)*) } {
-          Ok((input, unwrapped_res))
-        } else {
-          if let Some(e) = error {
-            Err(Err::Error(error_node_position!($i, ErrorKind::Permutation, e)))
-          } else {
-            Err(Err::Error(error_position!($i, ErrorKind::Permutation)))
-          }
-        }
-      }
-    }
-  );
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! permutation_iterator_sep (
-  ($it:tt,$i:expr, $separator:path, $all_done:expr, $needed:expr, $res:expr, $e:ident?, $($rest:tt)*) => (
-    permutation_iterator_sep!($it, $i, $separator, $all_done, $needed, $res, call!($e), $($rest)*);
-  );
-  ($it:tt,$i:expr, $separator:path, $all_done:expr, $needed:expr, $res:expr, $e:ident, $($rest:tt)*) => (
-    permutation_iterator_sep!($it, $i, $separator, $all_done, $needed, $res, call!($e), $($rest)*);
-  );
-
-  ($it:tt, $i:expr, $separator:path, $all_done:expr, $needed:expr, $res:expr, $submac:ident!( $($args:tt)* )?, $($rest:tt)*) => ({
-    permutation_iterator_sep!($it, $i, $separator, $all_done, $needed, $res, $submac!($($args)*), $($rest)*);
-  });
-  ($it:tt, $i:expr, $separator:path, $all_done:expr, $needed:expr, $res:expr, $submac:ident!( $($args:tt)* ), $($rest:tt)*) => ({
-    use $crate::lib::std::result::Result::*;
-    use $crate::Err;
-
-    if $res.$it == $crate::lib::std::option::Option::None {
-      match {sep!($i, $separator, $submac!($($args)*))} {
-        Ok((i,o))     => {
-          $i = i;
-          $res.$it = $crate::lib::std::option::Option::Some(o);
-          continue;
-        },
-        Err(Err::Error(_)) => {
-          $all_done = false;
-        },
-        Err(e) => {
-          $needed = $crate::lib::std::option::Option::Some(e);
-          break;
-        }
-      };
-    }
-    succ!($it, permutation_iterator_sep!($i, $separator, $all_done, $needed, $res, $($rest)*));
-  });
-
-  ($it:tt,$i:expr, $separator:path, $all_done:expr, $needed:expr, $res:expr, $e:ident?) => (
-    permutation_iterator_sep!($it, $i, $separator, $all_done, $res, call!($e));
-  );
-  ($it:tt,$i:expr, $separator:path, $all_done:expr, $needed:expr, $res:expr, $e:ident) => (
-    permutation_iterator_sep!($it, $i, $separator, $all_done, $res, call!($e));
-  );
-
-  ($it:tt, $i:expr, $separator:path, $all_done:expr, $needed:expr, $res:expr, $submac:ident!( $($args:tt)* )?) => ({
-    permutation_iterator_sep!($it, $i, $separator, $all_done, $needed, $res, $submac!($($args)*));
-  });
-  ($it:tt, $i:expr, $separator:path, $all_done:expr, $needed:expr, $res:expr, $submac:ident!( $($args:tt)* )) => ({
-    use $crate::lib::std::result::Result::*;
-    use $crate::Err;
-
-    if $res.$it == $crate::lib::std::option::Option::None {
-      match sep!($i, $separator, $submac!($($args)*)) {
-        Ok((i,o))     => {
-          $i = i;
-          $res.$it = $crate::lib::std::option::Option::Some(o);
-          continue;
-        },
-        Err(Err::Error(_)) => {
-          $all_done = false;
-        },
-        Err(e) => {
-          $needed = $crate::lib::std::option::Option::Some(e);
-          break;
-        }
-      };
-    }
-  });
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! alt_sep (
-  (__impl $i:expr, $separator:path, $e:path | $($rest:tt)*) => (
-    alt_sep!(__impl $i, $separator, call!($e) | $($rest)*);
-  );
-
-  (__impl $i:expr, $separator:path, $subrule:ident!( $($args:tt)*) | $($rest:tt)*) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::Err;
-
-      let res = sep!($i, $separator, $subrule!($($args)*));
-      match res {
-        Ok((_,_))          => res,
-        Err(Err::Error(_)) => alt_sep!(__impl $i, $separator, $($rest)*),
-        Err(e)            => Err(e),
-      }
-    }
-  );
-
-  (__impl $i:expr, $separator:path, $subrule:ident!( $($args:tt)* ) => { $gen:expr } | $($rest:tt)+) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::Err;
-
-      match sep!($i, $separator, $subrule!( $($args)* )) {
-        Ok((i,o))               => Ok((i,$gen(o))),
-        Err(Err::Error(_))      => {
-          alt_sep!(__impl $i, $separator, $($rest)+)
-        },
-        Err(e)            => Err(e),
-      }
-    }
-  );
-
-  (__impl $i:expr, $separator:path, $e:path => { $gen:expr } | $($rest:tt)*) => (
-    alt_sep!(__impl $i, $separator, call!($e) => { $gen } | $($rest)*);
-  );
-
-  (__impl $i:expr, $separator:path, $e:path => { $gen:expr }) => (
-    alt_sep!(__impl $i, $separator, call!($e) => { $gen });
-  );
-
-  (__impl $i:expr, $separator:path, $subrule:ident!( $($args:tt)* ) => { $gen:expr }) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::Err;
-
-      match sep!($i, $separator, $subrule!( $($args)* )) {
-        Ok((i,o))     => Ok((i,$gen(o))),
-        Err(Err::Error(e))      => {
-          fn unify_types<T>(_: &T, _: &T) {}
-          let e2 = error_position!($i, $crate::error::ErrorKind::Alt);
-          unify_types(&e, &e2);
-          Err(Err::Error(e2))
-        },
-        Err(e)            => Err(e),
-      }
-    }
-  );
-
-  (__impl $i:expr, $separator:path, $e:path) => (
-    alt_sep!(__impl $i, $separator, call!($e));
-  );
-
-  (__impl $i:expr, $separator:path, $subrule:ident!( $($args:tt)*)) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::Err;
-
-      match sep!($i, $separator, $subrule!( $($args)* )) {
-        Ok((i,o))     => Ok((i,o)),
-        Err(Err::Error(e))      => {
-          fn unify_types<T>(_: &T, _: &T) {}
-          let e2 = error_position!($i, $crate::error::ErrorKind::Alt);
-          unify_types(&e, &e2);
-          Err(Err::Error(e2))
-        },
-        Err(e)            => Err(e),
-      }
-    }
-  );
-
-  (__impl $i:expr) => ({
-    use $crate::lib::std::result::Result::*;
-    use $crate::{Err,Needed,IResult};
-
-    Err(Err::Error(error_position!($i, $crate::error::ErrorKind::Alt)))
-  });
-
-  (__impl $i:expr, $separator:path) => ({
-    use $crate::lib::std::result::Result::*;
-    use $crate::{Err,Needed,IResult};
-
-    Err(Err::Error(error_position!($i, $crate::error::ErrorKind::Alt)))
-  });
-
-  ($i:expr, $separator:path, $($rest:tt)*) => (
-    {
-      alt_sep!(__impl $i, $separator, $($rest)*)
-    }
-  );
-);
-
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! switch_sep (
-  (__impl $i:expr, $separator:path, $submac:ident!( $($args:tt)* ), $($p:pat => $subrule:ident!( $($args2:tt)* ))|* ) => (
-    {
-      use $crate::lib::std::result::Result::*;
-      use $crate::Err;
-
-      match sep!($i, $separator, $submac!($($args)*)) {
-        Err(Err::Error(e))      => Err(Err::Error(error_node_position!(
-            $i, $crate::error::ErrorKind::Switch, e
-        ))),
-        Err(Err::Failure(e))    => Err(Err::Failure(
-            error_node_position!($i, $crate::error::ErrorKind::Switch, e))),
-        Err(e) => Err(e),
-        Ok((i, o))    => {
-          match o {
-            $($p => match sep!(i, $separator, $subrule!($($args2)*)) {
-              Err(Err::Error(e)) => Err(Err::Error(error_node_position!(
-                  $i, $crate::error::ErrorKind::Switch, e
-              ))),
-              Err(Err::Failure(e))    => Err(Err::Failure(
-                  error_node_position!($i, $crate::error::ErrorKind::Switch, e))),
-              a => a,
-            }),*,
-            _    => Err(Err::Error(error_position!($i, $crate::error::ErrorKind::Switch)))
-          }
-        }
-      }
-    }
-  );
-  ($i:expr, $separator:path, $submac:ident!( $($args:tt)*), $($rest:tt)*) => (
-    {
-      switch_sep!(__impl $i, $separator, $submac!($($args)*), $($rest)*)
-    }
-  );
-  ($i:expr, $separator:path, $e:path, $($rest:tt)*) => (
-    {
-      switch_sep!(__impl $i, $separator, call!($e), $($rest)*)
-    }
-  );
-);
-
-#[doc(hidden)]
-#[cfg(feature = "alloc")]
-#[macro_export(local_inner_macros)]
-macro_rules! separated_list_sep (
-  ($i:expr, $separator:path, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
-    separated_list!(
-      $i,
-      sep!($separator, $submac!($($args)*)),
-      sep!($separator, $submac2!($($args2)*))
-    )
-  );
-  ($i:expr, $separator:path, $submac:ident!( $($args:tt)* ), $g:expr) => (
-    separated_list_sep!($i, $separator, $submac!($($args)*), call!($g));
-  );
-  ($i:expr, $separator:path, $f:expr, $submac:ident!( $($args:tt)* )) => (
-    separated_list_sep!($i, $separator, call!($f), $submac!($($args)*));
-  );
-  ($i:expr, $separator:path, $f:expr, $g:expr) => (
-    separated_list_sep!($i, $separator, call!($f), call!($g));
-  );
-);
-
-/// helper macros to build a separator parser
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// named!(pub space, eat_separator!(&b" \t"[..]));
-/// # fn main() {}
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! eat_separator (
-  ($i:expr, $arr:expr) => (
-    {
-      use $crate::{FindToken, InputTakeAtPosition};
-      let input = $i;
-      input.split_at_position(|c| !$arr.find_token(c))
-    }
-  );
-);
-
-/// sep is the parser rewriting macro for whitespace separated formats
-///
-/// it takes as argument a space eating function and a parser tree,
-/// and will intersperse the space parser everywhere
-///
-/// ```ignore
-/// #[macro_export(local_inner_macros)]
-/// macro_rules! ws (
-///   ($i:expr, $($args:tt)*) => (
-///     {
-///       use sp;
-///       sep!($i, sp, $($args)*)
-///     }
-///   )
-/// );
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! sep (
-  ($i:expr,  $separator:path, tuple ! ($($rest:tt)*) ) => {
-    tuple_sep!($i, $separator, (), $($rest)*)
-  };
-  ($i:expr,  $separator:path, pair ! ($($rest:tt)*) ) => {
-    wrap_sep!($i,
-      $separator,
-      pair_sep!($separator, $($rest)*)
-    )
-  };
-  ($i:expr,  $separator:path, delimited ! ($($rest:tt)*) ) => {
-    wrap_sep!($i,
-      $separator,
-      delimited_sep!($separator, $($rest)*)
-    )
-  };
-  ($i:expr,  $separator:path, separated_pair ! ($($rest:tt)*) ) => {
-    wrap_sep!($i,
-      $separator,
-      separated_pair_sep!($separator, $($rest)*)
-    )
-  };
-  ($i:expr,  $separator:path, preceded ! ($($rest:tt)*) ) => {
-    wrap_sep!($i,
-      $separator,
-      preceded_sep!($separator, $($rest)*)
-    )
-  };
-  ($i:expr,  $separator:path, terminated ! ($($rest:tt)*) ) => {
-    wrap_sep!($i,
-      $separator,
-      terminated_sep!($separator, $($rest)*)
-    )
-  };
-  ($i:expr,  $separator:path, do_parse ! ($($rest:tt)*) ) => {
-    wrap_sep!($i,
-      $separator,
-      do_parse_sep!($separator, $($rest)*)
-    )
-  };
-  ($i:expr,  $separator:path, permutation ! ($($rest:tt)*) ) => {
-    wrap_sep!($i,
-      $separator,
-      permutation_sep!($separator, $($rest)*)
-    )
-  };
-  ($i:expr,  $separator:path, alt ! ($($rest:tt)*) ) => {
-    wrap_sep!($i,
-      $separator,
-      alt_sep!($separator, $($rest)*)
-    )
-  };
-  ($i:expr,  $separator:path, switch ! ($($rest:tt)*) ) => {
-    wrap_sep!($i,
-      $separator,
-      switch_sep!($separator, $($rest)*)
-    )
-  };
-  ($i:expr,  $separator:path, separated_list ! ($($rest:tt)*) ) => {
-    wrap_sep!($i,
-      $separator,
-      separated_list_sep!($separator, $($rest)*)
-    )
-  };
-  ($i:expr,  $separator:path, many0 ! ($($rest:tt)*) ) => {
-    many0!($i, wrap_sep!($separator, $($rest)*))
-  };
-  ($i:expr,  $separator:path, many1 ! ($($rest:tt)*) ) => {
-    many1!($i, wrap_sep!($separator, $($rest)*))
-  };
-  ($i:expr, $separator:path, return_error!( $($args:tt)* )) => {
-    return_error!($i, wrap_sep!($separator, $($args)*))
-  };
-//FIXME: missing separated_nonempty_list,
-// many_till, many_m_n, count, count_fixed, fold_many0, fold_many1,
-// fold_many_m_n
-  ($i:expr, $separator:path, $submac:ident!( $($args:tt)* )) => {
-    wrap_sep!($i, $separator, $submac!($($args)*))
-  };
-  ($i:expr, $separator:path, $f:expr) => {
-    wrap_sep!($i, $separator, call!($f))
-  };
-);
-
-/// `ws!(I -> IResult<I,O>) => I -> IResult<I, O>`
-///
-/// transforms a parser to automatically consume
-/// whitespace between each token. By default,
-/// it takes the following characters: `" \t\r\n"`.
-///
-/// If you need a whitespace parser consuming a
-/// different set of characters, you can make
-/// your own by reusing the `sep!` combinator.
-///
-/// To use `ws!`, pass your parser as argument:
-///
-/// ```
-/// # #[macro_use] extern crate nom;
-/// # fn main() {
-/// named!(tuple<&[u8], (&[u8], &[u8]) >,
-///   ws!(tuple!( take!(3), tag!("de") ))
-/// );
-///
-/// assert_eq!(
-///   tuple(&b" \t abc de fg"[..]),
-///  Ok((&b"fg"[..], (&b"abc"[..], &b"de"[..])))
-/// );
-/// # }
-/// ```
-///
-#[macro_export(local_inner_macros)]
-#[deprecated(since = "5.0.0", note = "whitespace parsing only works with macros and will not be updated anymore")]
-macro_rules! ws (
-  ($i:expr, $($args:tt)*) => (
-    {
-      use $crate::Err;
-      use $crate::lib::std::result::Result::*;
-      use $crate::character::complete::multispace0;
-
-      match sep!($i, multispace0, $($args)*) {
-        Err(e) => Err(e),
-        Ok((i1,o))    => {
-          match (multispace0)(i1) {
-            Err(e) => Err(Err::convert(e)),
-            Ok((i2,_))    => Ok((i2, o))
-          }
-        }
-      }
-    }
-  )
-);
-
-#[cfg(test)]
-#[allow(dead_code)]
-mod tests {
-  #[cfg(feature = "alloc")]
-  use crate::{
-    error::ParseError,
-    lib::std::{
-      string::{String, ToString},
-      fmt::Debug
-    }
-  };
-  use crate::internal::{Err, IResult, Needed};
-  use crate::character::complete::multispace0 as sp;
-  use crate::error::ErrorKind;
-
-  #[test]
-  fn spaaaaace() {
-    assert_eq!(sp::<_,(_,ErrorKind)>(&b" \t abc "[..]), Ok((&b"abc "[..], &b" \t "[..])));
-  }
-
-  #[test]
-  fn tag() {
-    named!(abc, ws!(tag!("abc")));
-
-    assert_eq!(abc(&b" \t abc def"[..]), Ok((&b"def"[..], &b"abc"[..])));
-  }
-
-  #[test]
-  fn pair() {
-    named!(pair_2<&[u8], (&[u8], &[u8]) >,
-      ws!(pair!( take!(3), tag!("de") ))
-    );
-
-    assert_eq!(
-      pair_2(&b" \t abc de fg"[..]),
-      Ok((&b"fg"[..], (&b"abc"[..], &b"de"[..])))
-    );
-  }
-
-  #[test]
-  fn preceded() {
-    named!(prec<&[u8], &[u8] >,
-      ws!(preceded!( take!(3), tag!("de") ))
-    );
-
-    assert_eq!(prec(&b" \t abc de fg"[..]), Ok((&b"fg"[..], &b"de"[..])));
-  }
-
-  #[test]
-  fn terminated() {
-    named!(term<&[u8], &[u8] >,
-      ws!(terminated!( take!(3), tag!("de") ))
-    );
-
-    assert_eq!(term(&b" \t abc de fg"[..]), Ok((&b"fg"[..], &b"abc"[..])));
-  }
-
-  #[test]
-  fn tuple() {
-    //trace_macros!(true);
-    named!(tuple_2<&[u8], (&[u8], &[u8]) >,
-      ws!(tuple!( take!(3), tag!("de") ))
-    );
-    //trace_macros!(false);
-
-    assert_eq!(
-      tuple_2(&b" \t abc de fg"[..]),
-      Ok((&b"fg"[..], (&b"abc"[..], &b"de"[..])))
-    );
-  }
-
-  #[test]
-  fn levels() {
-    //trace_macros!(true);
-    named!(level_2<&[u8], (&[u8], (&[u8], &[u8])) >,
-      ws!(pair!(take!(3), tuple!( tag!("de"), tag!("fg ") )))
-    );
-    //trace_macros!(false);
-
-    assert_eq!(
-      level_2(&b" \t abc de fg \t hi "[..]),
-      Ok((&b"hi "[..], (&b"abc"[..], (&b"de"[..], &b"fg "[..]))))
-    );
-  }
-
-  #[test]
-  fn do_parse() {
-    fn ret_int1(i: &[u8]) -> IResult<&[u8], u8> {
-      Ok((i, 1))
-    };
-    fn ret_int2(i: &[u8]) -> IResult<&[u8], u8> {
-      Ok((i, 2))
-    };
-
-    //trace_macros!(true);
-    named!(do_parser<&[u8], (u8, u8)>,
-      ws!(do_parse!(
-        tag!("abcd")       >>
-        opt!(tag!("abcd")) >>
-        aa: ret_int1       >>
-        tag!("efgh")       >>
-        bb: ret_int2       >>
-        tag!("efgh")       >>
-        (aa, bb)
-      ))
-    );
-
-    //trace_macros!(false);
-
-    assert_eq!(
-      do_parser(&b"abcd abcd\tefghefghX"[..]),
-      Ok((&b"X"[..], (1, 2)))
-    );
-    assert_eq!(
-      do_parser(&b"abcd\tefgh      efgh X"[..]),
-      Ok((&b"X"[..], (1, 2)))
-    );
-    assert_eq!(
-      do_parser(&b"abcd  ab"[..]),
-      Err(Err::Incomplete(Needed::Size(4)))
-    );
-    assert_eq!(
-      do_parser(&b" abcd\tefgh\tef"[..]),
-      Err(Err::Incomplete(Needed::Size(4)))
-    );
-  }
-
-  #[test]
-  fn permutation() {
-    //trace_macros!(true);
-    named!(
-      perm<(&[u8], &[u8], &[u8])>,
-      ws!(permutation!(tag!("abcd"), tag!("efg"), tag!("hi")))
-    );
-    //trace_macros!(false);
-
-    let expected = (&b"abcd"[..], &b"efg"[..], &b"hi"[..]);
-
-    let a = &b"abcd\tefg \thijk"[..];
-    assert_eq!(perm(a), Ok((&b"jk"[..], expected)));
-    let b = &b"  efg  \tabcdhi jk"[..];
-    assert_eq!(perm(b), Ok((&b"jk"[..], expected)));
-    let c = &b" hi   efg\tabcdjk"[..];
-    assert_eq!(perm(c), Ok((&b"jk"[..], expected)));
-
-    let d = &b"efg  xyzabcdefghi"[..];
-    assert_eq!(
-      perm(d),
-      Err(Err::Error(error_node_position!(
-        &b"efg  xyzabcdefghi"[..],
-        ErrorKind::Permutation,
-        error_position!(&b"  xyzabcdefghi"[..], ErrorKind::Permutation)
-      )))
-    );
-
-    let e = &b" efg \tabc"[..];
-    assert_eq!(perm(e), Err(Err::Incomplete(Needed::Size(4))));
-  }
-
-  #[cfg(feature = "alloc")]
-  #[derive(Debug, Clone, PartialEq)]
-  pub struct ErrorStr(String);
-
-  #[cfg(feature = "alloc")]
-  impl<'a> From<(&'a[u8], ErrorKind)> for ErrorStr {
-    fn from(i: (&'a[u8], ErrorKind)) -> Self {
-      ErrorStr(format!("custom error code: {:?}", i))
-    }
-  }
-
-  #[cfg(feature = "alloc")]
-  impl<'a> From<(&'a str, ErrorKind)> for ErrorStr {
-    fn from(i: (&'a str, ErrorKind)) -> Self {
-      ErrorStr(format!("custom error message: {:?}", i))
-    }
-  }
-
-  #[cfg(feature = "alloc")]
-  impl<I: Debug> ParseError<I> for ErrorStr {
-    fn from_error_kind(input: I, kind: ErrorKind) -> Self {
-      ErrorStr(format!("custom error message: ({:?}, {:?})", input, kind))
-    }
-
-    fn append(input: I, kind: ErrorKind, other: Self) -> Self {
-      ErrorStr(format!("custom error message: ({:?}, {:?}) - {:?}", input, kind, other))
-    }
-  }
-
-  #[cfg(feature = "alloc")]
-  #[test]
-  fn alt() {
-    fn work(input: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
-      Ok((&b""[..], input))
-    }
-
-    #[allow(unused_variables)]
-    fn dont_work(input: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
-      Err(Err::Error(ErrorStr("abcd".to_string())))
-    }
-
-    fn work2(input: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
-      Ok((input, &b""[..]))
-    }
-
-    fn alt1(i: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
-      alt!(i, dont_work | dont_work)
-    }
-    fn alt2(i: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
-      alt!(i, dont_work | work)
-    }
-    fn alt3(i: &[u8]) -> IResult<&[u8], &[u8], ErrorStr> {
-      alt!(i, dont_work | dont_work | work2 | dont_work)
-    }
-
-    let a = &b"\tabcd"[..];
-    assert_eq!(
-      alt1(a),
-      Err(Err::Error(error_position!(a, ErrorKind::Alt)))
-    );
-    assert_eq!(alt2(a), Ok((&b""[..], a)));
-    assert_eq!(alt3(a), Ok((a, &b""[..])));
-
-  }
-
-  named!(str_parse(&str) -> &str, ws!(tag!("test")));
-  #[allow(unused_variables)]
-  #[test]
-  fn str_test() {
-    assert_eq!(str_parse(" \n   test\t a\nb"), Ok(("a\nb", "test")));
-  }
-
-  // test whitespace parser generation for alt
-  named!(space, tag!(" "));
-  #[cfg(feature = "alloc")]
-  named!(pipeline_statement<&[u8], ()>,
-    ws!(
-      do_parse!(
-      tag!("pipeline") >>
-      attributes: delimited!(char!('{'),
-                             separated_list!(char!(','), alt!(
-                               space |
-                               space
-                             )),
-                             char!('}')) >>
-
-      ({
-        let _ = attributes;
-        ()
-      })
-    )
-  )
-  );
-
-  #[cfg(feature = "alloc")]
-  named!(
-    fail<&[u8]>,
-    map!(many_till!(take!(1), ws!(tag!("."))), |(r, _)| r[0])
-  );
-}
diff --git a/tests/arithmetic.rs b/tests/arithmetic.rs
index b3c3893..5b627a9 100644
--- a/tests/arithmetic.rs
+++ b/tests/arithmetic.rs
@@ -1,15 +1,12 @@
-extern crate nom;
-
-
 use nom::{
-  IResult,
   branch::alt,
-  combinator::map_res,
-  character::complete::char,
   bytes::complete::tag,
+  character::complete::char,
   character::complete::{digit1 as digit, space0 as space},
+  combinator::map_res,
   multi::fold_many0,
-  sequence::{delimited, pair}
+  sequence::{delimited, pair},
+  IResult,
 };
 
 // Parser definition
@@ -18,15 +15,7 @@
 
 // We parse any expr surrounded by parens, ignoring all whitespaces around those
 fn parens(i: &str) -> IResult<&str, i64> {
-  delimited(
-    space,
-    delimited(
-      tag("("),
-      expr,
-      tag(")")
-    ),
-    space
-  )(i)
+  delimited(space, delimited(tag("("), expr, tag(")")), space)(i)
 }
 
 // We transform an integer string into a i64, ignoring surrounding whitespaces
@@ -36,7 +25,7 @@
 fn factor(i: &str) -> IResult<&str, i64> {
   alt((
     map_res(delimited(space, digit, space), FromStr::from_str),
-    parens
+    parens,
   ))(i)
 }
 
@@ -48,10 +37,14 @@
 
   fold_many0(
     pair(alt((char('*'), char('/'))), factor),
-    init,
+    move || init,
     |acc, (op, val): (char, i64)| {
-        if op  == '*' { acc * val } else { acc / val }
-    }
+      if op == '*' {
+        acc * val
+      } else {
+        acc / val
+      }
+    },
   )(i)
 }
 
@@ -60,10 +53,14 @@
 
   fold_many0(
     pair(alt((char('+'), char('-'))), term),
-    init,
+    move || init,
     |acc, (op, val): (char, i64)| {
-        if op  == '+' { acc + val } else { acc - val }
-    }
+      if op == '+' {
+        acc + val
+      } else {
+        acc - val
+      }
+    },
   )(i)
 }
 
@@ -78,32 +75,20 @@
 #[test]
 fn term_test() {
   assert_eq!(term(" 12 *2 /  3"), Ok(("", 8)));
-  assert_eq!(
-    term(" 2* 3  *2 *2 /  3"),
-    Ok(("", 8))
-  );
+  assert_eq!(term(" 2* 3  *2 *2 /  3"), Ok(("", 8)));
   assert_eq!(term(" 48 /  3/2"), Ok(("", 8)));
 }
 
 #[test]
 fn expr_test() {
   assert_eq!(expr(" 1 +  2 "), Ok(("", 3)));
-  assert_eq!(
-    expr(" 12 + 6 - 4+  3"),
-    Ok(("", 17))
-  );
+  assert_eq!(expr(" 12 + 6 - 4+  3"), Ok(("", 17)));
   assert_eq!(expr(" 1 + 2*3 + 4"), Ok(("", 11)));
 }
 
 #[test]
 fn parens_test() {
   assert_eq!(expr(" (  2 )"), Ok(("", 2)));
-  assert_eq!(
-    expr(" 2* (  3 + 4 ) "),
-    Ok(("", 14))
-  );
-  assert_eq!(
-    expr("  2*2 / ( 5 - 1) + 3"),
-    Ok(("", 4))
-  );
+  assert_eq!(expr(" 2* (  3 + 4 ) "), Ok(("", 14)));
+  assert_eq!(expr("  2*2 / ( 5 - 1) + 3"), Ok(("", 4)));
 }
diff --git a/tests/arithmetic_ast.rs b/tests/arithmetic_ast.rs
index ecb8d40..ca15110 100644
--- a/tests/arithmetic_ast.rs
+++ b/tests/arithmetic_ast.rs
@@ -1,18 +1,16 @@
-extern crate nom;
-
 use std::fmt;
 use std::fmt::{Debug, Display, Formatter};
 
 use std::str::FromStr;
 
 use nom::{
-  IResult,
-  character::complete::{digit1 as digit, multispace0 as multispace},
-  sequence::{preceded, delimited},
-  combinator::{map, map_res},
-  multi::many0,
   branch::alt,
   bytes::complete::tag,
+  character::complete::{digit1 as digit, multispace0 as multispace},
+  combinator::{map, map_res},
+  multi::many0,
+  sequence::{delimited, preceded},
+  IResult,
 };
 
 pub enum Expr {
@@ -33,7 +31,7 @@
 }
 
 impl Display for Expr {
-  fn fmt(&self, format: &mut Formatter) -> fmt::Result {
+  fn fmt(&self, format: &mut Formatter<'_>) -> fmt::Result {
     use self::Expr::*;
     match *self {
       Value(val) => write!(format, "{}", val),
@@ -47,7 +45,7 @@
 }
 
 impl Debug for Expr {
-  fn fmt(&self, format: &mut Formatter) -> fmt::Result {
+  fn fmt(&self, format: &mut Formatter<'_>) -> fmt::Result {
     use self::Expr::*;
     match *self {
       Value(val) => write!(format, "{}", val),
@@ -63,25 +61,18 @@
 fn parens(i: &str) -> IResult<&str, Expr> {
   delimited(
     multispace,
-    delimited(
-      tag("("),
-      map(expr, |e| Expr::Paren(Box::new(e))),
-      tag(")")
-    ),
-    multispace
+    delimited(tag("("), map(expr, |e| Expr::Paren(Box::new(e))), tag(")")),
+    multispace,
   )(i)
 }
 
 fn factor(i: &str) -> IResult<&str, Expr> {
   alt((
     map(
-      map_res(
-        delimited(multispace, digit, multispace),
-        FromStr::from_str
-      ),
-      Expr::Value
+      map_res(delimited(multispace, digit, multispace), FromStr::from_str),
+      Expr::Value,
     ),
-    parens
+    parens,
   ))(i)
 }
 
@@ -101,14 +92,13 @@
   let (i, initial) = factor(i)?;
   let (i, remainder) = many0(alt((
     |i| {
-      let(i, mul) = preceded(tag("*"), factor)(i)?;
-      Ok((i,(Oper::Mul, mul)))
+      let (i, mul) = preceded(tag("*"), factor)(i)?;
+      Ok((i, (Oper::Mul, mul)))
     },
     |i| {
-      let(i, div) = preceded(tag("/"), factor)(i)?;
+      let (i, div) = preceded(tag("/"), factor)(i)?;
       Ok((i, (Oper::Div, div)))
     },
-
   )))(i)?;
 
   Ok((i, fold_exprs(initial, remainder)))
@@ -118,14 +108,13 @@
   let (i, initial) = term(i)?;
   let (i, remainder) = many0(alt((
     |i| {
-      let(i, add) = preceded(tag("+"), term)(i)?;
-      Ok((i,(Oper::Add, add)))
+      let (i, add) = preceded(tag("+"), term)(i)?;
+      Ok((i, (Oper::Add, add)))
     },
     |i| {
-      let(i, sub) = preceded(tag("-"), term)(i)?;
+      let (i, sub) = preceded(tag("-"), term)(i)?;
       Ok((i, (Oper::Sub, sub)))
     },
-
   )))(i)?;
 
   Ok((i, fold_exprs(initial, remainder)))
diff --git a/tests/blockbuf-arithmetic.rs b/tests/blockbuf-arithmetic.rs
deleted file mode 100644
index 27a295f..0000000
--- a/tests/blockbuf-arithmetic.rs
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
-#[macro_use]
-extern crate nom;
-extern crate bytes;
-
-use nom::{Compare,CompareResult,InputLength,InputIter,Slice,HexDisplay};
-
-use std::str;
-use std::str::FromStr;
-use bytes::{Buf,MutBuf};
-use bytes::buf::{BlockBuf,BlockBufCursor};
-use std::ops::{Range,RangeTo,RangeFrom,RangeFull};
-use std::iter::{Enumerate,Iterator};
-use std::fmt;
-use std::cmp::{min,PartialEq};
-
-#[derive(Clone,Copy)]
-#[repr(C)]
-pub struct BlockSlice<'a> {
-  buf: &'a BlockBuf,
-  start: usize,
-  end:   usize,
-}
-
-impl<'a> BlockSlice<'a> {
-  fn cursor(&self) -> WrapCursor<'a> {
-    let mut cur = self.buf.buf();
-    cur.advance(self.start);
-    WrapCursor {
-      cursor: cur,
-      length: self.end - self.start,
-    }
-  }
-}
-
-impl<'a> fmt::Debug for BlockSlice<'a> {
-  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-    write!(f, "BlockSlice {{ start: {}, end: {}, data:\n{}\n}}", self.start, self.end, self.buf.bytes().unwrap_or(&b""[..]).to_hex(16))
-  }
-}
-
-impl<'a> PartialEq for BlockSlice<'a> {
-  fn eq(&self, other: &BlockSlice<'a>) -> bool {
-    let bufs = (self.buf as *const BlockBuf) == (other.buf as *const BlockBuf);
-    self.start == other.start && self.end == other.end && bufs
-  }
-}
-
-impl<'a> Slice<Range<usize>> for BlockSlice<'a> {
-  fn slice(&self, range:Range<usize>) -> Self {
-    BlockSlice {
-      buf:   self.buf,
-      start: self.start + range.start,
-      //FIXME: check for valid end here
-      end:   self.start + range.end,
-    }
-  }
-}
-
-impl<'a> Slice<RangeTo<usize>> for BlockSlice<'a> {
-  fn slice(&self, range:RangeTo<usize>) -> Self {
-    self.slice(0..range.end)
-  }
-}
-
-impl<'a> Slice<RangeFrom<usize>> for BlockSlice<'a> {
-  fn slice(&self, range:RangeFrom<usize>) -> Self {
-    self.slice(range.start..self.end - self.start)
-  }
-}
-
-impl<'a> Slice<RangeFull> for BlockSlice<'a> {
-  fn slice(&self, _:RangeFull) -> Self {
-    BlockSlice {
-      buf:   self.buf,
-      start: self.start,
-      end:   self.end,
-    }
-  }
-}
-
-
-impl<'a> InputIter for BlockSlice<'a> {
-    type Item     = u8;
-    type RawItem  = u8;
-    type Iter     = Enumerate<WrapCursor<'a>>;
-    type IterElem = WrapCursor<'a>;
-
-    fn iter_indices(&self)  -> Self::Iter {
-      self.cursor().enumerate()
-    }
-    fn iter_elements(&self) -> Self::IterElem {
-      self.cursor()
-    }
-    fn position<P>(&self, predicate: P) -> Option<usize> where P: Fn(Self::RawItem) -> bool {
-      self.cursor().position(|b| predicate(b))
-    }
-    fn slice_index(&self, count:usize) -> Option<usize> {
-      if self.end - self.start >= count {
-        Some(count)
-      } else {
-        None
-      }
-    }
-}
-
-
-impl<'a> InputLength for BlockSlice<'a> {
-  fn input_len(&self) -> usize {
-    self.end - self.start
-  }
-}
-
-impl<'a,'b> Compare<&'b[u8]> for BlockSlice<'a> {
-  fn compare(&self, t: &'b[u8]) -> CompareResult {
-    let len     = self.end - self.start;
-    let blen    = t.len();
-    let m       = if len < blen { len } else { blen };
-    let reduced = self.slice(..m);
-    let b       = &t[..m];
-
-    for (a,b) in reduced.cursor().zip(b.iter()) {
-      if a != *b {
-        return CompareResult::Error;
-      }
-    }
-    if m < blen {
-      CompareResult::Incomplete
-    } else {
-      CompareResult::Ok
-    }
-  }
-
-
-  #[inline(always)]
-  fn compare_no_case(&self, t: &'b[u8]) -> CompareResult {
-    let len     = self.end - self.start;
-    let blen    = t.len();
-    let m       = if len < blen { len } else { blen };
-    let reduced = self.slice(..m);
-    let other   = &t[..m];
-
-    if !reduced.cursor().zip(other).all(|(a, b)| {
-      match (a,*b) {
-        (0...64, 0...64) | (91...96, 91...96) | (123...255, 123...255) => a == *b,
-        (65...90, 65...90) | (97...122, 97...122) | (65...90, 97...122 ) |(97...122, 65...90) => {
-          a & 0b01000000 == *b & 0b01000000
-        }
-        _ => false
-      }
-    }) {
-      CompareResult::Error
-    } else if m < blen {
-      CompareResult::Incomplete
-    } else {
-      CompareResult::Ok
-    }
-  }
-}
-
-impl<'a,'b> Compare<&'b str> for BlockSlice<'a> {
-  fn compare(&self, t: &'b str) -> CompareResult {
-    self.compare(str::as_bytes(t))
-  }
-  fn compare_no_case(&self, t: &'b str) -> CompareResult {
-    self.compare_no_case(str::as_bytes(t))
-  }
-}
-
-//Wrapper to implement Iterator on BlockBufCursor
-pub struct WrapCursor<'a> {
-  pub cursor: BlockBufCursor<'a>,
-  pub length: usize,
-}
-
-impl<'a> Iterator for WrapCursor<'a> {
-  type Item = u8;
-  fn next(&mut self) -> Option<u8> {
-    //println!("NEXT: length={}, remaining={}", self.length, self.cursor.remaining());
-    if min(self.length, self.cursor.remaining()) > 0 {
-      self.length -=1;
-      Some(self.cursor.read_u8())
-    } else {
-      None
-    }
-  }
-}
-
-//Reimplement eat_separator instead of fixing iterators
-#[macro_export]
-macro_rules! block_eat_separator (
-  ($i:expr, $arr:expr) => (
-    {
-      use nom::{InputLength,InputIter,Slice};
-      if ($i).input_len() == 0 {
-        Ok(($i, ($i).slice(0..0)))
-      } else {
-        match ($i).iter_indices().position(|(_, item)| {
-          for (_,c) in ($arr).iter_indices() {
-            if *c == item { return false; }
-          }
-          true
-        }) {
-          Some(index) => {
-            Ok((($i).slice(index..), ($i).slice(..index)))
-          },
-          None => {
-            Ok((($i).slice(($i).input_len()..), $i))
-          }
-        }
-      }
-    }
-  )
-);
-
-#[macro_export]
-macro_rules! block_named (
-  ($name:ident, $submac:ident!( $($args:tt)* )) => (
-    fn $name<'a>( i: BlockSlice<'a> ) -> nom::IResult<BlockSlice<'a>, BlockSlice<'a>, u32> {
-      $submac!(i, $($args)*)
-    }
-  );
-  ($name:ident<$o:ty>, $submac:ident!( $($args:tt)* )) => (
-    fn $name<'a>( i: BlockSlice<'a> ) -> nom::IResult<BlockSlice<'a>, $o, u32> {
-      $submac!(i, $($args)*)
-    }
-  );
-);
-
-block_named!(sp, block_eat_separator!(&b" \t\r\n"[..]));
-
-macro_rules! block_ws (
-  ($i:expr, $($args:tt)*) => (
-    {
-      sep!($i, sp, $($args)*)
-    }
-  )
-);
-
-block_named!(digit, is_a!("0123456789"));
-
-block_named!(parens<i64>, block_ws!(delimited!( tag!("("), expr, tag!(")") )) );
-
-
-block_named!(factor<i64>, alt!(
-      map_res!(
-        block_ws!(digit),
-        to_i64
-    )
-  | parens
-  )
-);
-
-block_named!(term <i64>, do_parse!(
-    init: factor >>
-    res:  fold_many0!(
-        pair!(alt!(tag!("*") | tag!("/")), factor),
-        init,
-        |acc, (op, val): (BlockSlice, i64)| {
-            if (op.cursor().next().unwrap() as char) == '*' { acc * val } else { acc / val }
-        }
-    ) >>
-    (res)
-  )
-);
-
-block_named!(expr <i64>, do_parse!(
-    init: term >>
-    res:  fold_many0!(
-        pair!(alt!(tag!("+") | tag!("-")), term),
-        init,
-        |acc, (op, val): (BlockSlice, i64)| {
-            if (op.cursor().next().unwrap() as char) == '+' { acc + val } else { acc - val }
-        }
-    ) >>
-    (res)
-  )
-);
-
-
-fn blockbuf_from(input: &[u8]) -> BlockBuf {
-  let mut b = BlockBuf::new(2, 100);
-  b.copy_from(input);
-  b
-}
-
-
-fn sl<'a>(input: &'a BlockBuf) -> BlockSlice<'a> {
-  BlockSlice {
-    buf: input,
-    start: 0,
-    end:   input.len(),
-  }
-}
-
-fn to_i64<'a>(input: BlockSlice<'a>) -> Result<i64, ()> {
-  let v: Vec<u8> = input.cursor().collect();
-
-  match str::from_utf8(&v) {
-    Err(_) => Err(()),
-    Ok(s) => match FromStr::from_str(s) {
-      Err(_) => Err(()),
-      Ok(i)  => Ok(i)
-    }
-  }
-}
-
-#[test]
-fn factor_test() {
-  let a = blockbuf_from(&b"3"[..]);
-  println!("calculated: {:?}", factor(sl(&a)));
-}
-
-#[test]
-fn parens_test() {
-  let input1 = blockbuf_from(&b" 2* (  3 + 4 ) "[..]);
-  println!("calculated 1: {:?}", expr(sl(&input1)));
-  let input2 = blockbuf_from(&b"  2*2 / ( 5 - 1) + 3"[..]);
-  println!("calculated 2: {:?}", expr(sl(&input2)));
-}
-*/
diff --git a/tests/css.rs b/tests/css.rs
index 0ce7e77..ad3d72b 100644
--- a/tests/css.rs
+++ b/tests/css.rs
@@ -1,9 +1,7 @@
-extern crate nom;
-
-use nom::IResult;
 use nom::bytes::complete::{tag, take_while_m_n};
 use nom::combinator::map_res;
 use nom::sequence::tuple;
+use nom::IResult;
 
 #[derive(Debug, PartialEq)]
 pub struct Color {
@@ -21,10 +19,7 @@
 }
 
 fn hex_primary(input: &str) -> IResult<&str, u8> {
-  map_res(
-    take_while_m_n(2, 2, is_hex_digit),
-    from_hex
-  )(input)
+  map_res(take_while_m_n(2, 2, is_hex_digit), from_hex)(input)
 }
 
 fn hex_color(input: &str) -> IResult<&str, Color> {
@@ -34,7 +29,6 @@
   Ok((input, Color { red, green, blue }))
 }
 
-
 #[test]
 fn parse_color() {
   assert_eq!(
diff --git a/tests/custom_errors.rs b/tests/custom_errors.rs
index 89366dc..2021713 100644
--- a/tests/custom_errors.rs
+++ b/tests/custom_errors.rs
@@ -1,14 +1,13 @@
 #![allow(dead_code)]
-#![cfg_attr(feature = "cargo-clippy", allow(block_in_if_condition_stmt))]
 
-#[macro_use]
-extern crate nom;
-
-use nom::IResult;
-use nom::error::{ErrorKind,ParseError};
+use nom::bytes::streaming::tag;
 use nom::character::streaming::digit1 as digit;
-
-use std::convert::From;
+use nom::combinator::verify;
+use nom::error::{ErrorKind, ParseError};
+#[cfg(feature = "alloc")]
+use nom::multi::count;
+use nom::sequence::terminated;
+use nom::IResult;
 
 #[derive(Debug)]
 pub struct CustomError(String);
@@ -26,28 +25,24 @@
 
   fn append(_: &'a str, kind: ErrorKind, other: CustomError) -> Self {
     CustomError(format!("{:?}\nerror code was: {:?}", other, kind))
-
   }
-
 }
 
 fn test1(input: &str) -> IResult<&str, &str, CustomError> {
   //fix_error!(input, CustomError, tag!("abcd"))
-  tag!(input, "abcd")
+  tag("abcd")(input)
 }
 
 fn test2(input: &str) -> IResult<&str, &str, CustomError> {
   //terminated!(input, test1, fix_error!(CustomError, digit))
-  terminated!(input, test1, digit)
+  terminated(test1, digit)(input)
 }
 
 fn test3(input: &str) -> IResult<&str, &str, CustomError> {
-  verify!(input, test1, |s: &str| {
-    s.starts_with("abcd")
-  })
+  verify(test1, |s: &str| s.starts_with("abcd"))(input)
 }
 
 #[cfg(feature = "alloc")]
 fn test4(input: &str) -> IResult<&str, Vec<&str>, CustomError> {
-  count!(input, test1, 4)
+  count(test1, 4)(input)
 }
diff --git a/tests/escaped.rs b/tests/escaped.rs
index 19c1ed7..47c6a71 100644
--- a/tests/escaped.rs
+++ b/tests/escaped.rs
@@ -1,25 +1,28 @@
-use nom::{Err, error::ErrorKind, IResult};
-use nom::character::complete::digit1;
 use nom::bytes::complete::escaped;
+use nom::character::complete::digit1;
 use nom::character::complete::one_of;
+use nom::{error::ErrorKind, Err, IResult};
 
-fn esc(s: &str) -> IResult<&str, &str> {
-    escaped(digit1, '\\', one_of("\"n\\"))(s)
+fn esc(s: &str) -> IResult<&str, &str, (&str, ErrorKind)> {
+  escaped(digit1, '\\', one_of("\"n\\"))(s)
 }
 
-#[cfg(feature="alloc")]
-fn esc_trans(s: &str) -> IResult<&str, String> {
-    use nom::bytes::complete::{escaped_transform, tag};
-    escaped_transform(digit1, '\\', |i: &str| tag("n")(i))(s)
+#[cfg(feature = "alloc")]
+fn esc_trans(s: &str) -> IResult<&str, String, (&str, ErrorKind)> {
+  use nom::bytes::complete::{escaped_transform, tag};
+  escaped_transform(digit1, '\\', tag("n"))(s)
 }
 
 #[test]
 fn test_escaped() {
-    assert_eq!(esc("abcd"), Err(Err::Error(("abcd", ErrorKind::Escaped))));
+  assert_eq!(esc("abcd"), Err(Err::Error(("abcd", ErrorKind::Escaped))));
 }
 
 #[test]
-#[cfg(feature="alloc")]
+#[cfg(feature = "alloc")]
 fn test_escaped_transform() {
-    assert_eq!(esc_trans("abcd"), Err(Err::Error(("abcd", ErrorKind::EscapedTransform))));
+  assert_eq!(
+    esc_trans("abcd"),
+    Err(Err::Error(("abcd", ErrorKind::EscapedTransform)))
+  );
 }
diff --git a/tests/float.rs b/tests/float.rs
index eb82804..634b189 100644
--- a/tests/float.rs
+++ b/tests/float.rs
@@ -1,33 +1,33 @@
-#[macro_use]
-extern crate nom;
-
+use nom::branch::alt;
+use nom::bytes::complete::tag;
 use nom::character::streaming::digit1 as digit;
+use nom::combinator::{map, map_res, opt, recognize};
+use nom::sequence::{delimited, pair};
+use nom::IResult;
 
 use std::str;
 use std::str::FromStr;
 
-named!(
-  unsigned_float<f32>,
-  map_res!(
-    map_res!(
-      recognize!(alt!(
-        delimited!(digit, tag!("."), opt!(digit)) | delimited!(opt!(digit), tag!("."), digit)
-      )),
-      str::from_utf8
-    ),
-    FromStr::from_str
-  )
-);
+fn unsigned_float(i: &[u8]) -> IResult<&[u8], f32> {
+  let float_bytes = recognize(alt((
+    delimited(digit, tag("."), opt(digit)),
+    delimited(opt(digit), tag("."), digit),
+  )));
+  let float_str = map_res(float_bytes, str::from_utf8);
+  map_res(float_str, FromStr::from_str)(i)
+}
 
-named!(
-  float<f32>,
-  map!(
-    pair!(opt!(alt!(tag!("+") | tag!("-"))), unsigned_float),
-    |(sign, value): (Option<&[u8]>, f32)| sign
-      .and_then(|s| if s[0] == b'-' { Some(-1f32) } else { None })
-      .unwrap_or(1f32) * value
-  )
-);
+fn float(i: &[u8]) -> IResult<&[u8], f32> {
+  map(
+    pair(opt(alt((tag("+"), tag("-")))), unsigned_float),
+    |(sign, value)| {
+      sign
+        .and_then(|s| if s[0] == b'-' { Some(-1f32) } else { None })
+        .unwrap_or(1f32)
+        * value
+    },
+  )(i)
+}
 
 #[test]
 fn unsigned_float_test() {
diff --git a/tests/fnmut.rs b/tests/fnmut.rs
new file mode 100644
index 0000000..b1486cb
--- /dev/null
+++ b/tests/fnmut.rs
@@ -0,0 +1,39 @@
+use nom::{
+  bytes::complete::tag,
+  multi::{many0, many0_count},
+};
+
+#[test]
+fn parse() {
+  let mut counter = 0;
+
+  let res = {
+    let mut parser = many0::<_, _, (), _>(|i| {
+      counter += 1;
+      tag("abc")(i)
+    });
+
+    parser("abcabcabcabc").unwrap()
+  };
+
+  println!("res: {:?}", res);
+  assert_eq!(counter, 5);
+}
+
+#[test]
+fn accumulate() {
+  let mut v = Vec::new();
+
+  let (_, count) = {
+    let mut parser = many0_count::<_, _, (), _>(|i| {
+      let (i, o) = tag("abc")(i)?;
+      v.push(o);
+      Ok((i, ()))
+    });
+    parser("abcabcabcabc").unwrap()
+  };
+
+  println!("v: {:?}", v);
+  assert_eq!(count, 4);
+  assert_eq!(v.len(), 4);
+}
diff --git a/tests/inference.rs b/tests/inference.rs
deleted file mode 100644
index 851c138..0000000
--- a/tests/inference.rs
+++ /dev/null
@@ -1,53 +0,0 @@
-//! test type inference issues in parsee compilation
-//#![feature(trace_macros)]
-#![allow(dead_code)]
-#![allow(unused_comparisons)]
-#![allow(unused_variables)]
-#![allow(unused_imports)]
-
-#[macro_use]
-extern crate nom;
-
-use std::str;
-use nom::character::{streaming::alpha1 as alpha, is_digit};
-
-// issue #617
-named!(multi<&[u8], () >, fold_many0!( take_while1!( is_digit ), (), |_, _| {}));
-
-// issue #561
-#[cfg(feature = "alloc")]
-named!(
-  value<Vec<Vec<&str>>>,
-  do_parse!(
-    first_line: map_res!(is_not!("\n"), std::str::from_utf8)
-      >> rest:
-        many_m_n!(
-          0,
-          1,
-          separated_list!(
-            tag!("\n\t"),
-            map_res!(take_while!(call!(|c| c != b'\n')), std::str::from_utf8)
-          )
-        ) >> (rest)
-  )
-);
-
-// issue #534
-#[cfg(feature = "alloc")]
-fn wrap_suffix(input: &Option<Vec<&[u8]>>) -> Option<String> {
-  if input.is_some() {
-    // I've tried both of the lines below individually and get the same error.
-    Some("hello".to_string())
-  //Some(str::from_utf8(u).expect("Found invalid UTF-8").to_string())
-  } else {
-    None
-  }
-}
-
-#[cfg(feature = "alloc")]
-named!(parse_suffix<&[u8],Option<String>>,do_parse!(
-  u: opt!(many1!(alt!(
-    complete!(tag!("%")) | complete!(tag!("#"))  | complete!(tag!("@")) | complete!(alpha)
-  ))) >>
-  (wrap_suffix(&u))
-));
diff --git a/tests/ini.rs b/tests/ini.rs
index c3f9b75..e556f44 100644
--- a/tests/ini.rs
+++ b/tests/ini.rs
@@ -1,71 +1,57 @@
-#[macro_use]
-extern crate nom;
-
 use nom::{
-  IResult,
   bytes::complete::take_while,
-  sequence::delimited,
-  combinator::map_res,
-  character::complete::{char, alphanumeric1 as alphanumeric, multispace0 as multispace, space0 as space}
+  character::complete::{
+    alphanumeric1 as alphanumeric, char, multispace0 as multispace, space0 as space,
+  },
+  combinator::{map, map_res, opt},
+  multi::many0,
+  sequence::{delimited, pair, separated_pair, terminated, tuple},
+  IResult,
 };
 
-use std::str;
 use std::collections::HashMap;
+use std::str;
 
 fn category(i: &[u8]) -> IResult<&[u8], &str> {
-  map_res(delimited(char('['), take_while(|c| c != b']'), char(']')), str::from_utf8)(i)
+  map_res(
+    delimited(char('['), take_while(|c| c != b']'), char(']')),
+    str::from_utf8,
+  )(i)
 }
 
-fn complete_byte_slice_to_str<'a>(s: &'a[u8]) -> Result<&'a str, str::Utf8Error> {
-  str::from_utf8(s)
+fn key_value(i: &[u8]) -> IResult<&[u8], (&str, &str)> {
+  let (i, key) = map_res(alphanumeric, str::from_utf8)(i)?;
+  let (i, _) = tuple((opt(space), char('='), opt(space)))(i)?;
+  let (i, val) = map_res(take_while(|c| c != b'\n' && c != b';'), str::from_utf8)(i)?;
+  let (i, _) = opt(pair(char(';'), take_while(|c| c != b'\n')))(i)?;
+  Ok((i, (key, val)))
 }
 
-named!(key_value    <&[u8],(&str,&str)>,
-  do_parse!(
-     key: map_res!(alphanumeric, complete_byte_slice_to_str)
-  >>      opt!(space)
-  >>      char!('=')
-  >>      opt!(space)
-  >> val: map_res!(
-           take_while!(call!(|c| c != b'\n' && c != b';')),
-           complete_byte_slice_to_str
-         )
-  >>      opt!(pair!(char!(';'), take_while!(call!(|c| c != b'\n'))))
-  >>      (key, val)
-  )
-);
+fn keys_and_values(i: &[u8]) -> IResult<&[u8], HashMap<&str, &str>> {
+  map(many0(terminated(key_value, opt(multispace))), |vec| {
+    vec.into_iter().collect()
+  })(i)
+}
 
-named!(keys_and_values<&[u8], HashMap<&str, &str> >,
-  map!(
-    many0!(terminated!(key_value, opt!(multispace))),
-    |vec: Vec<_>| vec.into_iter().collect()
-  )
-);
+fn category_and_keys(i: &[u8]) -> IResult<&[u8], (&str, HashMap<&str, &str>)> {
+  let (i, category) = terminated(category, opt(multispace))(i)?;
+  let (i, keys) = keys_and_values(i)?;
+  Ok((i, (category, keys)))
+}
 
-named!(category_and_keys<&[u8],(&str,HashMap<&str,&str>)>,
-  do_parse!(
-    category: category         >>
-              opt!(multispace) >>
-    keys: keys_and_values      >>
-    (category, keys)
-  )
-);
-
-named!(categories<&[u8], HashMap<&str, HashMap<&str,&str> > >,
-  map!(
-    many0!(
-      separated_pair!(
-        category,
-        opt!(multispace),
-        map!(
-          many0!(terminated!(key_value, opt!(multispace))),
-          |vec: Vec<_>| vec.into_iter().collect()
-        )
-      )
-    ),
-    |vec: Vec<_>| vec.into_iter().collect()
-  )
-);
+fn categories(i: &[u8]) -> IResult<&[u8], HashMap<&str, HashMap<&str, &str>>> {
+  map(
+    many0(separated_pair(
+      category,
+      opt(multispace),
+      map(
+        many0(terminated(key_value, opt(multispace))),
+        |vec: Vec<_>| vec.into_iter().collect(),
+      ),
+    )),
+    |vec: Vec<_>| vec.into_iter().collect(),
+  )(i)
+}
 
 #[test]
 fn parse_category_test() {
diff --git a/tests/ini_str.rs b/tests/ini_str.rs
index d778918..3702303 100644
--- a/tests/ini_str.rs
+++ b/tests/ini_str.rs
@@ -1,12 +1,10 @@
-#[macro_use]
-extern crate nom;
-
 use nom::{
-  IResult,
+  bytes::complete::{is_a, tag, take_till, take_while},
+  character::complete::{alphanumeric1 as alphanumeric, char, space0 as space},
   combinator::opt,
-  bytes::complete::{take_while, is_a},
-  sequence::{delimited, terminated},
-  character::complete::{char, alphanumeric1 as alphanumeric, space0 as space}
+  multi::many0,
+  sequence::{delimited, pair, terminated, tuple},
+  IResult,
 };
 
 use std::collections::HashMap;
@@ -24,24 +22,26 @@
 }
 
 fn category(i: &str) -> IResult<&str, &str> {
-  terminated(delimited(char('['), take_while(|c| c != ']'), char(']')), opt(is_a(" \r\n")))(i)
+  terminated(
+    delimited(char('['), take_while(|c| c != ']'), char(']')),
+    opt(is_a(" \r\n")),
+  )(i)
 }
 
-named!(key_value    <&str,(&str,&str)>,
-  do_parse!(
-    key: alphanumeric                              >>
-         opt!(space)                               >>
-         tag!("=")                               >>
-         opt!(space)                               >>
-    val: take_till!(is_line_ending_or_comment)   >>
-         opt!(space)                               >>
-         opt!(pair!(tag!(";"), not_line_ending)) >>
-         opt!(space_or_line_ending)                >>
-    (key, val)
-  )
-);
+fn key_value(i: &str) -> IResult<&str, (&str, &str)> {
+  let (i, key) = alphanumeric(i)?;
+  let (i, _) = tuple((opt(space), tag("="), opt(space)))(i)?;
+  let (i, val) = take_till(is_line_ending_or_comment)(i)?;
+  let (i, _) = opt(space)(i)?;
+  let (i, _) = opt(pair(tag(";"), not_line_ending))(i)?;
+  let (i, _) = opt(space_or_line_ending)(i)?;
 
-named!(keys_and_values_aggregator<&str, Vec<(&str, &str)> >, many0!(key_value));
+  Ok((i, (key, val)))
+}
+
+fn keys_and_values_aggregator(i: &str) -> IResult<&str, Vec<(&str, &str)>> {
+  many0(key_value)(i)
+}
 
 fn keys_and_values(input: &str) -> IResult<&str, HashMap<&str, &str>> {
   match keys_and_values_aggregator(input) {
@@ -50,11 +50,13 @@
   }
 }
 
-named!(category_and_keys<&str,(&str,HashMap<&str,&str>)>,
-  pair!(category, keys_and_values)
-);
+fn category_and_keys(i: &str) -> IResult<&str, (&str, HashMap<&str, &str>)> {
+  pair(category, keys_and_values)(i)
+}
 
-named!(categories_aggregator<&str, Vec<(&str, HashMap<&str,&str>)> >, many0!(category_and_keys));
+fn categories_aggregator(i: &str) -> IResult<&str, Vec<(&str, HashMap<&str, &str>)>> {
+  many0(category_and_keys)(i)
+}
 
 fn categories(input: &str) -> IResult<&str, HashMap<&str, HashMap<&str, &str>>> {
   match categories_aggregator(input) {
diff --git a/tests/issues.rs b/tests/issues.rs
index 62a1a01..6df183b 100644
--- a/tests/issues.rs
+++ b/tests/issues.rs
@@ -2,10 +2,7 @@
 #![allow(dead_code)]
 #![cfg_attr(feature = "cargo-clippy", allow(redundant_closure))]
 
-#[macro_use]
-extern crate nom;
-
-use nom::{character::{is_digit, streaming::space1 as space}, Err, IResult, Needed, error::ErrorKind, number::streaming::le_u64};
+use nom::{error::ErrorKind, Err, IResult, Needed};
 
 #[allow(dead_code)]
 struct Range {
@@ -17,77 +14,40 @@
   if !input.is_empty() {
     Ok((&input[1..], input[0] as char))
   } else {
-    Err(Err::Incomplete(Needed::Size(1)))
+    Err(Err::Incomplete(Needed::new(1)))
   }
 }
 
-//trace_macros!(true);
-
-#[allow(dead_code)]
-named!(range<&[u8], Range>,
-    alt!(
-        do_parse!(
-            start: take_char >>
-            tag!("-")        >>
-            end: take_char   >>
-            (Range {
-                start: start,
-                end:   end,
-            })
-        ) |
-        map!(
-            take_char,
-            |c| {
-                Range {
-                    start: c,
-                    end:   c,
-                }
-            }
-        )
-    )
-);
-
-#[allow(dead_code)]
-named!(literal<&[u8], Vec<char> >,
-    map!(
-        many1!(take_char),
-        |cs| {
-          cs
-        }
-    )
-);
-
-#[test]
-fn issue_58() {
-  let _ = range(&b"abcd"[..]);
-  let _ = literal(&b"abcd"[..]);
-}
-
-//trace_macros!(false);
-
 #[cfg(feature = "std")]
 mod parse_int {
   use nom::HexDisplay;
-  use nom::{IResult, character::streaming::{digit1 as digit, space1 as space}};
+  use nom::{
+    character::streaming::{digit1 as digit, space1 as space},
+    combinator::{complete, map, opt},
+    multi::many0,
+    IResult,
+  };
   use std::str;
 
-  named!(parse_ints<Vec<i32>>, many0!(spaces_or_int));
+  fn parse_ints(input: &[u8]) -> IResult<&[u8], Vec<i32>> {
+    many0(spaces_or_int)(input)
+  }
 
   fn spaces_or_int(input: &[u8]) -> IResult<&[u8], i32> {
     println!("{}", input.to_hex(8));
-    do_parse!(
-      input,
-      opt!(complete!(space)) >> res: map!(complete!(digit), |x| {
-        println!("x: {:?}", x);
-        let result = str::from_utf8(x).unwrap();
-        println!("Result: {}", result);
-        println!("int is empty?: {}", x.is_empty());
-        match result.parse() {
-          Ok(i) => i,
-          Err(e) => panic!("UH OH! NOT A DIGIT! {:?}", e),
-        }
-      }) >> (res)
-    )
+    let (i, _) = opt(complete(space))(input)?;
+    let (i, res) = map(complete(digit), |x| {
+      println!("x: {:?}", x);
+      let result = str::from_utf8(x).unwrap();
+      println!("Result: {}", result);
+      println!("int is empty?: {}", x.is_empty());
+      match result.parse() {
+        Ok(i) => i,
+        Err(e) => panic!("UH OH! NOT A DIGIT! {:?}", e),
+      }
+    })(i)?;
+
+    Ok((i, res))
   }
 
   #[test]
@@ -104,67 +64,34 @@
 
 #[test]
 fn usize_length_bytes_issue() {
+  use nom::multi::length_data;
   use nom::number::streaming::be_u16;
-  let _: IResult<&[u8], &[u8], (&[u8], ErrorKind)> = length_data!(b"012346", be_u16);
+  let _: IResult<&[u8], &[u8], (&[u8], ErrorKind)> = length_data(be_u16)(b"012346");
 }
 
-/*
- DOES NOT COMPILE
-#[test]
-fn issue_152() {
-  named!(take4, take!(4));
-  named!(xyz, tag!("XYZ"));
-  named!(abc, tag!("abc"));
-
-
-  named!(sw,
-    switch!(take4,
-      b"abcd" => xyz |
-      b"efgh" => abc
-    )
-  );
-}
-*/
-
 #[test]
 fn take_till_issue() {
-  named!(nothing, take_till!(call!(|_| true)));
+  use nom::bytes::streaming::take_till;
 
-  assert_eq!(nothing(b""), Err(Err::Incomplete(Needed::Size(1))));
+  fn nothing(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    take_till(|_| true)(i)
+  }
+
+  assert_eq!(nothing(b""), Err(Err::Incomplete(Needed::new(1))));
   assert_eq!(nothing(b"abc"), Ok((&b"abc"[..], &b""[..])));
 }
 
-named!(
-  issue_498<Vec<&[u8]>>,
-  separated_nonempty_list!(opt!(space), tag!("abcd"))
-);
-
-named!(issue_308(&str) -> bool,
-    do_parse! (
-        tag! ("foo") >>
-        b: alt! (
-            complete!(map! (tag! ("1"), |_: &str|->bool {true})) |
-            value! (false)
-        ) >>
-        (b) ));
-
-#[cfg(feature = "alloc")]
-fn issue_302(input: &[u8]) -> IResult<&[u8], Option<Vec<u64>>> {
-  do_parse!(input, entries: cond!(true, count!(le_u64, 3)) >> (entries))
-}
-
 #[test]
 fn issue_655() {
   use nom::character::streaming::{line_ending, not_line_ending};
-  named!(twolines(&str) -> (&str, &str),
-    do_parse!(
-      l1 : not_line_ending >>
-           line_ending >>
-      l2 : not_line_ending >>
-           line_ending >>
-      ((l1, l2))
-    )
-  );
+  fn twolines(i: &str) -> IResult<&str, (&str, &str)> {
+    let (i, l1) = not_line_ending(i)?;
+    let (i, _) = line_ending(i)?;
+    let (i, l2) = not_line_ending(i)?;
+    let (i, _) = line_ending(i)?;
+
+    Ok((i, (l1, l2)))
+  }
 
   assert_eq!(twolines("foo\nbar\n"), Ok(("", ("foo", "bar"))));
   assert_eq!(twolines("féo\nbar\n"), Ok(("", ("féo", "bar"))));
@@ -172,119 +99,68 @@
   assert_eq!(twolines("foé\r\nbar\n"), Ok(("", ("foé", "bar"))));
 }
 
-#[test]
-fn issue_721() {
-  named!(f1<&str, u16>, parse_to!(u16));
-  named!(f2<&str, String>, parse_to!(String));
-  assert_eq!(f1("1234"), Ok(("", 1234)));
-  assert_eq!(f2("foo"), Ok(("", "foo".to_string())));
-  //assert_eq!(parse_to!("1234", u16), Ok(("", 1234)));
-  //assert_eq!(parse_to!("foo", String), Ok(("", "foo".to_string())));
-}
-
 #[cfg(feature = "alloc")]
-named!(issue_717<&[u8], Vec<&[u8]> >,
-  separated_list!(tag!([0x0]), is_not!([0x0u8]))
-);
+fn issue_717(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+  use nom::bytes::complete::{is_not, tag};
+  use nom::multi::separated_list0;
 
-struct NoPartialEq {
-  value: i32,
+  separated_list0(tag([0x0]), is_not([0x0u8]))(i)
 }
 
-named!(issue_724<&str, i32>,
-  do_parse!(
-    metadata: permutation!(
-      map!(tag!("hello"), |_| NoPartialEq { value: 1 }),
-      map!(tag!("world"), |_| NoPartialEq { value: 2 })
-    ) >>
-    (metadata.0.value + metadata.1.value)
-  )
-);
-
-#[test]
-fn issue_752() {
-    assert_eq!(
-        Err::Error(("ab", nom::error::ErrorKind::ParseTo)),
-        parse_to!("ab", usize).unwrap_err()
-    )
-}
-
-fn atom_specials(c: u8) -> bool {
-    c == b'q'
-}
-
-named!(
-    capability<&str>,
-    do_parse!(tag!(" ") >> _atom: map_res!(take_till1!(atom_specials), std::str::from_utf8) >> ("a"))
-);
-
-#[test]
-fn issue_759() {
-    assert_eq!(capability(b" abcqd"), Ok((&b"qd"[..], "a")));
-}
-
-named_args!(issue_771(count: usize)<Vec<u32>>,
-  length_count!(value!(count), call!(nom::number::streaming::be_u32))
-);
-
-/// This test is in a separate module to check that all required symbols are imported in
-/// `escaped_transform!()`. Without the module, the `use`-es of the current module would
-/// mask the error ('"Use of undeclared type or module `Needed`" in escaped_transform!').
-mod issue_780 {
-  named!(issue_780<&str, String>,
-    escaped_transform!(call!(::nom::character::streaming::alpha1), '\\', tag!("n"))
-  );
-}
-
-// issue 617
-named!(digits, take_while1!( is_digit ));
-named!(multi_617<&[u8], () >, fold_many0!( digits, (), |_, _| {}));
-
-// Sad :(
-named!(multi_617_fails<&[u8], () >, fold_many0!( take_while1!( is_digit ), (), |_, _| {}));
-
 mod issue_647 {
-  use nom::{Err, number::streaming::be_f64, error::ErrorKind};
+  use nom::bytes::streaming::tag;
+  use nom::combinator::complete;
+  use nom::multi::separated_list0;
+  use nom::{error::Error, number::streaming::be_f64, Err, IResult};
   pub type Input<'a> = &'a [u8];
 
   #[derive(PartialEq, Debug, Clone)]
   struct Data {
-      c: f64,
-      v: Vec<f64>
+    c: f64,
+    v: Vec<f64>,
   }
 
-  fn list<'a,'b>(input: Input<'a>, _cs: &'b f64) -> Result<(Input<'a>,Vec<f64>), Err<(&'a [u8], ErrorKind)>> {
-      separated_list!(input, complete!(tag!(",")), complete!(be_f64))
+  fn list<'a, 'b>(
+    input: Input<'a>,
+    _cs: &'b f64,
+  ) -> Result<(Input<'a>, Vec<f64>), Err<Error<&'a [u8]>>> {
+    separated_list0(complete(tag(",")), complete(be_f64))(input)
   }
 
-  named!(data<Input,Data>, map!(
-      do_parse!(
-          c: be_f64 >>
-          tag!("\n") >>
-          v: call!(list,&c) >>
-          (c,v)
-      ), |(c,v)| {
-          Data {
-              c: c,
-              v: v
-          }
-      }
-  ));
+  fn data(input: Input<'_>) -> IResult<Input<'_>, Data> {
+    let (i, c) = be_f64(input)?;
+    let (i, _) = tag("\n")(i)?;
+    let (i, v) = list(i, &c)?;
+    Ok((i, Data { c, v }))
+  }
 }
 
-named!(issue_775, take_till1!(|_| true));
-
 #[test]
 fn issue_848_overflow_incomplete_bits_to_bytes() {
-  named!(take, take!(0x2000000000000000));
-  named!(parser<&[u8], &[u8]>, bits!(bytes!(take)));
-  assert_eq!(parser(&b""[..]), Err(Err::Failure(error_position!(&b""[..], ErrorKind::TooLarge))));
+  fn take(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    use nom::bytes::streaming::take;
+    take(0x2000000000000000_usize)(i)
+  }
+  fn parser(i: &[u8]) -> IResult<&[u8], &[u8]> {
+    use nom::bits::{bits, bytes};
+
+    bits(bytes(take))(i)
+  }
+  assert_eq!(
+    parser(&b""[..]),
+    Err(Err::Failure(nom::error_position!(
+      &b""[..],
+      ErrorKind::TooLarge
+    )))
+  );
 }
 
 #[test]
 fn issue_942() {
-  use nom::error::ParseError;
-  pub fn parser<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, usize, E> {
+  use nom::error::{ContextError, ParseError};
+  pub fn parser<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
+    i: &'a str,
+  ) -> IResult<&'a str, usize, E> {
     use nom::{character::complete::char, error::context, multi::many0_count};
     many0_count(context("char_a", char('a')))(i)
   }
@@ -293,17 +169,17 @@
 
 #[test]
 fn issue_many_m_n_with_zeros() {
-    use nom::multi::many_m_n;
-    use nom::character::complete::char;
-    let parser = many_m_n::<_, _, (), _>(0, 0, char('a'));
-    assert_eq!(parser("aaa"), Ok(("aaa", vec!())));
+  use nom::character::complete::char;
+  use nom::multi::many_m_n;
+  let mut parser = many_m_n::<_, _, (), _>(0, 0, char('a'));
+  assert_eq!(parser("aaa"), Ok(("aaa", vec![])));
 }
 
 #[test]
 fn issue_1027_convert_error_panic_nonempty() {
-  use nom::error::{VerboseError, convert_error};
-  use nom::sequence::pair;
   use nom::character::complete::char;
+  use nom::error::{convert_error, VerboseError};
+  use nom::sequence::pair;
 
   let input = "a";
 
@@ -313,6 +189,20 @@
     _ => unreachable!(),
   };
 
-  let msg = convert_error(&input, err);
-  assert_eq!(msg, "0: at line 1:\na\n ^\nexpected \'b\', got end of input\n\n");
+  let msg = convert_error(input, err);
+  assert_eq!(
+    msg,
+    "0: at line 1:\na\n ^\nexpected \'b\', got end of input\n\n"
+  );
+}
+
+#[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))));
 }
diff --git a/tests/json.rs b/tests/json.rs
index 14329a1..e8a06fd 100644
--- a/tests/json.rs
+++ b/tests/json.rs
@@ -1,105 +1,236 @@
 #![cfg(feature = "alloc")]
-//#![feature(trace_macros)]
 
-#[macro_use]
-extern crate nom;
+use nom::{
+  branch::alt,
+  bytes::complete::{tag, take},
+  character::complete::{anychar, char, multispace0, none_of},
+  combinator::{map, map_opt, map_res, value, verify},
+  error::ParseError,
+  multi::{fold_many0, separated_list0},
+  number::complete::double,
+  sequence::{delimited, preceded, separated_pair},
+  IResult, Parser,
+};
 
-use nom::{character::is_alphanumeric, number::complete::recognize_float};
-
-use std::str;
 use std::collections::HashMap;
 
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Clone)]
 pub enum JsonValue {
+  Null,
+  Bool(bool),
   Str(String),
-  Num(f32),
+  Num(f64),
   Array(Vec<JsonValue>),
   Object(HashMap<String, JsonValue>),
 }
 
-named!(float<f32>, flat_map!(recognize_float, parse_to!(f32)));
+fn boolean(input: &str) -> IResult<&str, bool> {
+  alt((value(false, tag("false")), value(true, tag("true"))))(input)
+}
 
-//FIXME: verify how json strings are formatted
-named!(
-  string<&str>,
-  delimited!(
-    char!('"'),
-    //map_res!(escaped!(call!(alphanumeric), '\\', is_a!("\"n\\")), str::from_utf8),
-    map_res!(
-      escaped!(take_while1!(is_alphanumeric), '\\', one_of!("\"n\\")),
-      str::from_utf8
+fn u16_hex(input: &str) -> IResult<&str, u16> {
+  map_res(take(4usize), |s| u16::from_str_radix(s, 16))(input)
+}
+
+fn unicode_escape(input: &str) -> IResult<&str, char> {
+  map_opt(
+    alt((
+      // Not a surrogate
+      map(verify(u16_hex, |cp| !(0xD800..0xE000).contains(cp)), |cp| {
+        cp as u32
+      }),
+      // See https://en.wikipedia.org/wiki/UTF-16#Code_points_from_U+010000_to_U+10FFFF for details
+      map(
+        verify(
+          separated_pair(u16_hex, tag("\\u"), u16_hex),
+          |(high, low)| (0xD800..0xDC00).contains(high) && (0xDC00..0xE000).contains(low),
+        ),
+        |(high, low)| {
+          let high_ten = (high as u32) - 0xD800;
+          let low_ten = (low as u32) - 0xDC00;
+          (high_ten << 10) + low_ten + 0x10000
+        },
+      ),
+    )),
+    // Could be probably replaced with .unwrap() or _unchecked due to the verify checks
+    std::char::from_u32,
+  )(input)
+}
+
+fn character(input: &str) -> IResult<&str, char> {
+  let (input, c) = none_of("\"")(input)?;
+  if c == '\\' {
+    alt((
+      map_res(anychar, |c| {
+        Ok(match c {
+          '"' | '\\' | '/' => c,
+          'b' => '\x08',
+          'f' => '\x0C',
+          'n' => '\n',
+          'r' => '\r',
+          't' => '\t',
+          _ => return Err(()),
+        })
+      }),
+      preceded(char('u'), unicode_escape),
+    ))(input)
+  } else {
+    Ok((input, c))
+  }
+}
+
+fn string(input: &str) -> IResult<&str, String> {
+  delimited(
+    char('"'),
+    fold_many0(character, String::new, |mut string, c| {
+      string.push(c);
+      string
+    }),
+    char('"'),
+  )(input)
+}
+
+fn ws<'a, O, E: ParseError<&'a str>, F: Parser<&'a str, O, E>>(f: F) -> impl Parser<&'a str, O, E> {
+  delimited(multispace0, f, multispace0)
+}
+
+fn array(input: &str) -> IResult<&str, Vec<JsonValue>> {
+  delimited(
+    char('['),
+    ws(separated_list0(ws(char(',')), json_value)),
+    char(']'),
+  )(input)
+}
+
+fn object(input: &str) -> IResult<&str, HashMap<String, JsonValue>> {
+  map(
+    delimited(
+      char('{'),
+      ws(separated_list0(
+        ws(char(',')),
+        separated_pair(string, ws(char(':')), json_value),
+      )),
+      char('}'),
     ),
-    char!('"')
-  )
-);
+    |key_values| key_values.into_iter().collect(),
+  )(input)
+}
 
-named!(
-  array<Vec<JsonValue>>,
-  ws!(delimited!(
-    char!('['),
-    separated_list!(char!(','), value),
-    char!(']')
-  ))
-);
+fn json_value(input: &str) -> IResult<&str, JsonValue> {
+  use JsonValue::*;
 
-named!(
-  key_value<(&str, JsonValue)>,
-  ws!(separated_pair!(string, char!(':'), value))
-);
+  alt((
+    value(Null, tag("null")),
+    map(boolean, Bool),
+    map(string, Str),
+    map(double, Num),
+    map(array, Array),
+    map(object, Object),
+  ))(input)
+}
 
-named!(
-  hash<HashMap<String, JsonValue>>,
-  ws!(map!(
-    delimited!(char!('{'), separated_list!(char!(','), key_value), char!('}')),
-    |tuple_vec| {
-      let mut h: HashMap<String, JsonValue> = HashMap::new();
-      for (k, v) in tuple_vec {
-        h.insert(String::from(k), v);
-      }
-      h
-    }
-  ))
-);
+fn json(input: &str) -> IResult<&str, JsonValue> {
+  ws(json_value).parse(input)
+}
 
-named!(
-  value<JsonValue>,
-  ws!(alt!(
-      hash   => { |h|   JsonValue::Object(h)            } |
-      array  => { |v|   JsonValue::Array(v)             } |
-      string => { |s|   JsonValue::Str(String::from(s)) } |
-      float  => { |num| JsonValue::Num(num)             }
-    ))
-);
+#[test]
+fn json_string() {
+  assert_eq!(string("\"\""), Ok(("", "".to_string())));
+  assert_eq!(string("\"abc\""), Ok(("", "abc".to_string())));
+  assert_eq!(
+    string("\"abc\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0001\\u2014\u{2014}def\""),
+    Ok(("", "abc\"\\/\x08\x0C\n\r\t\x01——def".to_string())),
+  );
+  assert_eq!(string("\"\\uD83D\\uDE10\""), Ok(("", "😐".to_string())));
+
+  assert!(string("\"").is_err());
+  assert!(string("\"abc").is_err());
+  assert!(string("\"\\\"").is_err());
+  assert!(string("\"\\u123\"").is_err());
+  assert!(string("\"\\uD800\"").is_err());
+  assert!(string("\"\\uD800\\uD800\"").is_err());
+  assert!(string("\"\\uDC00\"").is_err());
+}
 
 #[test]
 fn json_object() {
-  let input =
-    r#"{
-      "a": 42,
-      "b": "x"
-    }\0"#;
+  use JsonValue::*;
 
-  let mut expected_map = HashMap::new();
-  expected_map.insert(String::from("a"), JsonValue::Num(42f32));
-  expected_map.insert(String::from("b"), JsonValue::Str(String::from("x")));
-  let expected = JsonValue::Object(expected_map);
+  let input = r#"{"a":42,"b":"x"}"#;
 
-  assert_eq!(expected, value(input.as_bytes()).unwrap().1);
+  let expected = Object(
+    vec![
+      ("a".to_string(), Num(42.0)),
+      ("b".to_string(), Str("x".to_string())),
+    ]
+    .into_iter()
+    .collect(),
+  );
+
+  assert_eq!(json(input), Ok(("", expected)));
 }
 
 #[test]
 fn json_array() {
-  let input =
-    r#"[
-      42,
-      "x"
-    ]\0"#;
+  use JsonValue::*;
 
-  let expected_vec = vec![
-    JsonValue::Num(42f32),
-    JsonValue::Str(String::from("x"))
-  ];
-  let expected = JsonValue::Array(expected_vec);
+  let input = r#"[42,"x"]"#;
 
-  assert_eq!(expected, value(input.as_bytes()).unwrap().1);
+  let expected = Array(vec![Num(42.0), Str("x".to_string())]);
+
+  assert_eq!(json(input), Ok(("", expected)));
+}
+
+#[test]
+fn json_whitespace() {
+  use JsonValue::*;
+
+  let input = r#"
+  {
+    "null" : null,
+    "true"  :true ,
+    "false":  false  ,
+    "number" : 123e4 ,
+    "string" : " abc 123 " ,
+    "array" : [ false , 1 , "two" ] ,
+    "object" : { "a" : 1.0 , "b" : "c" } ,
+    "empty_array" : [  ] ,
+    "empty_object" : {   }
+  }
+  "#;
+
+  assert_eq!(
+    json(input),
+    Ok((
+      "",
+      Object(
+        vec![
+          ("null".to_string(), Null),
+          ("true".to_string(), Bool(true)),
+          ("false".to_string(), Bool(false)),
+          ("number".to_string(), Num(123e4)),
+          ("string".to_string(), Str(" abc 123 ".to_string())),
+          (
+            "array".to_string(),
+            Array(vec![Bool(false), Num(1.0), Str("two".to_string())])
+          ),
+          (
+            "object".to_string(),
+            Object(
+              vec![
+                ("a".to_string(), Num(1.0)),
+                ("b".to_string(), Str("c".to_string())),
+              ]
+              .into_iter()
+              .collect()
+            )
+          ),
+          ("empty_array".to_string(), Array(vec![]),),
+          ("empty_object".to_string(), Object(HashMap::new()),),
+        ]
+        .into_iter()
+        .collect()
+      )
+    ))
+  );
 }
diff --git a/tests/mp4.rs b/tests/mp4.rs
index 1432621..852bf29 100644
--- a/tests/mp4.rs
+++ b/tests/mp4.rs
@@ -1,12 +1,13 @@
 #![allow(dead_code)]
 
-#[macro_use]
-extern crate nom;
-
 use nom::{
-  IResult, Needed, Err,
+  branch::alt,
+  bytes::streaming::{tag, take},
+  combinator::{map, map_res},
   error::ErrorKind,
-  number::streaming::{be_u16, be_u32, be_u64, be_f32}
+  multi::many0,
+  number::streaming::{be_f32, be_u16, be_u32, be_u64},
+  Err, IResult, Needed,
 };
 
 use std::str;
@@ -18,7 +19,7 @@
       if i.len() >= sz - 4 {
         Ok((&i[(sz - 4)..], &i[0..(sz - 4)]))
       } else {
-        Err(Err::Incomplete(Needed::Size(offset as usize + 4)))
+        Err(Err::Incomplete(Needed::new(offset as usize + 4)))
       }
     }
     Err(e) => Err(e),
@@ -93,109 +94,109 @@
   track_id:      u32
 }
 
-#[allow(non_snake_case)]
-named!(mvhd32 <&[u8], MvhdBox>,
-  do_parse!(
-  version_flags: be_u32 >>
-  created_date:  be_u32 >>
-  modified_date: be_u32 >>
-  scale:         be_u32 >>
-  duration:      be_u32 >>
-  speed:         be_f32 >>
-  volume:        be_u16 >> // actually a 2 bytes decimal
-              take!(10) >>
-  scale_a:       be_f32 >>
-  rotate_b:      be_f32 >>
-  angle_u:       be_f32 >>
-  rotate_c:      be_f32 >>
-  scale_d:       be_f32 >>
-  angle_v:       be_f32 >>
-  position_x:    be_f32 >>
-  position_y:    be_f32 >>
-  scale_w:       be_f32 >>
-  preview:       be_u64 >>
-  poster:        be_u32 >>
-  selection:     be_u64 >>
-  current_time:  be_u32 >>
-  track_id:      be_u32 >>
-  (
-    MvhdBox::M32(Mvhd32 {
-      version_flags: version_flags,
-      created_date:  created_date,
-      modified_date: modified_date,
-      scale:         scale,
-      duration:      duration,
-      speed:         speed,
-      volume:        volume,
-      scaleA:        scale_a,
-      rotateB:       rotate_b,
-      angleU:        angle_u,
-      rotateC:       rotate_c,
-      scaleD:        scale_d,
-      angleV:        angle_v,
-      positionX:     position_x,
-      positionY:     position_y,
-      scaleW:        scale_w,
-      preview:       preview,
-      poster:        poster,
-      selection:     selection,
-      current_time:  current_time,
-      track_id:      track_id
-    })
-  ))
-);
+#[cfg_attr(rustfmt, rustfmt_skip)]
+fn mvhd32(i: &[u8]) -> IResult<&[u8], MvhdBox> {
+  let (i, version_flags) = be_u32(i)?;
+  let (i, created_date) =  be_u32(i)?;
+  let (i, modified_date) = be_u32(i)?;
+  let (i, scale) =         be_u32(i)?;
+  let (i, duration) =      be_u32(i)?;
+  let (i, speed) =         be_f32(i)?;
+  let (i, volume) =        be_u16(i)?; // actually a 2 bytes decimal
+  let (i, _) =             take(10_usize)(i)?;
+  let (i, scale_a) =       be_f32(i)?;
+  let (i, rotate_b) =      be_f32(i)?;
+  let (i, angle_u) =       be_f32(i)?;
+  let (i, rotate_c) =      be_f32(i)?;
+  let (i, scale_d) =       be_f32(i)?;
+  let (i, angle_v) =       be_f32(i)?;
+  let (i, position_x) =    be_f32(i)?;
+  let (i, position_y) =    be_f32(i)?;
+  let (i, scale_w) =       be_f32(i)?;
+  let (i, preview) =       be_u64(i)?;
+  let (i, poster) =        be_u32(i)?;
+  let (i, selection) =     be_u64(i)?;
+  let (i, current_time) =  be_u32(i)?;
+  let (i, track_id) =      be_u32(i)?;
 
-#[allow(non_snake_case)]
-named!(mvhd64 <&[u8], MvhdBox>,
-  do_parse!(
-  version_flags: be_u32 >>
-  created_date:  be_u64 >>
-  modified_date: be_u64 >>
-  scale:         be_u32 >>
-  duration:      be_u64 >>
-  speed:         be_f32 >>
-  volume:        be_u16 >> // actually a 2 bytes decimal
-              take!(10) >>
-  scale_a:       be_f32 >>
-  rotate_b:      be_f32 >>
-  angle_u:       be_f32 >>
-  rotate_c:      be_f32 >>
-  scale_d:       be_f32 >>
-  angle_v:       be_f32 >>
-  position_x:    be_f32 >>
-  position_y:    be_f32 >>
-  scale_w:       be_f32 >>
-  preview:       be_u64 >>
-  poster:        be_u32 >>
-  selection:     be_u64 >>
-  current_time:  be_u32 >>
-  track_id:      be_u32 >>
-  (
-    MvhdBox::M64(Mvhd64 {
-      version_flags: version_flags,
-      created_date:  created_date,
-      modified_date: modified_date,
-      scale:         scale,
-      duration:      duration,
-      speed:         speed,
-      volume:        volume,
-      scaleA:        scale_a,
-      rotateB:       rotate_b,
-      angleU:        angle_u,
-      rotateC:       rotate_c,
-      scaleD:        scale_d,
-      angleV:        angle_v,
-      positionX:     position_x,
-      positionY:     position_y,
-      scaleW:        scale_w,
-      preview:       preview,
-      poster:        poster,
-      selection:     selection,
-      current_time:  current_time,
-      track_id:      track_id
-    })
-  ))
-);
+  let mvhd_box = MvhdBox::M32(Mvhd32 {
+    version_flags,
+    created_date,
+    modified_date,
+    scale,
+    duration,
+    speed,
+    volume,
+    scaleA:    scale_a,
+    rotateB:   rotate_b,
+    angleU:    angle_u,
+    rotateC:   rotate_c,
+    scaleD:    scale_d,
+    angleV:    angle_v,
+    positionX: position_x,
+    positionY: position_y,
+    scaleW:    scale_w,
+    preview,
+    poster,
+    selection,
+    current_time,
+    track_id,
+  });
+
+  Ok((i, mvhd_box))
+}
+
+#[cfg_attr(rustfmt, rustfmt_skip)]
+fn mvhd64(i: &[u8]) -> IResult<&[u8], MvhdBox> {
+  let (i, version_flags) = be_u32(i)?;
+  let (i, created_date) =  be_u64(i)?;
+  let (i, modified_date) = be_u64(i)?;
+  let (i, scale) =         be_u32(i)?;
+  let (i, duration) =      be_u64(i)?;
+  let (i, speed) =         be_f32(i)?;
+  let (i, volume) =        be_u16(i)?; // actually a 2 bytes decimal
+  let (i, _) =             take(10_usize)(i)?;
+  let (i, scale_a) =       be_f32(i)?;
+  let (i, rotate_b) =      be_f32(i)?;
+  let (i, angle_u) =       be_f32(i)?;
+  let (i, rotate_c) =      be_f32(i)?;
+  let (i, scale_d) =       be_f32(i)?;
+  let (i, angle_v) =       be_f32(i)?;
+  let (i, position_x) =    be_f32(i)?;
+  let (i, position_y) =    be_f32(i)?;
+  let (i, scale_w) =       be_f32(i)?;
+  let (i, preview) =       be_u64(i)?;
+  let (i, poster) =        be_u32(i)?;
+  let (i, selection) =     be_u64(i)?;
+  let (i, current_time) =  be_u32(i)?;
+  let (i, track_id) =      be_u32(i)?;
+
+  let mvhd_box = MvhdBox::M64(Mvhd64 {
+    version_flags,
+    created_date,
+    modified_date,
+    scale,
+    duration,
+    speed,
+    volume,
+    scaleA:    scale_a,
+    rotateB:   rotate_b,
+    angleU:    angle_u,
+    rotateC:   rotate_c,
+    scaleD:    scale_d,
+    angleV:    angle_v,
+    positionX: position_x,
+    positionY: position_y,
+    scaleW:    scale_w,
+    preview,
+    poster,
+    selection,
+    current_time,
+    track_id,
+  });
+
+  Ok((i, mvhd_box))
+}
 
 #[derive(Debug, Clone)]
 pub enum MvhdBox {
@@ -242,26 +243,32 @@
   tag: MP4BoxType,
 }
 
-named!(brand_name<&[u8],&str>, map_res!(take!(4), str::from_utf8));
+fn brand_name(input: &[u8]) -> IResult<&[u8], &str> {
+  map_res(take(4_usize), str::from_utf8)(input)
+}
 
-named!(filetype_parser<&[u8], FileType>,
-  do_parse!(
-    m: brand_name          >>
-    v: take!(4)            >>
-    c: many0!(brand_name)  >>
-    (FileType{ major_brand: m, major_brand_version:v, compatible_brands: c })
-  )
-);
+fn filetype_parser(input: &[u8]) -> IResult<&[u8], FileType<'_>> {
+  let (i, name) = brand_name(input)?;
+  let (i, version) = take(4_usize)(i)?;
+  let (i, brands) = many0(brand_name)(i)?;
+
+  let ft = FileType {
+    major_brand: name,
+    major_brand_version: version,
+    compatible_brands: brands,
+  };
+  Ok((i, ft))
+}
 
 fn mvhd_box(input: &[u8]) -> IResult<&[u8], MvhdBox> {
   let res = if input.len() < 100 {
-    Err(Err::Incomplete(Needed::Size(100)))
+    Err(Err::Incomplete(Needed::new(100)))
   } else if input.len() == 100 {
     mvhd32(input)
   } else if input.len() == 112 {
     mvhd64(input)
   } else {
-    Err(Err::Error(error_position!(input, ErrorKind::TooLarge)))
+    Err(Err::Error(nom::error_position!(input, ErrorKind::TooLarge)))
   };
   println!("res: {:?}", res);
   res
@@ -271,49 +278,43 @@
   Ok((input, MP4BoxType::Unknown))
 }
 
-//named!(box_type<&[u8], MP4BoxType>,
 fn box_type(input: &[u8]) -> IResult<&[u8], MP4BoxType> {
-  alt!(input,
-    tag!("ftyp") => { |_| MP4BoxType::Ftyp } |
-    tag!("moov") => { |_| MP4BoxType::Moov } |
-    tag!("mdat") => { |_| MP4BoxType::Mdat } |
-    tag!("free") => { |_| MP4BoxType::Free } |
-    tag!("skip") => { |_| MP4BoxType::Skip } |
-    tag!("wide") => { |_| MP4BoxType::Wide } |
-    unknown_box_type
-  )
+  alt((
+    map(tag("ftyp"), |_| MP4BoxType::Ftyp),
+    map(tag("moov"), |_| MP4BoxType::Moov),
+    map(tag("mdat"), |_| MP4BoxType::Mdat),
+    map(tag("free"), |_| MP4BoxType::Free),
+    map(tag("skip"), |_| MP4BoxType::Skip),
+    map(tag("wide"), |_| MP4BoxType::Wide),
+    unknown_box_type,
+  ))(input)
 }
 
 // warning, an alt combinator with 9 branches containing a tag combinator
 // can make the compilation very slow. Use functions as sub parsers,
-// or split into multiple alt! parsers if it gets slow
-named!(moov_type<&[u8], MP4BoxType>,
-  alt!(
-    tag!("mdra") => { |_| MP4BoxType::Mdra } |
-    tag!("dref") => { |_| MP4BoxType::Dref } |
-    tag!("cmov") => { |_| MP4BoxType::Cmov } |
-    tag!("rmra") => { |_| MP4BoxType::Rmra } |
-    tag!("iods") => { |_| MP4BoxType::Iods } |
-    tag!("mvhd") => { |_| MP4BoxType::Mvhd } |
-    tag!("clip") => { |_| MP4BoxType::Clip } |
-    tag!("trak") => { |_| MP4BoxType::Trak } |
-    tag!("udta") => { |_| MP4BoxType::Udta }
-  )
-);
+// or split into multiple alt parsers if it gets slow
+fn moov_type(input: &[u8]) -> IResult<&[u8], MP4BoxType> {
+  alt((
+    map(tag("mdra"), |_| MP4BoxType::Mdra),
+    map(tag("dref"), |_| MP4BoxType::Dref),
+    map(tag("cmov"), |_| MP4BoxType::Cmov),
+    map(tag("rmra"), |_| MP4BoxType::Rmra),
+    map(tag("iods"), |_| MP4BoxType::Iods),
+    map(tag("mvhd"), |_| MP4BoxType::Mvhd),
+    map(tag("clip"), |_| MP4BoxType::Clip),
+    map(tag("trak"), |_| MP4BoxType::Trak),
+    map(tag("udta"), |_| MP4BoxType::Udta),
+  ))(input)
+}
 
-named!(box_header<&[u8],MP4BoxHeader>,
-  do_parse!(
-    length: be_u32 >>
-    tag: box_type  >>
-    (MP4BoxHeader{ length: length, tag: tag})
-  )
-);
+fn box_header(input: &[u8]) -> IResult<&[u8], MP4BoxHeader> {
+  let (i, length) = be_u32(input)?;
+  let (i, tag) = box_type(i)?;
+  Ok((i, MP4BoxHeader { length, tag }))
+}
 
-named!(moov_header<&[u8],MP4BoxHeader>,
-  do_parse!(
-    length: be_u32 >>
-    tag: moov_type >>
-    (MP4BoxHeader{ length: length, tag: tag})
-  )
-);
-
+fn moov_header(input: &[u8]) -> IResult<&[u8], MP4BoxHeader> {
+  let (i, length) = be_u32(input)?;
+  let (i, tag) = moov_type(i)?;
+  Ok((i, MP4BoxHeader { length, tag }))
+}
diff --git a/tests/multiline.rs b/tests/multiline.rs
index cca19ec..7378b9e 100644
--- a/tests/multiline.rs
+++ b/tests/multiline.rs
@@ -1,10 +1,8 @@
-extern crate nom;
-
 use nom::{
-  IResult,
+  character::complete::{alphanumeric1 as alphanumeric, line_ending as eol},
   multi::many0,
   sequence::terminated,
-  character::complete::{alphanumeric1 as alphanumeric, line_ending as eol}
+  IResult,
 };
 
 pub fn end_of_line(input: &str) -> IResult<&str, &str> {
@@ -26,10 +24,7 @@
 #[cfg(feature = "alloc")]
 #[test]
 fn read_lines_test() {
-  let res = Ok((
-    "",
-    vec!["Duck", "Dog", "Cow"],
-  ));
+  let res = Ok(("", vec!["Duck", "Dog", "Cow"]));
 
   assert_eq!(read_lines("Duck\nDog\nCow\n"), res);
   assert_eq!(read_lines("Duck\nDog\nCow"), res);
diff --git a/tests/named_args.rs b/tests/named_args.rs
deleted file mode 100644
index 811b0a0..0000000
--- a/tests/named_args.rs
+++ /dev/null
@@ -1,161 +0,0 @@
-#[macro_use]
-extern crate nom;
-
-use nom::{
-  branch::alt,
-  sequence::{delimited, pair, preceded},
-  character::complete::{digit1 as digit, space0 as space},
-  bytes::complete::tag
-};
-
-// Parser definition
-
-use std::str;
-use std::str::FromStr;
-
-use self::Operator::*;
-
-enum Operator {
-  Slash,
-  Star,
-}
-
-impl Operator {
-  fn to_str(&self) -> &'static str {
-    match *self {
-      Slash => "/",
-      Star => "*",
-    }
-  }
-}
-
-// Parse the specified `Operator`.
-named_args!(operator(op: Operator) <&[u8], &[u8]>,
-    call!(tag(op.to_str()))
-);
-
-// We parse any expr surrounded by the tags `open_tag` and `close_tag`, ignoring all whitespaces around those
-named_args!(brackets<'a>(open_tag: &str, close_tag: &str) <&'a[u8], i64>,
-  call!(delimited(
-    space,
-    delimited(tag(open_tag), preceded(space, expr), preceded(space, tag(close_tag))),
-    space
-  ))
-);
-
-fn byte_slice_to_str<'a>(s: &'a[u8]) -> Result<&'a str, str::Utf8Error> {
-  str::from_utf8(s)
-}
-
-// We transform an integer string into a i64, ignoring surrounding whitespaces
-// We look for a digit suite, and try to convert it.
-// If either str::from_utf8 or FromStr::from_str fail,
-// we fallback to the brackets parser defined above
-named!(factor<&[u8], i64>, alt!(
-    map_res!(
-      map_res!(
-        call!(delimited(space, digit, space)),
-        byte_slice_to_str
-      ),
-      FromStr::from_str
-    )
-  | call!(brackets, "(", ")")
-  )
-);
-
-// We read an initial factor and for each time we find
-// a * or / operator followed by another factor, we do
-// the math by folding everything
-named!(term <&[u8], i64>, do_parse!(
-    init: factor >>
-    res:  fold_many0!(
-        pair!(alt!(call!(operator, Star) | call!(operator, Slash)), factor),
-        init,
-        |acc, (op, val): (&[u8], i64)| {
-            if (op[0] as char) == '*' { acc * val } else { acc / val }
-        }
-    ) >>
-    (res)
-  )
-);
-
-named!(expr <&[u8], i64>, do_parse!(
-    init: term >>
-    res:  fold_many0!(
-        call!(pair(alt((tag("+"), tag("-"))), term)),
-        init,
-        |acc, (op, val): (&[u8], i64)| {
-            if (op[0] as char) == '+' { acc + val } else { acc - val }
-        }
-    ) >>
-    (res)
-  )
-);
-
-#[test]
-fn factor_test() {
-  assert_eq!(
-    factor(&b"3"[..]),
-    Ok((&b""[..], 3))
-  );
-  assert_eq!(
-    factor(&b" 12"[..]),
-    Ok((&b""[..], 12))
-  );
-  assert_eq!(
-    factor(&b"537  "[..]),
-    Ok((&b""[..], 537))
-  );
-  assert_eq!(
-    factor(&b"  24   "[..]),
-    Ok((&b""[..], 24))
-  );
-}
-
-#[test]
-fn term_test() {
-  assert_eq!(
-    term(&b" 12 *2 /  3"[..]),
-    Ok((&b""[..], 8))
-  );
-  assert_eq!(
-    term(&b" 2* 3  *2 *2 /  3"[..]),
-    Ok((&b""[..], 8))
-  );
-  assert_eq!(
-    term(&b" 48 /  3/2"[..]),
-    Ok((&b""[..], 8))
-  );
-}
-
-#[test]
-fn expr_test() {
-  assert_eq!(
-    expr(&b" 1 +  2 "[..]),
-    Ok((&b""[..], 3))
-  );
-  assert_eq!(
-    expr(&b" 12 + 6 - 4+  3"[..]),
-    Ok((&b""[..], 17))
-  );
-  assert_eq!(
-    expr(&b" 1 + 2*3 + 4"[..]),
-    Ok((&b""[..], 11))
-  );
-}
-
-#[test]
-fn parens_test() {
-  assert_eq!(
-    expr(&b" (  2 )"[..]),
-    Ok((&b""[..], 2))
-  );
-  assert_eq!(
-    expr(&b" 2* (  3 + 4 ) "[..]),
-    Ok((&b""[..], 14))
-  );
-  assert_eq!(
-    expr(&b"  2*2 / ( 5 - 1) + 3"[..]),
-    Ok((&b""[..], 4))
-  );
-}
diff --git a/tests/overflow.rs b/tests/overflow.rs
index 2f4a87f..ea513bb 100644
--- a/tests/overflow.rs
+++ b/tests/overflow.rs
@@ -1,139 +1,145 @@
 #![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
 #![cfg(target_pointer_width = "64")]
 
-#[macro_use]
-extern crate nom;
-
-use nom::{Err, Needed};
+use nom::bytes::streaming::take;
+#[cfg(feature = "alloc")]
+use nom::multi::{length_data, many0};
 #[cfg(feature = "alloc")]
 use nom::number::streaming::be_u64;
+use nom::sequence::tuple;
+use nom::{Err, IResult, Needed};
 
 // Parser definition
 
 // We request a length that would trigger an overflow if computing consumed + requested
-named!(parser01<&[u8],()>,
-    do_parse!(
-        hdr: take!(1) >>
-        data: take!(18446744073709551615) >>
-        ({
-          let _ = hdr;
-          let _ = data;
-          ()
-        })
-    )
-);
-
-// We request a length that would trigger an overflow if computing consumed + requested
-named!(parser02<&[u8],(&[u8],&[u8])>,
-    tuple!(take!(1),take!(18446744073709551615))
-);
-
-#[test]
-fn overflow_incomplete_do_parse() {
-  assert_eq!(
-    parser01(&b"3"[..]),
-    Err(Err::Incomplete(Needed::Size(18446744073709551615)))
-  );
+fn parser02(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
+  tuple((take(1_usize), take(18446744073709551615_usize)))(i)
 }
 
 #[test]
 fn overflow_incomplete_tuple() {
   assert_eq!(
     parser02(&b"3"[..]),
-    Err(Err::Incomplete(Needed::Size(18446744073709551615)))
+    Err(Err::Incomplete(Needed::new(18446744073709551615)))
   );
 }
 
 #[test]
 #[cfg(feature = "alloc")]
 fn overflow_incomplete_length_bytes() {
-  named!(multi<&[u8], Vec<&[u8]> >, many0!( length_data!(be_u64) ) );
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    many0(length_data(be_u64))(i)
+  }
 
   // Trigger an overflow in length_data
   assert_eq!(
-    multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xff\xaa"[..]),
-    Err(Err::Incomplete(Needed::Size(18446744073709551615)))
+    multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xff"[..]),
+    Err(Err::Incomplete(Needed::new(18446744073709551615)))
   );
 }
 
 #[test]
 #[cfg(feature = "alloc")]
 fn overflow_incomplete_many0() {
-  named!(multi<&[u8], Vec<&[u8]> >, many0!( length_data!(be_u64) ) );
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    many0(length_data(be_u64))(i)
+  }
 
   // Trigger an overflow in many0
   assert_eq!(
-    multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef\xaa"[..]),
-    Err(Err::Incomplete(Needed::Size(18446744073709551599)))
+    multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef"[..]),
+    Err(Err::Incomplete(Needed::new(18446744073709551599)))
   );
 }
 
 #[test]
 #[cfg(feature = "alloc")]
 fn overflow_incomplete_many1() {
-  named!(multi<&[u8], Vec<&[u8]> >, many1!( length_data!(be_u64) ) );
+  use nom::multi::many1;
+
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    many1(length_data(be_u64))(i)
+  }
 
   // Trigger an overflow in many1
   assert_eq!(
-    multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef\xaa"[..]),
-    Err(Err::Incomplete(Needed::Size(18446744073709551599)))
+    multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef"[..]),
+    Err(Err::Incomplete(Needed::new(18446744073709551599)))
   );
 }
 
 #[test]
 #[cfg(feature = "alloc")]
 fn overflow_incomplete_many_till() {
-  named!(multi<&[u8], (Vec<&[u8]>, &[u8]) >, many_till!( length_data!(be_u64), tag!("abc") ) );
+  use nom::{bytes::complete::tag, multi::many_till};
+
+  fn multi(i: &[u8]) -> IResult<&[u8], (Vec<&[u8]>, &[u8])> {
+    many_till(length_data(be_u64), tag("abc"))(i)
+  }
 
   // Trigger an overflow in many_till
   assert_eq!(
-    multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef\xaa"[..]),
-    Err(Err::Incomplete(Needed::Size(18446744073709551599)))
+    multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef"[..]),
+    Err(Err::Incomplete(Needed::new(18446744073709551599)))
   );
 }
 
 #[test]
 #[cfg(feature = "alloc")]
 fn overflow_incomplete_many_m_n() {
-  named!(multi<&[u8], Vec<&[u8]> >, many_m_n!(2, 4, length_data!(be_u64) ) );
+  use nom::multi::many_m_n;
+
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    many_m_n(2, 4, length_data(be_u64))(i)
+  }
 
   // Trigger an overflow in many_m_n
   assert_eq!(
-    multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef\xaa"[..]),
-    Err(Err::Incomplete(Needed::Size(18446744073709551599)))
+    multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef"[..]),
+    Err(Err::Incomplete(Needed::new(18446744073709551599)))
   );
 }
 
 #[test]
 #[cfg(feature = "alloc")]
 fn overflow_incomplete_count() {
-  named!(counter<&[u8], Vec<&[u8]> >, count!( length_data!(be_u64), 2 ) );
+  use nom::multi::count;
+
+  fn counter(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    count(length_data(be_u64), 2)(i)
+  }
 
   assert_eq!(
-    counter(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef\xaa"[..]),
-    Err(Err::Incomplete(Needed::Size(18446744073709551599)))
+    counter(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xef"[..]),
+    Err(Err::Incomplete(Needed::new(18446744073709551599)))
   );
 }
 
 #[test]
 #[cfg(feature = "alloc")]
 fn overflow_incomplete_length_count() {
+  use nom::multi::length_count;
   use nom::number::streaming::be_u8;
-  named!(multi<&[u8], Vec<&[u8]> >, length_count!( be_u8, length_data!(be_u64) ) );
+
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    length_count(be_u8, length_data(be_u64))(i)
+  }
 
   assert_eq!(
-    multi(&b"\x04\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xee\xaa"[..]),
-    Err(Err::Incomplete(Needed::Size(18446744073709551598)))
+    multi(&b"\x04\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xee"[..]),
+    Err(Err::Incomplete(Needed::new(18446744073709551598)))
   );
 }
 
 #[test]
 #[cfg(feature = "alloc")]
 fn overflow_incomplete_length_data() {
-  named!(multi<&[u8], Vec<&[u8]> >, many0!( length_data!(be_u64) ) );
+  fn multi(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> {
+    many0(length_data(be_u64))(i)
+  }
 
   assert_eq!(
-    multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xff\xaa"[..]),
-    Err(Err::Incomplete(Needed::Size(18446744073709551615)))
+    multi(&b"\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xff\xff\xff\xff\xff\xff\xff\xff"[..]),
+    Err(Err::Incomplete(Needed::new(18446744073709551615)))
   );
 }
diff --git a/tests/reborrow_fold.rs b/tests/reborrow_fold.rs
index b53555b..486617e 100644
--- a/tests/reborrow_fold.rs
+++ b/tests/reborrow_fold.rs
@@ -1,18 +1,31 @@
 #![allow(dead_code)]
-#![allow(unused_variables)]
-
-#[macro_use]
-extern crate nom;
+// #![allow(unused_variables)]
 
 use std::str;
 
-named_args!(atom<'a>(tomb: &'a mut ())<String>,
-            map!(map_res!(is_not!(" \t\r\n()"), str::from_utf8), ToString::to_string));
+use nom::bytes::complete::is_not;
+use nom::character::complete::char;
+use nom::combinator::{map, map_res};
+use nom::multi::fold_many0;
+use nom::sequence::delimited;
+use nom::IResult;
 
-/*FIXME: should we support the use case of borrowing data mutably in a parser?
-named_args!(list<'a>(tomb: &'a mut ())<String>,
-  delimited!(
-    char!('('),
-    fold_many0!(call!(atom, tomb), "".to_string(), |acc: String, next: String| acc + next.as_str()),
-    char!(')')));
-*/
+fn atom<'a>(_tomb: &'a mut ()) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], String> {
+  move |input| {
+    map(
+      map_res(is_not(" \t\r\n"), str::from_utf8),
+      ToString::to_string,
+    )(input)
+  }
+}
+
+// FIXME: should we support the use case of borrowing data mutably in a parser?
+fn list<'a>(i: &'a [u8], tomb: &'a mut ()) -> IResult<&'a [u8], String> {
+  delimited(
+    char('('),
+    fold_many0(atom(tomb), String::new, |acc: String, next: String| {
+      acc + next.as_str()
+    }),
+    char(')'),
+  )(i)
+}
diff --git a/tests/test1.rs b/tests/test1.rs
deleted file mode 100644
index 85c442f..0000000
--- a/tests/test1.rs
+++ /dev/null
@@ -1,44 +0,0 @@
-#![cfg(feature = "stream")]
-
-#[macro_use]
-extern crate nom;
-
-use nom::{not_line_ending, IResult};
-
-use std::fmt::Debug;
-
-/*
-#[test]
-#[allow(unused_must_use)]
-fn tag() {
-  FileProducer::new("assets/links.txt", 20).map(|producer: FileProducer| {
-    let mut p = producer;
-    p.refill();
-
-    consumer_from_parser!(PrintConsumer<()>, flat_map!(map_res!(tag!("https!"), str::from_utf8), print));
-    let mut cs = PrintConsumer::new();
-    for _ in 1..4 {
-      p.apply(&mut cs);
-    }
-  });
-}
-*/
-
-pub fn print<T: Debug>(input: T) -> IResult<T, ()> {
-  println!("{:?}", input);
-  Ok((input, ()))
-}
-
-#[test]
-fn is_not() {
-  //is_not!(foo b"\r\n");
-  named!(foo<&[u8],&[u8]>, is_not!(&b"\r\n"[..]));
-  let a = &b"ab12cd\nefgh"[..];
-  assert_eq!(foo(a), Ok((&b"\nefgh"[..], &b"ab12cd"[..])));
-}
-
-#[test]
-fn exported_public_method_defined_by_macro() {
-  let a = &b"ab12cd\nefgh"[..];
-  assert_eq!(not_line_ending(a), Ok((&b"\nefgh"[..], &b"ab12cd"[..])));
-}