├── .github └── workflows │ ├── ci.yaml │ ├── master.yaml │ └── pr.yaml ├── .gitignore ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── RELEASES.md ├── ci ├── rustup.sh └── test_full.sh └── src └── lib.rs /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: merge_group 3 | 4 | jobs: 5 | 6 | test: 7 | name: Test 8 | runs-on: ubuntu-latest 9 | strategy: 10 | matrix: 11 | rust: [ 12 | 1.31.0, # MSRV 13 | 1.51.0, 14 | 1.60.0, 15 | stable, 16 | beta, 17 | nightly, 18 | ] 19 | steps: 20 | - uses: actions/checkout@v4 21 | - uses: actions/cache@v4 22 | if: startsWith(matrix.rust, '1') 23 | with: 24 | path: ~/.cargo/registry/index 25 | key: cargo-${{ matrix.rust }}-git-index 26 | - uses: dtolnay/rust-toolchain@master 27 | with: 28 | toolchain: ${{ matrix.rust }} 29 | - run: ./ci/test_full.sh 30 | 31 | # try a target that doesn't have std at all 32 | no_std: 33 | name: No Std 34 | runs-on: ubuntu-latest 35 | steps: 36 | - uses: actions/checkout@v4 37 | - uses: dtolnay/rust-toolchain@stable 38 | with: 39 | target: thumbv6m-none-eabi 40 | - run: cargo build --target thumbv6m-none-eabi --no-default-features 41 | 42 | fmt: 43 | name: Format 44 | runs-on: ubuntu-latest 45 | steps: 46 | - uses: actions/checkout@v4 47 | - uses: dtolnay/rust-toolchain@1.62.0 48 | with: 49 | components: rustfmt 50 | - run: cargo fmt --all --check 51 | 52 | # One job that "summarizes" the success state of this pipeline. This can then be added to branch 53 | # protection, rather than having to add each job separately. 54 | success: 55 | name: Success 56 | runs-on: ubuntu-latest 57 | needs: [test, no_std, fmt] 58 | # Github branch protection is exceedingly silly and treats "jobs skipped because a dependency 59 | # failed" as success. So we have to do some contortions to ensure the job fails if any of its 60 | # dependencies fails. 61 | if: always() # make sure this is never "skipped" 62 | steps: 63 | # Manually check the status of all dependencies. `if: failure()` does not work. 64 | - name: check if any dependency failed 65 | run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}' 66 | -------------------------------------------------------------------------------- /.github/workflows/master.yaml: -------------------------------------------------------------------------------- 1 | name: master 2 | on: 3 | push: 4 | branches: 5 | - master 6 | schedule: 7 | - cron: '0 0 * * 0' # 00:00 Sunday 8 | 9 | jobs: 10 | 11 | test: 12 | name: Test 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | rust: [1.31.0, stable] 17 | steps: 18 | - uses: actions/checkout@v4 19 | - uses: actions/cache@v4 20 | if: startsWith(matrix.rust, '1') 21 | with: 22 | path: ~/.cargo/registry/index 23 | key: cargo-${{ matrix.rust }}-git-index 24 | - uses: dtolnay/rust-toolchain@master 25 | with: 26 | toolchain: ${{ matrix.rust }} 27 | - run: ./ci/test_full.sh 28 | -------------------------------------------------------------------------------- /.github/workflows/pr.yaml: -------------------------------------------------------------------------------- 1 | name: PR 2 | on: 3 | pull_request: 4 | 5 | jobs: 6 | 7 | test: 8 | name: Test 9 | runs-on: ubuntu-latest 10 | strategy: 11 | matrix: 12 | rust: [1.31.0, stable] 13 | steps: 14 | - uses: actions/checkout@v4 15 | - uses: actions/cache@v4 16 | if: startsWith(matrix.rust, '1') 17 | with: 18 | path: ~/.cargo/registry/index 19 | key: cargo-${{ matrix.rust }}-git-index 20 | - uses: dtolnay/rust-toolchain@master 21 | with: 22 | toolchain: ${{ matrix.rust }} 23 | - run: ./ci/test_full.sh 24 | 25 | fmt: 26 | name: Format 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@v4 30 | - uses: dtolnay/rust-toolchain@1.62.0 31 | with: 32 | components: rustfmt 33 | - run: cargo fmt --all --check 34 | 35 | # One job that "summarizes" the success state of this pipeline. This can then be added to branch 36 | # protection, rather than having to add each job separately. 37 | success: 38 | name: Success 39 | runs-on: ubuntu-latest 40 | needs: [test, fmt] 41 | # Github branch protection is exceedingly silly and treats "jobs skipped because a dependency 42 | # failed" as success. So we have to do some contortions to ensure the job fails if any of its 43 | # dependencies fails. 44 | if: always() # make sure this is never "skipped" 45 | steps: 46 | # Manually check the status of all dependencies. `if: failure()` does not work. 47 | - name: check if any dependency failed 48 | run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}' 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Cargo.lock 2 | target 3 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["The Rust Project Developers"] 3 | description = "External iterators for generic mathematics" 4 | documentation = "https://docs.rs/num-iter" 5 | homepage = "https://github.com/rust-num/num-iter" 6 | keywords = ["mathematics", "numerics"] 7 | categories = ["algorithms", "science", "no-std"] 8 | license = "MIT OR Apache-2.0" 9 | repository = "https://github.com/rust-num/num-iter" 10 | name = "num-iter" 11 | version = "0.1.45" 12 | readme = "README.md" 13 | exclude = ["/ci/*", "/.github/*"] 14 | edition = "2018" 15 | rust-version = "1.31" 16 | 17 | [package.metadata.docs.rs] 18 | features = ["std"] 19 | 20 | [dependencies] 21 | 22 | [dependencies.num-integer] 23 | version = "0.1.46" 24 | default-features = false 25 | features = ["i128"] 26 | 27 | [dependencies.num-traits] 28 | version = "0.2.11" 29 | default-features = false 30 | features = ["i128"] 31 | 32 | [features] 33 | default = ["std"] 34 | std = ["num-integer/std", "num-traits/std"] 35 | 36 | # vestigial features, now always in effect 37 | i128 = [] 38 | 39 | [build-dependencies] 40 | autocfg = "1" 41 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 The Rust Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # num-iter 2 | 3 | [![crate](https://img.shields.io/crates/v/num-iter.svg)](https://crates.io/crates/num-iter) 4 | [![documentation](https://docs.rs/num-iter/badge.svg)](https://docs.rs/num-iter) 5 | [![minimum rustc 1.31](https://img.shields.io/badge/rustc-1.31+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) 6 | [![build status](https://github.com/rust-num/num-iter/workflows/master/badge.svg)](https://github.com/rust-num/num-iter/actions) 7 | 8 | Generic `Range` iterators for Rust. 9 | 10 | ## Usage 11 | 12 | Add this to your `Cargo.toml`: 13 | 14 | ```toml 15 | [dependencies] 16 | num-iter = "0.1" 17 | ``` 18 | 19 | ## Features 20 | 21 | This crate can be used without the standard library (`#![no_std]`) by disabling 22 | the default `std` feature. Use this in `Cargo.toml`: 23 | 24 | ```toml 25 | [dependencies.num-iter] 26 | version = "0.1.35" 27 | default-features = false 28 | ``` 29 | 30 | There is no functional difference with and without `std` at this time, but 31 | there may be in the future. 32 | 33 | ## Releases 34 | 35 | Release notes are available in [RELEASES.md](RELEASES.md). 36 | 37 | ## Compatibility 38 | 39 | The `num-iter` crate is tested for rustc 1.31 and greater. 40 | 41 | ## License 42 | 43 | Licensed under either of 44 | 45 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 46 | * [MIT license](http://opensource.org/licenses/MIT) 47 | 48 | at your option. 49 | 50 | ### Contribution 51 | 52 | Unless you explicitly state otherwise, any contribution intentionally submitted 53 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 54 | dual licensed as above, without any additional terms or conditions. 55 | -------------------------------------------------------------------------------- /RELEASES.md: -------------------------------------------------------------------------------- 1 | # Release 0.1.45 (2024-05-03) 2 | 3 | - [Use `Integer::dec` in `DoubleEndedIterator`][29] 4 | 5 | **Contributors**: @cuviper 6 | 7 | [29]: https://github.com/rust-num/num-iter/pull/29 8 | 9 | # Release 0.1.44 (2024-02-07) 10 | 11 | - [Upgrade to 2018 edition, **MSRV 1.31**][22] 12 | 13 | **Contributors**: @cuviper 14 | 15 | [22]: https://github.com/rust-num/num-iter/pull/22 16 | 17 | # Release 0.1.43 (2022-04-26) 18 | 19 | - [`Range`, `RangeInclusive`, and `RangeFrom` now implement `RangeBounds`][21] 20 | from Rust 1.28 and later. 21 | 22 | **Contributors**: @chrismit3s, @cuviper 23 | 24 | [21]: https://github.com/rust-num/num-iter/pull/21 25 | 26 | # Release 0.1.42 (2020-10-29) 27 | 28 | - [The "i128" feature now bypasses compiler probing][20]. The build script 29 | used to probe anyway and panic if requested support wasn't found, but 30 | sometimes this ran into bad corner cases with `autocfg`. 31 | 32 | **Contributors**: @cuviper 33 | 34 | [20]: https://github.com/rust-num/num-iter/pull/20 35 | 36 | # Release 0.1.41 (2020-06-11) 37 | 38 | - [The new `RangeFrom` and `RangeFromStep` iterators][18] will count from a 39 | given starting value, without any terminating value. 40 | 41 | **Contributors**: @cuviper, @sollyucko 42 | 43 | [18]: https://github.com/rust-num/num-iter/pull/18 44 | 45 | # Release 0.1.40 (2020-01-09) 46 | 47 | - [Updated the `autocfg` build dependency to 1.0][14]. 48 | 49 | **Contributors**: @cuviper, @dingelish 50 | 51 | [14]: https://github.com/rust-num/num-iter/pull/14 52 | 53 | # Release 0.1.39 (2019-05-21) 54 | 55 | - [Fixed feature detection on `no_std` targets][11]. 56 | 57 | **Contributors**: @cuviper 58 | 59 | [11]: https://github.com/rust-num/num-iter/pull/11 60 | 61 | # Release 0.1.38 (2019-05-20) 62 | 63 | - Maintenance update -- no functional changes. 64 | 65 | **Contributors**: @cuviper, @ignatenkobrain 66 | 67 | # Release 0.1.37 (2018-05-11) 68 | 69 | - [Support for 128-bit integers is now automatically detected and enabled.][5] 70 | Setting the `i128` crate feature now causes the build script to panic if such 71 | support is not detected. 72 | 73 | **Contributors**: @cuviper 74 | 75 | [5]: https://github.com/rust-num/num-iter/pull/5 76 | 77 | # Release 0.1.36 (2018-05-10) 78 | 79 | - [The iterators are now implemented for `i128` and `u128`][7] starting with 80 | Rust 1.26, enabled by the new `i128` crate feature. 81 | 82 | **Contributors**: @cuviper 83 | 84 | [4]: https://github.com/rust-num/num-iter/pull/4 85 | 86 | # Release 0.1.35 (2018-02-06) 87 | 88 | - [num-iter now has its own source repository][num-356] at [rust-num/num-iter][home]. 89 | - [There is now a `std` feature][2], enabled by default, along with the implication 90 | that building *without* this feature makes this a `#[no_std]` crate. 91 | - There is no difference in the API at this time. 92 | 93 | **Contributors**: @cuviper 94 | 95 | [home]: https://github.com/rust-num/num-iter 96 | [num-356]: https://github.com/rust-num/num/pull/356 97 | [2]: https://github.com/rust-num/num-iter/pull/2 98 | 99 | 100 | # Prior releases 101 | 102 | No prior release notes were kept. Thanks all the same to the many 103 | contributors that have made this crate what it is! 104 | 105 | -------------------------------------------------------------------------------- /ci/rustup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Use rustup to locally run the same suite of tests as .github/workflows/ 3 | # (You should first install/update all of the versions below.) 4 | 5 | set -ex 6 | 7 | ci=$(dirname $0) 8 | for version in 1.31.0 1.51.0 1.60.0 stable beta nightly; do 9 | rustup run "$version" "$ci/test_full.sh" 10 | done 11 | -------------------------------------------------------------------------------- /ci/test_full.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | CRATE=num-iter 6 | MSRV=1.31 7 | 8 | get_rust_version() { 9 | local array=($(rustc --version)); 10 | echo "${array[1]}"; 11 | return 0; 12 | } 13 | RUST_VERSION=$(get_rust_version) 14 | 15 | check_version() { 16 | IFS=. read -ra rust <<< "$RUST_VERSION" 17 | IFS=. read -ra want <<< "$1" 18 | [[ "${rust[0]}" -gt "${want[0]}" || 19 | ( "${rust[0]}" -eq "${want[0]}" && 20 | "${rust[1]}" -ge "${want[1]}" ) 21 | ]] 22 | } 23 | 24 | echo "Testing $CRATE on rustc $RUST_VERSION" 25 | if ! check_version $MSRV ; then 26 | echo "The minimum for $CRATE is rustc $MSRV" 27 | exit 1 28 | fi 29 | 30 | FEATURES=() 31 | echo "Testing supported features: ${FEATURES[*]}" 32 | 33 | cargo generate-lockfile 34 | 35 | # num-traits 0.2.19 started using dep: features, which requires 1.60 and is 36 | # otherwise ignored down to 1.51, but we need a manual downgrade before that. 37 | check_version 1.51 || cargo update -p num-traits --precise 0.2.18 38 | 39 | set -x 40 | 41 | # test the default 42 | cargo build 43 | cargo test 44 | 45 | # test `no_std` 46 | cargo build --no-default-features 47 | cargo test --no-default-features 48 | 49 | # test each isolated feature, with and without std 50 | for feature in ${FEATURES[*]}; do 51 | cargo build --no-default-features --features="std $feature" 52 | cargo test --no-default-features --features="std $feature" 53 | 54 | cargo build --no-default-features --features="$feature" 55 | cargo test --no-default-features --features="$feature" 56 | done 57 | 58 | # test all supported features, with and without std 59 | cargo build --features="std ${FEATURES[*]}" 60 | cargo test --features="std ${FEATURES[*]}" 61 | 62 | cargo build --features="${FEATURES[*]}" 63 | cargo test --features="${FEATURES[*]}" 64 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! External iterators for generic mathematics 12 | //! 13 | //! ## Compatibility 14 | //! 15 | //! The `num-iter` crate is tested for rustc 1.31 and greater. 16 | 17 | #![doc(html_root_url = "https://docs.rs/num-iter/0.1")] 18 | #![no_std] 19 | 20 | use core::ops::{Add, Bound, RangeBounds, Sub}; 21 | use core::usize; 22 | use num_integer::Integer; 23 | use num_traits::{CheckedAdd, One, ToPrimitive, Zero}; 24 | 25 | /// An iterator over the range [start, stop) 26 | #[derive(Clone)] 27 | pub struct Range { 28 | state: A, 29 | stop: A, 30 | one: A, 31 | } 32 | 33 | /// Returns an iterator over the given range [start, stop) (that is, starting 34 | /// at start (inclusive), and ending at stop (exclusive)). 35 | /// 36 | /// # Example 37 | /// 38 | /// ```rust 39 | /// let array = [0, 1, 2, 3, 4]; 40 | /// 41 | /// for i in num_iter::range(0, 5) { 42 | /// println!("{}", i); 43 | /// assert_eq!(i, array[i]); 44 | /// } 45 | /// ``` 46 | #[inline] 47 | pub fn range(start: A, stop: A) -> Range 48 | where 49 | A: Add + PartialOrd + Clone + One, 50 | { 51 | Range { 52 | state: start, 53 | stop, 54 | one: One::one(), 55 | } 56 | } 57 | 58 | #[inline] 59 | fn unsigned(x: &T) -> Option { 60 | match x.to_u128() { 61 | Some(u) => Some(u), 62 | None => Some(x.to_i128()? as u128), 63 | } 64 | } 65 | 66 | impl RangeBounds for Range { 67 | fn start_bound(&self) -> Bound<&A> { 68 | Bound::Included(&self.state) 69 | } 70 | 71 | fn end_bound(&self) -> Bound<&A> { 72 | Bound::Excluded(&self.stop) 73 | } 74 | } 75 | 76 | // FIXME: rust-lang/rust#10414: Unfortunate type bound 77 | impl Iterator for Range 78 | where 79 | A: Add + PartialOrd + Clone + ToPrimitive, 80 | { 81 | type Item = A; 82 | 83 | #[inline] 84 | fn next(&mut self) -> Option { 85 | if self.state < self.stop { 86 | let result = self.state.clone(); 87 | self.state = self.state.clone() + self.one.clone(); 88 | Some(result) 89 | } else { 90 | None 91 | } 92 | } 93 | 94 | #[inline] 95 | fn size_hint(&self) -> (usize, Option) { 96 | // Check for empty ranges first. 97 | if self.state >= self.stop { 98 | return (0, Some(0)); 99 | } 100 | 101 | // Try to cast both ends to the largest unsigned primitive. 102 | // Note that negative values will wrap to a large positive. 103 | if let Some(a) = unsigned(&self.state) { 104 | if let Some(b) = unsigned(&self.stop) { 105 | // We've lost signs, but we already know state < stop, so 106 | // a `wrapping_sub` will give the correct unsigned delta. 107 | return match b.wrapping_sub(a).to_usize() { 108 | Some(len) => (len, Some(len)), 109 | None => (usize::MAX, None), 110 | }; 111 | } 112 | } 113 | 114 | // Standard fallback for unbounded/unrepresentable bounds 115 | (0, None) 116 | } 117 | } 118 | 119 | /// `Integer` is required to ensure the range will be the same regardless of 120 | /// the direction it is consumed. 121 | impl DoubleEndedIterator for Range 122 | where 123 | A: Integer + Clone + ToPrimitive, 124 | { 125 | #[inline] 126 | fn next_back(&mut self) -> Option { 127 | if self.stop > self.state { 128 | self.stop.dec(); 129 | Some(self.stop.clone()) 130 | } else { 131 | None 132 | } 133 | } 134 | } 135 | 136 | /// An iterator over the range [start, stop] 137 | #[derive(Clone)] 138 | pub struct RangeInclusive { 139 | range: Range, 140 | done: bool, 141 | } 142 | 143 | /// Return an iterator over the range [start, stop] 144 | #[inline] 145 | pub fn range_inclusive(start: A, stop: A) -> RangeInclusive 146 | where 147 | A: Add + PartialOrd + Clone + One, 148 | { 149 | RangeInclusive { 150 | range: range(start, stop), 151 | done: false, 152 | } 153 | } 154 | 155 | impl RangeBounds for RangeInclusive { 156 | fn start_bound(&self) -> Bound<&A> { 157 | Bound::Included(&self.range.state) 158 | } 159 | 160 | fn end_bound(&self) -> Bound<&A> { 161 | Bound::Included(&self.range.stop) 162 | } 163 | } 164 | 165 | impl Iterator for RangeInclusive 166 | where 167 | A: Add + PartialOrd + Clone + ToPrimitive, 168 | { 169 | type Item = A; 170 | 171 | #[inline] 172 | fn next(&mut self) -> Option { 173 | match self.range.next() { 174 | Some(x) => Some(x), 175 | None => { 176 | if !self.done && self.range.state == self.range.stop { 177 | self.done = true; 178 | Some(self.range.stop.clone()) 179 | } else { 180 | None 181 | } 182 | } 183 | } 184 | } 185 | 186 | #[inline] 187 | fn size_hint(&self) -> (usize, Option) { 188 | let (lo, hi) = self.range.size_hint(); 189 | if self.done { 190 | (lo, hi) 191 | } else { 192 | let lo = lo.saturating_add(1); 193 | let hi = match hi { 194 | Some(x) => x.checked_add(1), 195 | None => None, 196 | }; 197 | (lo, hi) 198 | } 199 | } 200 | } 201 | 202 | impl DoubleEndedIterator for RangeInclusive 203 | where 204 | A: Sub + Integer + Clone + ToPrimitive, 205 | { 206 | #[inline] 207 | fn next_back(&mut self) -> Option { 208 | if self.range.stop > self.range.state { 209 | let result = self.range.stop.clone(); 210 | self.range.stop.dec(); 211 | Some(result) 212 | } else if !self.done && self.range.state == self.range.stop { 213 | self.done = true; 214 | Some(self.range.stop.clone()) 215 | } else { 216 | None 217 | } 218 | } 219 | } 220 | 221 | /// An iterator over the range [start, stop) by `step`. It handles overflow by stopping. 222 | #[derive(Clone)] 223 | pub struct RangeStep { 224 | state: A, 225 | stop: A, 226 | step: A, 227 | rev: bool, 228 | } 229 | 230 | /// Return an iterator over the range [start, stop) by `step`. It handles overflow by stopping. 231 | #[inline] 232 | pub fn range_step(start: A, stop: A, step: A) -> RangeStep 233 | where 234 | A: CheckedAdd + PartialOrd + Clone + Zero, 235 | { 236 | let rev = step < Zero::zero(); 237 | RangeStep { 238 | state: start, 239 | stop, 240 | step, 241 | rev, 242 | } 243 | } 244 | 245 | impl Iterator for RangeStep 246 | where 247 | A: CheckedAdd + PartialOrd + Clone, 248 | { 249 | type Item = A; 250 | 251 | #[inline] 252 | fn next(&mut self) -> Option { 253 | if (self.rev && self.state > self.stop) || (!self.rev && self.state < self.stop) { 254 | let result = self.state.clone(); 255 | match self.state.checked_add(&self.step) { 256 | Some(x) => self.state = x, 257 | None => self.state = self.stop.clone(), 258 | } 259 | Some(result) 260 | } else { 261 | None 262 | } 263 | } 264 | } 265 | 266 | /// An iterator over the range [start, stop] by `step`. It handles overflow by stopping. 267 | #[derive(Clone)] 268 | pub struct RangeStepInclusive { 269 | state: A, 270 | stop: A, 271 | step: A, 272 | rev: bool, 273 | done: bool, 274 | } 275 | 276 | /// Return an iterator over the range [start, stop] by `step`. It handles overflow by stopping. 277 | #[inline] 278 | pub fn range_step_inclusive(start: A, stop: A, step: A) -> RangeStepInclusive 279 | where 280 | A: CheckedAdd + PartialOrd + Clone + Zero, 281 | { 282 | let rev = step < Zero::zero(); 283 | RangeStepInclusive { 284 | state: start, 285 | stop, 286 | step, 287 | rev, 288 | done: false, 289 | } 290 | } 291 | 292 | impl Iterator for RangeStepInclusive 293 | where 294 | A: CheckedAdd + PartialOrd + Clone + PartialEq, 295 | { 296 | type Item = A; 297 | 298 | #[inline] 299 | fn next(&mut self) -> Option { 300 | if !self.done 301 | && ((self.rev && self.state >= self.stop) || (!self.rev && self.state <= self.stop)) 302 | { 303 | let result = self.state.clone(); 304 | match self.state.checked_add(&self.step) { 305 | Some(x) => self.state = x, 306 | None => self.done = true, 307 | } 308 | Some(result) 309 | } else { 310 | None 311 | } 312 | } 313 | } 314 | 315 | /// An iterator over the infinite range starting at `start` 316 | #[derive(Clone)] 317 | pub struct RangeFrom { 318 | state: A, 319 | one: A, 320 | } 321 | 322 | /// Return an iterator over the infinite range starting at `start` and continuing forever. 323 | /// 324 | /// *Note*: Currently, the `Iterator` implementation is not checked for overflow. 325 | /// If you use a finite-sized integer type and the integer overflows, 326 | /// it might panic in debug mode or wrap around in release mode. 327 | /// **This behavior is not guaranteed and may change at any time.** 328 | #[inline] 329 | pub fn range_from(start: A) -> RangeFrom 330 | where 331 | A: Add + Clone + One, 332 | { 333 | RangeFrom { 334 | state: start, 335 | one: One::one(), 336 | } 337 | } 338 | 339 | impl RangeBounds for RangeFrom { 340 | fn start_bound(&self) -> Bound<&A> { 341 | Bound::Included(&self.state) 342 | } 343 | 344 | fn end_bound(&self) -> Bound<&A> { 345 | Bound::Unbounded 346 | } 347 | } 348 | 349 | impl Iterator for RangeFrom 350 | where 351 | A: Add + Clone, 352 | { 353 | type Item = A; 354 | 355 | #[inline] 356 | fn next(&mut self) -> Option { 357 | let result = self.state.clone(); 358 | self.state = self.state.clone() + self.one.clone(); 359 | Some(result) 360 | } 361 | 362 | #[inline] 363 | fn size_hint(&self) -> (usize, Option) { 364 | (usize::MAX, None) 365 | } 366 | } 367 | 368 | /// An iterator over the infinite range starting at `start` by `step` 369 | #[derive(Clone)] 370 | pub struct RangeStepFrom { 371 | state: A, 372 | step: A, 373 | } 374 | 375 | /// Return an iterator over the infinite range starting at `start` and continuing forever by `step`. 376 | /// 377 | /// *Note*: Currently, the `Iterator` implementation is not checked for overflow. 378 | /// If you use a finite-sized integer type and the integer overflows, 379 | /// it might panic in debug mode or wrap around in release mode. 380 | /// **This behavior is not guaranteed and may change at any time.** 381 | #[inline] 382 | pub fn range_step_from(start: A, step: A) -> RangeStepFrom 383 | where 384 | A: Add + Clone, 385 | { 386 | RangeStepFrom { state: start, step } 387 | } 388 | 389 | impl Iterator for RangeStepFrom 390 | where 391 | A: Add + Clone, 392 | { 393 | type Item = A; 394 | 395 | #[inline] 396 | fn next(&mut self) -> Option { 397 | let result = self.state.clone(); 398 | self.state = self.state.clone() + self.step.clone(); 399 | Some(result) 400 | } 401 | 402 | #[inline] 403 | fn size_hint(&self) -> (usize, Option) { 404 | (usize::MAX, None) 405 | } 406 | } 407 | 408 | #[cfg(test)] 409 | mod tests { 410 | use core::cmp::Ordering; 411 | use core::iter; 412 | use core::ops::{Add, Mul}; 413 | use core::{isize, usize}; 414 | use num_traits::{One, ToPrimitive}; 415 | 416 | #[test] 417 | fn test_range() { 418 | /// A mock type to check Range when ToPrimitive returns None 419 | struct Foo; 420 | 421 | impl ToPrimitive for Foo { 422 | fn to_i64(&self) -> Option { 423 | None 424 | } 425 | fn to_u64(&self) -> Option { 426 | None 427 | } 428 | } 429 | 430 | impl Add for Foo { 431 | type Output = Foo; 432 | 433 | fn add(self, _: Foo) -> Foo { 434 | Foo 435 | } 436 | } 437 | 438 | impl PartialEq for Foo { 439 | fn eq(&self, _: &Foo) -> bool { 440 | true 441 | } 442 | } 443 | 444 | impl PartialOrd for Foo { 445 | fn partial_cmp(&self, _: &Foo) -> Option { 446 | None 447 | } 448 | } 449 | 450 | impl Clone for Foo { 451 | fn clone(&self) -> Foo { 452 | Foo 453 | } 454 | } 455 | 456 | impl Mul for Foo { 457 | type Output = Foo; 458 | 459 | fn mul(self, _: Foo) -> Foo { 460 | Foo 461 | } 462 | } 463 | 464 | impl One for Foo { 465 | fn one() -> Foo { 466 | Foo 467 | } 468 | } 469 | 470 | assert!(super::range(0, 5).eq([0, 1, 2, 3, 4].iter().cloned())); 471 | assert!(super::range(-10, -1).eq([-10, -9, -8, -7, -6, -5, -4, -3, -2].iter().cloned())); 472 | assert!(super::range(0, 5).rev().eq([4, 3, 2, 1, 0].iter().cloned())); 473 | assert_eq!(super::range(200, -5).count(), 0); 474 | assert_eq!(super::range(200, -5).rev().count(), 0); 475 | assert_eq!(super::range(200, 200).count(), 0); 476 | assert_eq!(super::range(200, 200).rev().count(), 0); 477 | 478 | assert_eq!(super::range(0, 100).size_hint(), (100, Some(100))); 479 | // this test is only meaningful when sizeof usize < sizeof u64 480 | assert_eq!( 481 | super::range(usize::MAX - 1, usize::MAX).size_hint(), 482 | (1, Some(1)) 483 | ); 484 | assert_eq!(super::range(-10, -1).size_hint(), (9, Some(9))); 485 | assert_eq!( 486 | super::range(isize::MIN, isize::MAX).size_hint(), 487 | (usize::MAX, Some(usize::MAX)) 488 | ); 489 | } 490 | 491 | #[test] 492 | fn test_range_128() { 493 | use core::{i128, u128}; 494 | 495 | assert!(super::range(0i128, 5).eq([0, 1, 2, 3, 4].iter().cloned())); 496 | assert!(super::range(-10i128, -1).eq([-10, -9, -8, -7, -6, -5, -4, -3, -2].iter().cloned())); 497 | assert!(super::range(0u128, 5) 498 | .rev() 499 | .eq([4, 3, 2, 1, 0].iter().cloned())); 500 | 501 | assert_eq!( 502 | super::range(i128::MIN, i128::MIN + 1).size_hint(), 503 | (1, Some(1)) 504 | ); 505 | assert_eq!( 506 | super::range(i128::MAX - 1, i128::MAX).size_hint(), 507 | (1, Some(1)) 508 | ); 509 | assert_eq!( 510 | super::range(i128::MIN, i128::MAX).size_hint(), 511 | (usize::MAX, None) 512 | ); 513 | 514 | assert_eq!( 515 | super::range(u128::MAX - 1, u128::MAX).size_hint(), 516 | (1, Some(1)) 517 | ); 518 | assert_eq!( 519 | super::range(0, usize::MAX as u128).size_hint(), 520 | (usize::MAX, Some(usize::MAX)) 521 | ); 522 | assert_eq!( 523 | super::range(0, usize::MAX as u128 + 1).size_hint(), 524 | (usize::MAX, None) 525 | ); 526 | assert_eq!(super::range(0, i128::MAX).size_hint(), (usize::MAX, None)); 527 | } 528 | 529 | #[test] 530 | fn test_range_inclusive() { 531 | assert!(super::range_inclusive(0, 5).eq([0, 1, 2, 3, 4, 5].iter().cloned())); 532 | assert!(super::range_inclusive(0, 5) 533 | .rev() 534 | .eq([5, 4, 3, 2, 1, 0].iter().cloned())); 535 | assert_eq!(super::range_inclusive(200, -5).count(), 0); 536 | assert_eq!(super::range_inclusive(200, -5).rev().count(), 0); 537 | assert!(super::range_inclusive(200, 200).eq(iter::once(200))); 538 | assert!(super::range_inclusive(200, 200).rev().eq(iter::once(200))); 539 | assert_eq!( 540 | super::range_inclusive(isize::MIN, isize::MAX - 1).size_hint(), 541 | (usize::MAX, Some(usize::MAX)) 542 | ); 543 | assert_eq!( 544 | super::range_inclusive(isize::MIN, isize::MAX).size_hint(), 545 | (usize::MAX, None) 546 | ); 547 | } 548 | 549 | #[test] 550 | fn test_range_inclusive_128() { 551 | use core::i128; 552 | 553 | assert!(super::range_inclusive(0u128, 5).eq([0, 1, 2, 3, 4, 5].iter().cloned())); 554 | assert!(super::range_inclusive(0u128, 5) 555 | .rev() 556 | .eq([5, 4, 3, 2, 1, 0].iter().cloned())); 557 | assert_eq!(super::range_inclusive(200i128, -5).count(), 0); 558 | assert_eq!(super::range_inclusive(200i128, -5).rev().count(), 0); 559 | assert!(super::range_inclusive(200u128, 200).eq(iter::once(200))); 560 | assert!(super::range_inclusive(200u128, 200) 561 | .rev() 562 | .eq(iter::once(200))); 563 | assert_eq!( 564 | super::range_inclusive(isize::MIN as i128, isize::MAX as i128 - 1).size_hint(), 565 | (usize::MAX, Some(usize::MAX)) 566 | ); 567 | assert_eq!( 568 | super::range_inclusive(isize::MIN as i128, isize::MAX as i128).size_hint(), 569 | (usize::MAX, None) 570 | ); 571 | assert_eq!( 572 | super::range_inclusive(isize::MIN as i128, isize::MAX as i128 + 1).size_hint(), 573 | (usize::MAX, None) 574 | ); 575 | assert_eq!( 576 | super::range_inclusive(i128::MIN, i128::MAX).size_hint(), 577 | (usize::MAX, None) 578 | ); 579 | } 580 | 581 | #[test] 582 | fn test_range_step() { 583 | assert!(super::range_step(0, 20, 5).eq([0, 5, 10, 15].iter().cloned())); 584 | assert!(super::range_step(20, 0, -5).eq([20, 15, 10, 5].iter().cloned())); 585 | assert!(super::range_step(20, 0, -6).eq([20, 14, 8, 2].iter().cloned())); 586 | assert!(super::range_step(200u8, 255, 50).eq([200u8, 250].iter().cloned())); 587 | assert!(super::range_step(200, -5, 1).eq(iter::empty())); 588 | assert!(super::range_step(200, 200, 1).eq(iter::empty())); 589 | } 590 | 591 | #[test] 592 | fn test_range_step_128() { 593 | use core::u128::MAX as UMAX; 594 | 595 | assert!(super::range_step(0u128, 20, 5).eq([0, 5, 10, 15].iter().cloned())); 596 | assert!(super::range_step(20i128, 0, -5).eq([20, 15, 10, 5].iter().cloned())); 597 | assert!(super::range_step(20i128, 0, -6).eq([20, 14, 8, 2].iter().cloned())); 598 | assert!(super::range_step(UMAX - 55, UMAX, 50).eq([UMAX - 55, UMAX - 5].iter().cloned())); 599 | assert!(super::range_step(200i128, -5, 1).eq(iter::empty())); 600 | assert!(super::range_step(200i128, 200, 1).eq(iter::empty())); 601 | } 602 | 603 | #[test] 604 | fn test_range_step_inclusive() { 605 | assert!(super::range_step_inclusive(0, 20, 5).eq([0, 5, 10, 15, 20].iter().cloned())); 606 | assert!(super::range_step_inclusive(20, 0, -5).eq([20, 15, 10, 5, 0].iter().cloned())); 607 | assert!(super::range_step_inclusive(20, 0, -6).eq([20, 14, 8, 2].iter().cloned())); 608 | assert!(super::range_step_inclusive(200u8, 255, 50).eq([200u8, 250].iter().cloned())); 609 | assert!(super::range_step_inclusive(200, -5, 1).eq(iter::empty())); 610 | assert!(super::range_step_inclusive(200, 200, 1).eq(iter::once(200))); 611 | } 612 | 613 | #[test] 614 | fn test_range_step_inclusive_128() { 615 | use core::u128::MAX as UMAX; 616 | 617 | assert!(super::range_step_inclusive(0u128, 20, 5).eq([0, 5, 10, 15, 20].iter().cloned())); 618 | assert!(super::range_step_inclusive(20i128, 0, -5).eq([20, 15, 10, 5, 0].iter().cloned())); 619 | assert!(super::range_step_inclusive(20i128, 0, -6).eq([20, 14, 8, 2].iter().cloned())); 620 | assert!(super::range_step_inclusive(UMAX - 55, UMAX, 50) 621 | .eq([UMAX - 55, UMAX - 5].iter().cloned())); 622 | assert!(super::range_step_inclusive(200i128, -5, 1).eq(iter::empty())); 623 | assert!(super::range_step_inclusive(200i128, 200, 1).eq(iter::once(200))); 624 | } 625 | 626 | #[test] 627 | fn test_range_from() { 628 | assert!(super::range_from(10u8) 629 | .take(5) 630 | .eq([10, 11, 12, 13, 14].iter().cloned())); 631 | assert_eq!(super::range_from(10u8).size_hint(), (usize::MAX, None)); 632 | } 633 | 634 | #[test] 635 | fn test_range_step_from() { 636 | assert!(super::range_step_from(10u8, 2u8) 637 | .take(5) 638 | .eq([10, 12, 14, 16, 18].iter().cloned())); 639 | assert_eq!( 640 | super::range_step_from(10u8, 2u8).size_hint(), 641 | (usize::MAX, None) 642 | ); 643 | 644 | assert!(super::range_step_from(10u8, 1u8) 645 | .take(5) 646 | .eq([10, 11, 12, 13, 14].iter().cloned())); 647 | assert_eq!( 648 | super::range_step_from(10u8, 1u8).size_hint(), 649 | (usize::MAX, None) 650 | ); 651 | 652 | assert!(super::range_step_from(10u8, 0u8) 653 | .take(5) 654 | .eq([10, 10, 10, 10, 10].iter().cloned())); 655 | assert_eq!( 656 | super::range_step_from(10u8, 0u8).size_hint(), 657 | (usize::MAX, None) 658 | ); 659 | 660 | assert!(super::range_step_from(10i8, 2i8) 661 | .take(5) 662 | .eq([10, 12, 14, 16, 18].iter().cloned())); 663 | assert_eq!( 664 | super::range_step_from(10i8, 2i8).size_hint(), 665 | (usize::MAX, None) 666 | ); 667 | 668 | assert!(super::range_step_from(10i8, 1i8) 669 | .take(5) 670 | .eq([10, 11, 12, 13, 14].iter().cloned())); 671 | assert_eq!( 672 | super::range_step_from(10i8, 1i8).size_hint(), 673 | (usize::MAX, None) 674 | ); 675 | 676 | assert!(super::range_step_from(10i8, 0i8) 677 | .take(5) 678 | .eq([10, 10, 10, 10, 10].iter().cloned())); 679 | assert_eq!( 680 | super::range_step_from(10i8, 0i8).size_hint(), 681 | (usize::MAX, None) 682 | ); 683 | 684 | assert!(super::range_step_from(10i8, -1i8) 685 | .take(5) 686 | .eq([10, 9, 8, 7, 6].iter().cloned())); 687 | assert_eq!( 688 | super::range_step_from(10i8, -1i8).size_hint(), 689 | (usize::MAX, None) 690 | ); 691 | 692 | assert!(super::range_step_from(10i8, -2i8) 693 | .take(5) 694 | .eq([10, 8, 6, 4, 2].iter().cloned())); 695 | assert_eq!( 696 | super::range_step_from(10i8, -2i8).size_hint(), 697 | (usize::MAX, None) 698 | ); 699 | } 700 | } 701 | --------------------------------------------------------------------------------