├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── docker-publish.yml │ └── rust.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── Cargo.lock ├── Cargo.toml ├── Dockerfile ├── LICENSE ├── README.md ├── assets └── logo.png ├── benches └── bench.rs └── src └── main.rs /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [thomaschaplin] 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/docker-publish.yml: -------------------------------------------------------------------------------- 1 | name: Docker Image CI 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v3 13 | - name: docker login 14 | env: 15 | DOCKER_USER: ${{secrets.DOCKER_USER}} 16 | DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}} 17 | run: | 18 | docker login -u $DOCKER_USER -p $DOCKER_PASSWORD 19 | - name: Build the Docker image 20 | run: docker build . --file Dockerfile --tag thomaschaplin/rust-counter-strings 21 | 22 | - name: Docker Push 23 | run: docker push thomaschaplin/rust-counter-strings 24 | -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v3 17 | - name: Check 18 | run: cargo check --verbose 19 | - name: Format 20 | run: cargo fmt --all -- --check --verbose 21 | - name: Clippy 22 | run: cargo clippy -- -D warnings --verbose 23 | - name: Test 24 | run: cargo test --verbose 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | thomaschaplin@outlook.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "anes" 7 | version = "0.1.6" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" 10 | 11 | [[package]] 12 | name = "anstyle" 13 | version = "1.0.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" 16 | 17 | [[package]] 18 | name = "autocfg" 19 | version = "1.0.1" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 22 | 23 | [[package]] 24 | name = "bitflags" 25 | version = "1.3.2" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 28 | 29 | [[package]] 30 | name = "bumpalo" 31 | version = "3.7.0" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" 34 | 35 | [[package]] 36 | name = "cast" 37 | version = "0.3.0" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" 40 | 41 | [[package]] 42 | name = "cc" 43 | version = "1.0.79" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" 46 | 47 | [[package]] 48 | name = "cfg-if" 49 | version = "1.0.0" 50 | source = "registry+https://github.com/rust-lang/crates.io-index" 51 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 52 | 53 | [[package]] 54 | name = "ciborium" 55 | version = "0.2.1" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" 58 | dependencies = [ 59 | "ciborium-io", 60 | "ciborium-ll", 61 | "serde", 62 | ] 63 | 64 | [[package]] 65 | name = "ciborium-io" 66 | version = "0.2.1" 67 | source = "registry+https://github.com/rust-lang/crates.io-index" 68 | checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" 69 | 70 | [[package]] 71 | name = "ciborium-ll" 72 | version = "0.2.1" 73 | source = "registry+https://github.com/rust-lang/crates.io-index" 74 | checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" 75 | dependencies = [ 76 | "ciborium-io", 77 | "half", 78 | ] 79 | 80 | [[package]] 81 | name = "clap" 82 | version = "4.3.2" 83 | source = "registry+https://github.com/rust-lang/crates.io-index" 84 | checksum = "401a4694d2bf92537b6867d94de48c4842089645fdcdf6c71865b175d836e9c2" 85 | dependencies = [ 86 | "clap_builder", 87 | ] 88 | 89 | [[package]] 90 | name = "clap_builder" 91 | version = "4.3.1" 92 | source = "registry+https://github.com/rust-lang/crates.io-index" 93 | checksum = "72394f3339a76daf211e57d4bcb374410f3965dcc606dd0e03738c7888766980" 94 | dependencies = [ 95 | "anstyle", 96 | "bitflags", 97 | "clap_lex", 98 | ] 99 | 100 | [[package]] 101 | name = "clap_lex" 102 | version = "0.5.0" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" 105 | 106 | [[package]] 107 | name = "criterion" 108 | version = "0.5.1" 109 | source = "registry+https://github.com/rust-lang/crates.io-index" 110 | checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" 111 | dependencies = [ 112 | "anes", 113 | "cast", 114 | "ciborium", 115 | "clap", 116 | "criterion-plot", 117 | "is-terminal", 118 | "itertools", 119 | "num-traits", 120 | "once_cell", 121 | "oorandom", 122 | "plotters", 123 | "rayon", 124 | "regex", 125 | "serde", 126 | "serde_derive", 127 | "serde_json", 128 | "tinytemplate", 129 | "walkdir", 130 | ] 131 | 132 | [[package]] 133 | name = "criterion-plot" 134 | version = "0.5.0" 135 | source = "registry+https://github.com/rust-lang/crates.io-index" 136 | checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" 137 | dependencies = [ 138 | "cast", 139 | "itertools", 140 | ] 141 | 142 | [[package]] 143 | name = "crossbeam-channel" 144 | version = "0.5.1" 145 | source = "registry+https://github.com/rust-lang/crates.io-index" 146 | checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" 147 | dependencies = [ 148 | "cfg-if", 149 | "crossbeam-utils", 150 | ] 151 | 152 | [[package]] 153 | name = "crossbeam-deque" 154 | version = "0.8.1" 155 | source = "registry+https://github.com/rust-lang/crates.io-index" 156 | checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" 157 | dependencies = [ 158 | "cfg-if", 159 | "crossbeam-epoch", 160 | "crossbeam-utils", 161 | ] 162 | 163 | [[package]] 164 | name = "crossbeam-epoch" 165 | version = "0.9.5" 166 | source = "registry+https://github.com/rust-lang/crates.io-index" 167 | checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" 168 | dependencies = [ 169 | "cfg-if", 170 | "crossbeam-utils", 171 | "lazy_static", 172 | "memoffset", 173 | "scopeguard", 174 | ] 175 | 176 | [[package]] 177 | name = "crossbeam-utils" 178 | version = "0.8.5" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" 181 | dependencies = [ 182 | "cfg-if", 183 | "lazy_static", 184 | ] 185 | 186 | [[package]] 187 | name = "either" 188 | version = "1.6.1" 189 | source = "registry+https://github.com/rust-lang/crates.io-index" 190 | checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" 191 | 192 | [[package]] 193 | name = "errno" 194 | version = "0.3.1" 195 | source = "registry+https://github.com/rust-lang/crates.io-index" 196 | checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" 197 | dependencies = [ 198 | "errno-dragonfly", 199 | "libc", 200 | "windows-sys", 201 | ] 202 | 203 | [[package]] 204 | name = "errno-dragonfly" 205 | version = "0.1.2" 206 | source = "registry+https://github.com/rust-lang/crates.io-index" 207 | checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" 208 | dependencies = [ 209 | "cc", 210 | "libc", 211 | ] 212 | 213 | [[package]] 214 | name = "half" 215 | version = "1.7.1" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" 218 | 219 | [[package]] 220 | name = "hermit-abi" 221 | version = "0.1.19" 222 | source = "registry+https://github.com/rust-lang/crates.io-index" 223 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 224 | dependencies = [ 225 | "libc", 226 | ] 227 | 228 | [[package]] 229 | name = "hermit-abi" 230 | version = "0.3.1" 231 | source = "registry+https://github.com/rust-lang/crates.io-index" 232 | checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" 233 | 234 | [[package]] 235 | name = "io-lifetimes" 236 | version = "1.0.11" 237 | source = "registry+https://github.com/rust-lang/crates.io-index" 238 | checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" 239 | dependencies = [ 240 | "hermit-abi 0.3.1", 241 | "libc", 242 | "windows-sys", 243 | ] 244 | 245 | [[package]] 246 | name = "is-terminal" 247 | version = "0.4.7" 248 | source = "registry+https://github.com/rust-lang/crates.io-index" 249 | checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" 250 | dependencies = [ 251 | "hermit-abi 0.3.1", 252 | "io-lifetimes", 253 | "rustix", 254 | "windows-sys", 255 | ] 256 | 257 | [[package]] 258 | name = "itertools" 259 | version = "0.10.1" 260 | source = "registry+https://github.com/rust-lang/crates.io-index" 261 | checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" 262 | dependencies = [ 263 | "either", 264 | ] 265 | 266 | [[package]] 267 | name = "itoa" 268 | version = "0.4.8" 269 | source = "registry+https://github.com/rust-lang/crates.io-index" 270 | checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" 271 | 272 | [[package]] 273 | name = "js-sys" 274 | version = "0.3.54" 275 | source = "registry+https://github.com/rust-lang/crates.io-index" 276 | checksum = "1866b355d9c878e5e607473cbe3f63282c0b7aad2db1dbebf55076c686918254" 277 | dependencies = [ 278 | "wasm-bindgen", 279 | ] 280 | 281 | [[package]] 282 | name = "lazy_static" 283 | version = "1.4.0" 284 | source = "registry+https://github.com/rust-lang/crates.io-index" 285 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 286 | 287 | [[package]] 288 | name = "libc" 289 | version = "0.2.146" 290 | source = "registry+https://github.com/rust-lang/crates.io-index" 291 | checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" 292 | 293 | [[package]] 294 | name = "linux-raw-sys" 295 | version = "0.3.8" 296 | source = "registry+https://github.com/rust-lang/crates.io-index" 297 | checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" 298 | 299 | [[package]] 300 | name = "log" 301 | version = "0.4.14" 302 | source = "registry+https://github.com/rust-lang/crates.io-index" 303 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 304 | dependencies = [ 305 | "cfg-if", 306 | ] 307 | 308 | [[package]] 309 | name = "memoffset" 310 | version = "0.6.4" 311 | source = "registry+https://github.com/rust-lang/crates.io-index" 312 | checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" 313 | dependencies = [ 314 | "autocfg", 315 | ] 316 | 317 | [[package]] 318 | name = "num-traits" 319 | version = "0.2.14" 320 | source = "registry+https://github.com/rust-lang/crates.io-index" 321 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" 322 | dependencies = [ 323 | "autocfg", 324 | ] 325 | 326 | [[package]] 327 | name = "num_cpus" 328 | version = "1.13.0" 329 | source = "registry+https://github.com/rust-lang/crates.io-index" 330 | checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" 331 | dependencies = [ 332 | "hermit-abi 0.1.19", 333 | "libc", 334 | ] 335 | 336 | [[package]] 337 | name = "once_cell" 338 | version = "1.18.0" 339 | source = "registry+https://github.com/rust-lang/crates.io-index" 340 | checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" 341 | 342 | [[package]] 343 | name = "oorandom" 344 | version = "11.1.3" 345 | source = "registry+https://github.com/rust-lang/crates.io-index" 346 | checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" 347 | 348 | [[package]] 349 | name = "plotters" 350 | version = "0.3.1" 351 | source = "registry+https://github.com/rust-lang/crates.io-index" 352 | checksum = "32a3fd9ec30b9749ce28cd91f255d569591cdf937fe280c312143e3c4bad6f2a" 353 | dependencies = [ 354 | "num-traits", 355 | "plotters-backend", 356 | "plotters-svg", 357 | "wasm-bindgen", 358 | "web-sys", 359 | ] 360 | 361 | [[package]] 362 | name = "plotters-backend" 363 | version = "0.3.2" 364 | source = "registry+https://github.com/rust-lang/crates.io-index" 365 | checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" 366 | 367 | [[package]] 368 | name = "plotters-svg" 369 | version = "0.3.1" 370 | source = "registry+https://github.com/rust-lang/crates.io-index" 371 | checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" 372 | dependencies = [ 373 | "plotters-backend", 374 | ] 375 | 376 | [[package]] 377 | name = "proc-macro2" 378 | version = "1.0.29" 379 | source = "registry+https://github.com/rust-lang/crates.io-index" 380 | checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" 381 | dependencies = [ 382 | "unicode-xid", 383 | ] 384 | 385 | [[package]] 386 | name = "quote" 387 | version = "1.0.9" 388 | source = "registry+https://github.com/rust-lang/crates.io-index" 389 | checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" 390 | dependencies = [ 391 | "proc-macro2", 392 | ] 393 | 394 | [[package]] 395 | name = "rayon" 396 | version = "1.5.1" 397 | source = "registry+https://github.com/rust-lang/crates.io-index" 398 | checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" 399 | dependencies = [ 400 | "autocfg", 401 | "crossbeam-deque", 402 | "either", 403 | "rayon-core", 404 | ] 405 | 406 | [[package]] 407 | name = "rayon-core" 408 | version = "1.9.1" 409 | source = "registry+https://github.com/rust-lang/crates.io-index" 410 | checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" 411 | dependencies = [ 412 | "crossbeam-channel", 413 | "crossbeam-deque", 414 | "crossbeam-utils", 415 | "lazy_static", 416 | "num_cpus", 417 | ] 418 | 419 | [[package]] 420 | name = "regex" 421 | version = "1.5.4" 422 | source = "registry+https://github.com/rust-lang/crates.io-index" 423 | checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" 424 | dependencies = [ 425 | "regex-syntax", 426 | ] 427 | 428 | [[package]] 429 | name = "regex-syntax" 430 | version = "0.6.25" 431 | source = "registry+https://github.com/rust-lang/crates.io-index" 432 | checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" 433 | 434 | [[package]] 435 | name = "rust-counter-strings" 436 | version = "0.1.0" 437 | dependencies = [ 438 | "criterion", 439 | "unicode-segmentation", 440 | ] 441 | 442 | [[package]] 443 | name = "rustix" 444 | version = "0.37.19" 445 | source = "registry+https://github.com/rust-lang/crates.io-index" 446 | checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" 447 | dependencies = [ 448 | "bitflags", 449 | "errno", 450 | "io-lifetimes", 451 | "libc", 452 | "linux-raw-sys", 453 | "windows-sys", 454 | ] 455 | 456 | [[package]] 457 | name = "ryu" 458 | version = "1.0.5" 459 | source = "registry+https://github.com/rust-lang/crates.io-index" 460 | checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" 461 | 462 | [[package]] 463 | name = "same-file" 464 | version = "1.0.6" 465 | source = "registry+https://github.com/rust-lang/crates.io-index" 466 | checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" 467 | dependencies = [ 468 | "winapi-util", 469 | ] 470 | 471 | [[package]] 472 | name = "scopeguard" 473 | version = "1.1.0" 474 | source = "registry+https://github.com/rust-lang/crates.io-index" 475 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 476 | 477 | [[package]] 478 | name = "serde" 479 | version = "1.0.130" 480 | source = "registry+https://github.com/rust-lang/crates.io-index" 481 | checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" 482 | dependencies = [ 483 | "serde_derive", 484 | ] 485 | 486 | [[package]] 487 | name = "serde_derive" 488 | version = "1.0.130" 489 | source = "registry+https://github.com/rust-lang/crates.io-index" 490 | checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" 491 | dependencies = [ 492 | "proc-macro2", 493 | "quote", 494 | "syn", 495 | ] 496 | 497 | [[package]] 498 | name = "serde_json" 499 | version = "1.0.67" 500 | source = "registry+https://github.com/rust-lang/crates.io-index" 501 | checksum = "a7f9e390c27c3c0ce8bc5d725f6e4d30a29d26659494aa4b17535f7522c5c950" 502 | dependencies = [ 503 | "itoa", 504 | "ryu", 505 | "serde", 506 | ] 507 | 508 | [[package]] 509 | name = "syn" 510 | version = "1.0.76" 511 | source = "registry+https://github.com/rust-lang/crates.io-index" 512 | checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84" 513 | dependencies = [ 514 | "proc-macro2", 515 | "quote", 516 | "unicode-xid", 517 | ] 518 | 519 | [[package]] 520 | name = "tinytemplate" 521 | version = "1.2.1" 522 | source = "registry+https://github.com/rust-lang/crates.io-index" 523 | checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" 524 | dependencies = [ 525 | "serde", 526 | "serde_json", 527 | ] 528 | 529 | [[package]] 530 | name = "unicode-segmentation" 531 | version = "1.11.0" 532 | source = "registry+https://github.com/rust-lang/crates.io-index" 533 | checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" 534 | 535 | [[package]] 536 | name = "unicode-xid" 537 | version = "0.2.2" 538 | source = "registry+https://github.com/rust-lang/crates.io-index" 539 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 540 | 541 | [[package]] 542 | name = "walkdir" 543 | version = "2.3.2" 544 | source = "registry+https://github.com/rust-lang/crates.io-index" 545 | checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" 546 | dependencies = [ 547 | "same-file", 548 | "winapi", 549 | "winapi-util", 550 | ] 551 | 552 | [[package]] 553 | name = "wasm-bindgen" 554 | version = "0.2.77" 555 | source = "registry+https://github.com/rust-lang/crates.io-index" 556 | checksum = "5e68338db6becec24d3c7977b5bf8a48be992c934b5d07177e3931f5dc9b076c" 557 | dependencies = [ 558 | "cfg-if", 559 | "wasm-bindgen-macro", 560 | ] 561 | 562 | [[package]] 563 | name = "wasm-bindgen-backend" 564 | version = "0.2.77" 565 | source = "registry+https://github.com/rust-lang/crates.io-index" 566 | checksum = "f34c405b4f0658583dba0c1c7c9b694f3cac32655db463b56c254a1c75269523" 567 | dependencies = [ 568 | "bumpalo", 569 | "lazy_static", 570 | "log", 571 | "proc-macro2", 572 | "quote", 573 | "syn", 574 | "wasm-bindgen-shared", 575 | ] 576 | 577 | [[package]] 578 | name = "wasm-bindgen-macro" 579 | version = "0.2.77" 580 | source = "registry+https://github.com/rust-lang/crates.io-index" 581 | checksum = "b9d5a6580be83b19dc570a8f9c324251687ab2184e57086f71625feb57ec77c8" 582 | dependencies = [ 583 | "quote", 584 | "wasm-bindgen-macro-support", 585 | ] 586 | 587 | [[package]] 588 | name = "wasm-bindgen-macro-support" 589 | version = "0.2.77" 590 | source = "registry+https://github.com/rust-lang/crates.io-index" 591 | checksum = "e3775a030dc6f5a0afd8a84981a21cc92a781eb429acef9ecce476d0c9113e92" 592 | dependencies = [ 593 | "proc-macro2", 594 | "quote", 595 | "syn", 596 | "wasm-bindgen-backend", 597 | "wasm-bindgen-shared", 598 | ] 599 | 600 | [[package]] 601 | name = "wasm-bindgen-shared" 602 | version = "0.2.77" 603 | source = "registry+https://github.com/rust-lang/crates.io-index" 604 | checksum = "c279e376c7a8e8752a8f1eaa35b7b0bee6bb9fb0cdacfa97cc3f1f289c87e2b4" 605 | 606 | [[package]] 607 | name = "web-sys" 608 | version = "0.3.54" 609 | source = "registry+https://github.com/rust-lang/crates.io-index" 610 | checksum = "0a84d70d1ec7d2da2d26a5bd78f4bca1b8c3254805363ce743b7a05bc30d195a" 611 | dependencies = [ 612 | "js-sys", 613 | "wasm-bindgen", 614 | ] 615 | 616 | [[package]] 617 | name = "winapi" 618 | version = "0.3.9" 619 | source = "registry+https://github.com/rust-lang/crates.io-index" 620 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 621 | dependencies = [ 622 | "winapi-i686-pc-windows-gnu", 623 | "winapi-x86_64-pc-windows-gnu", 624 | ] 625 | 626 | [[package]] 627 | name = "winapi-i686-pc-windows-gnu" 628 | version = "0.4.0" 629 | source = "registry+https://github.com/rust-lang/crates.io-index" 630 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 631 | 632 | [[package]] 633 | name = "winapi-util" 634 | version = "0.1.5" 635 | source = "registry+https://github.com/rust-lang/crates.io-index" 636 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 637 | dependencies = [ 638 | "winapi", 639 | ] 640 | 641 | [[package]] 642 | name = "winapi-x86_64-pc-windows-gnu" 643 | version = "0.4.0" 644 | source = "registry+https://github.com/rust-lang/crates.io-index" 645 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 646 | 647 | [[package]] 648 | name = "windows-sys" 649 | version = "0.48.0" 650 | source = "registry+https://github.com/rust-lang/crates.io-index" 651 | checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" 652 | dependencies = [ 653 | "windows-targets", 654 | ] 655 | 656 | [[package]] 657 | name = "windows-targets" 658 | version = "0.48.0" 659 | source = "registry+https://github.com/rust-lang/crates.io-index" 660 | checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" 661 | dependencies = [ 662 | "windows_aarch64_gnullvm", 663 | "windows_aarch64_msvc", 664 | "windows_i686_gnu", 665 | "windows_i686_msvc", 666 | "windows_x86_64_gnu", 667 | "windows_x86_64_gnullvm", 668 | "windows_x86_64_msvc", 669 | ] 670 | 671 | [[package]] 672 | name = "windows_aarch64_gnullvm" 673 | version = "0.48.0" 674 | source = "registry+https://github.com/rust-lang/crates.io-index" 675 | checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" 676 | 677 | [[package]] 678 | name = "windows_aarch64_msvc" 679 | version = "0.48.0" 680 | source = "registry+https://github.com/rust-lang/crates.io-index" 681 | checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" 682 | 683 | [[package]] 684 | name = "windows_i686_gnu" 685 | version = "0.48.0" 686 | source = "registry+https://github.com/rust-lang/crates.io-index" 687 | checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" 688 | 689 | [[package]] 690 | name = "windows_i686_msvc" 691 | version = "0.48.0" 692 | source = "registry+https://github.com/rust-lang/crates.io-index" 693 | checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" 694 | 695 | [[package]] 696 | name = "windows_x86_64_gnu" 697 | version = "0.48.0" 698 | source = "registry+https://github.com/rust-lang/crates.io-index" 699 | checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" 700 | 701 | [[package]] 702 | name = "windows_x86_64_gnullvm" 703 | version = "0.48.0" 704 | source = "registry+https://github.com/rust-lang/crates.io-index" 705 | checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" 706 | 707 | [[package]] 708 | name = "windows_x86_64_msvc" 709 | version = "0.48.0" 710 | source = "registry+https://github.com/rust-lang/crates.io-index" 711 | checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" 712 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust-counter-strings" 3 | version = "0.1.0" 4 | edition = "2021" 5 | authors = ["Thomas Chaplin "] 6 | license = "MIT" 7 | readme = "README.md" 8 | repository = "https://github.com/thomaschaplin/counter-strings" 9 | homepage = "https://github.com/thomaschaplin/counter-strings" 10 | documentation = "https://github.com/thomaschaplin/rust-counter-strings#readme" 11 | description = """ 12 | Generate self-describing strings of a given length to help aid software testing 13 | """ 14 | 15 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 16 | 17 | [dependencies] 18 | unicode-segmentation = "1.11.0" 19 | 20 | [features] 21 | grapheme = [] 22 | 23 | [dev-dependencies] 24 | criterion = "0.5.1" 25 | 26 | [[bench]] 27 | name = "bench" 28 | harness = false 29 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | ## Builder 3 | #################################################################################################### 4 | FROM rust:latest AS builder 5 | 6 | RUN rustup target add x86_64-unknown-linux-musl 7 | RUN apt update && apt install -y musl-tools musl-dev binutils 8 | 9 | # Create appuser 10 | ENV USER=rust 11 | ENV UID=10001 12 | 13 | RUN adduser \ 14 | --disabled-password \ 15 | --gecos "" \ 16 | --home "/nonexistent" \ 17 | --shell "/sbin/nologin" \ 18 | --no-create-home \ 19 | --uid "${UID}" \ 20 | "${USER}" 21 | 22 | WORKDIR /rust-counter-strings 23 | 24 | COPY ./ . 25 | 26 | RUN cargo build --target x86_64-unknown-linux-musl --release 27 | 28 | RUN strip target/x86_64-unknown-linux-musl/release/rust-counter-strings 29 | 30 | # Download upx binary 31 | ADD https://github.com/upx/upx/releases/download/v4.2.2/upx-4.2.2-amd64_linux.tar.xz /tmp/upx.tar.xz 32 | RUN tar -xvf /tmp/upx.tar.xz -C /tmp && cp /tmp/upx-4.2.2-amd64_linux/upx /usr/local/bin/upx 33 | 34 | #################################################################################################### 35 | ## Final Image 36 | #################################################################################################### 37 | FROM scratch 38 | 39 | # Import from builder. 40 | COPY --from=builder /etc/passwd /etc/passwd 41 | COPY --from=builder /etc/group /etc/group 42 | 43 | WORKDIR /rust-counter-strings 44 | 45 | # Copy our build 46 | COPY --from=builder /rust-counter-strings/target/x86_64-unknown-linux-musl/release/rust-counter-strings ./ 47 | 48 | # Use an unprivileged user. 49 | USER rust:rust 50 | 51 | ENTRYPOINT ["./rust-counter-strings"] 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Thomas Chaplin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | logo 2 | 3 | # rust-counter-strings 4 | 5 | Counter strings generator written in [rust](https://www.rust-lang.org/) to help aid software testing 6 | 7 | ## What is a counterstring? 8 | 9 | > "A counterstring is a graduated string of arbitrary length. No matter where you are in the string, you always know the character position. This comes in handy when you are pasting huge strings into fields and they get truncated at a certain point" - [James Bach](https://www.satisfice.com/blog/archives/22) 10 | 11 | ## How do I use a counterstring? 12 | 13 | > "Each asterisk in the string occurs at a position specified by the immediately preceding number. Thus, the asterisk following the 29 is the 29th character in that string. So, you can chop the end of the string anywhere, and you know exactly where it was cut. Without having to count, you know that the string `2*4*6*8*11*14*17*2` has exactly 18 characters in it. This saves some effort when you’re dealing with a half million characters. I pasted a 4000 character counterstring into the address field and it was truncated at `2045*20`, meaning that 2047 characters were pasted." - [James Bach](https://www.satisfice.com/blog/archives/22) 14 | 15 | ## Docker Usage 16 | 17 | - `docker pull thomaschaplin/rust-counter-strings` 18 | - `docker run --rm thomaschaplin/rust-counter-strings ` 19 | 20 | ## Development Setup 21 | 22 | Make sure you have [rust](https://www.rust-lang.org/) installed on your machine by following the [getting started guide](https://www.rust-lang.org/learn/get-started) 23 | 24 | ### Instructions 25 | 26 | * Clone this repository `git clone git@github.com:thomaschaplin/rust-counter-strings.git` 27 | * Change directory `cd rust-counter-strings` 28 | * Build the application `cargo build` 29 | * Run the application `cargo run ` 30 | 31 | ### Final Build 32 | 33 | * Build the application in release mode `cargo build --release` 34 | * Execute the `rust-counter-strings` binary file found in `target/release/rust-counter-strings` 35 | 36 | #### Example Usage: 37 | 38 | `./rust-counter-strings 50` 39 | 40 | ``` 41 | 2*4*6*8*11*14*17*20*23*26*29*32*35*38*41*44*47*50* 42 | ``` 43 | 44 | ### Local Docker Setup 45 | 46 | Build 47 | ``` 48 | docker build --rm -f Dockerfile -t thomaschaplin/rust-counter-strings . 49 | ``` 50 | 51 | Run 52 | ``` 53 | docker run --rm thomaschaplin/rust-counter-strings 54 | ``` 55 | 56 | --- 57 | 58 | [Rope](https://www.clipartkey.com/view/imioim_rope-lasso-clipart-rope-black-and-white/) graphic by Alpenx Nbr from ClipArtKey. 59 | -------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thomaschaplin/rust-counter-strings/ec7b768ed27573e68e905deb34e24c6db1a3c6a9/assets/logo.png -------------------------------------------------------------------------------- /benches/bench.rs: -------------------------------------------------------------------------------- 1 | use criterion::BenchmarkId; 2 | use criterion::Criterion; 3 | use criterion::{criterion_group, criterion_main}; 4 | use rust_counter_strings::generate; 5 | 6 | fn bench(c: &mut Criterion) { 7 | let count: usize = 100; 8 | 9 | c.bench_with_input(BenchmarkId::new("generate", count), &count, |b, &s| { 10 | b.iter(|| generate(s)); 11 | }); 12 | } 13 | 14 | criterion_group!(benches, bench); 15 | criterion_main!(benches); 16 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | use unicode_segmentation::UnicodeSegmentation; 3 | 4 | fn main() { 5 | let count = get_count(); 6 | let counter_string = generate(count); 7 | 8 | println!("{}", counter_string); 9 | } 10 | 11 | pub fn generate(mut count: usize) -> String { 12 | let mut counter_string = String::new(); 13 | 14 | while count > 0 { 15 | let mut result = String::from("*"); 16 | result.push_str(&count.to_string().graphemes(true).rev().collect::()); 17 | 18 | if result.len() > count { 19 | result.truncate(count); 20 | } 21 | 22 | counter_string.push_str(&result); 23 | count -= result.len(); 24 | } 25 | 26 | counter_string.graphemes(true).rev().collect::() 27 | } 28 | 29 | pub fn get_count() -> usize { 30 | let args: Vec = env::args().collect(); 31 | if args.len() < 2 { 32 | panic!("Please provide a number as argument"); 33 | } 34 | 35 | args[1].trim().parse().unwrap_or_else(|_| { 36 | panic!( 37 | "Failed to read value \"{}\", we were expecting a number!", 38 | args[1].trim() 39 | ) 40 | }) 41 | } 42 | 43 | #[cfg(test)] 44 | mod tests { 45 | use super::*; 46 | 47 | #[test] 48 | fn test_generate() { 49 | assert_eq!(generate(10), "*3*5*7*10*"); 50 | assert_eq!( 51 | generate(50), 52 | "2*4*6*8*11*14*17*20*23*26*29*32*35*38*41*44*47*50*" 53 | ); 54 | assert_eq!(generate(1), "*"); 55 | assert_eq!(generate(0), ""); 56 | } 57 | 58 | #[test] 59 | #[should_panic(expected = "Please provide a number as argument")] 60 | fn test_get_count_without_argument() { 61 | let _ = get_count(); 62 | } 63 | 64 | #[test] 65 | #[should_panic(expected = "Please provide a number as argument")] 66 | fn test_get_count_with_invalid_argument() { 67 | env::set_var("ARG", "invalid"); 68 | let _ = get_count(); 69 | } 70 | } 71 | --------------------------------------------------------------------------------