├── .github └── dependabot.yml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md └── src ├── example.rs └── lib.rs /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference#package-ecosystem- 2 | version: 2 3 | updates: 4 | - package-ecosystem: "cargo" 5 | directory: "/" 6 | schedule: 7 | interval: "weekly" 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "addr2line" 7 | version = "0.24.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" 10 | dependencies = [ 11 | "gimli", 12 | ] 13 | 14 | [[package]] 15 | name = "adler2" 16 | version = "2.0.0" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" 19 | 20 | [[package]] 21 | name = "anyhow" 22 | version = "1.0.98" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" 25 | 26 | [[package]] 27 | name = "async-trait" 28 | version = "0.1.88" 29 | source = "registry+https://github.com/rust-lang/crates.io-index" 30 | checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" 31 | dependencies = [ 32 | "proc-macro2", 33 | "quote", 34 | "syn", 35 | ] 36 | 37 | [[package]] 38 | name = "backtrace" 39 | version = "0.3.74" 40 | source = "registry+https://github.com/rust-lang/crates.io-index" 41 | checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" 42 | dependencies = [ 43 | "addr2line", 44 | "cfg-if", 45 | "libc", 46 | "miniz_oxide", 47 | "object", 48 | "rustc-demangle", 49 | "windows-targets 0.52.6", 50 | ] 51 | 52 | [[package]] 53 | name = "base64" 54 | version = "0.22.1" 55 | source = "registry+https://github.com/rust-lang/crates.io-index" 56 | checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" 57 | 58 | [[package]] 59 | name = "bumpalo" 60 | version = "3.17.0" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" 63 | 64 | [[package]] 65 | name = "bytes" 66 | version = "1.10.1" 67 | source = "registry+https://github.com/rust-lang/crates.io-index" 68 | checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" 69 | 70 | [[package]] 71 | name = "cfg-if" 72 | version = "1.0.0" 73 | source = "registry+https://github.com/rust-lang/crates.io-index" 74 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 75 | 76 | [[package]] 77 | name = "displaydoc" 78 | version = "0.2.5" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" 81 | dependencies = [ 82 | "proc-macro2", 83 | "quote", 84 | "syn", 85 | ] 86 | 87 | [[package]] 88 | name = "fnv" 89 | version = "1.0.7" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 92 | 93 | [[package]] 94 | name = "form_urlencoded" 95 | version = "1.2.1" 96 | source = "registry+https://github.com/rust-lang/crates.io-index" 97 | checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" 98 | dependencies = [ 99 | "percent-encoding", 100 | ] 101 | 102 | [[package]] 103 | name = "futures-channel" 104 | version = "0.3.31" 105 | source = "registry+https://github.com/rust-lang/crates.io-index" 106 | checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" 107 | dependencies = [ 108 | "futures-core", 109 | ] 110 | 111 | [[package]] 112 | name = "futures-core" 113 | version = "0.3.31" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" 116 | 117 | [[package]] 118 | name = "futures-task" 119 | version = "0.3.31" 120 | source = "registry+https://github.com/rust-lang/crates.io-index" 121 | checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" 122 | 123 | [[package]] 124 | name = "futures-util" 125 | version = "0.3.31" 126 | source = "registry+https://github.com/rust-lang/crates.io-index" 127 | checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" 128 | dependencies = [ 129 | "futures-core", 130 | "futures-task", 131 | "pin-project-lite", 132 | "pin-utils", 133 | ] 134 | 135 | [[package]] 136 | name = "gimli" 137 | version = "0.31.1" 138 | source = "registry+https://github.com/rust-lang/crates.io-index" 139 | checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" 140 | 141 | [[package]] 142 | name = "http" 143 | version = "1.3.1" 144 | source = "registry+https://github.com/rust-lang/crates.io-index" 145 | checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" 146 | dependencies = [ 147 | "bytes", 148 | "fnv", 149 | "itoa", 150 | ] 151 | 152 | [[package]] 153 | name = "http-body" 154 | version = "1.0.1" 155 | source = "registry+https://github.com/rust-lang/crates.io-index" 156 | checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" 157 | dependencies = [ 158 | "bytes", 159 | "http", 160 | ] 161 | 162 | [[package]] 163 | name = "http-body-util" 164 | version = "0.1.3" 165 | source = "registry+https://github.com/rust-lang/crates.io-index" 166 | checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" 167 | dependencies = [ 168 | "bytes", 169 | "futures-core", 170 | "http", 171 | "http-body", 172 | "pin-project-lite", 173 | ] 174 | 175 | [[package]] 176 | name = "httparse" 177 | version = "1.10.1" 178 | source = "registry+https://github.com/rust-lang/crates.io-index" 179 | checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" 180 | 181 | [[package]] 182 | name = "hyper" 183 | version = "1.6.0" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" 186 | dependencies = [ 187 | "bytes", 188 | "futures-channel", 189 | "futures-util", 190 | "http", 191 | "http-body", 192 | "httparse", 193 | "itoa", 194 | "pin-project-lite", 195 | "smallvec", 196 | "tokio", 197 | "want", 198 | ] 199 | 200 | [[package]] 201 | name = "hyper-util" 202 | version = "0.1.11" 203 | source = "registry+https://github.com/rust-lang/crates.io-index" 204 | checksum = "497bbc33a26fdd4af9ed9c70d63f61cf56a938375fbb32df34db9b1cd6d643f2" 205 | dependencies = [ 206 | "bytes", 207 | "futures-channel", 208 | "futures-util", 209 | "http", 210 | "http-body", 211 | "hyper", 212 | "libc", 213 | "pin-project-lite", 214 | "socket2", 215 | "tokio", 216 | "tower-service", 217 | "tracing", 218 | ] 219 | 220 | [[package]] 221 | name = "icu_collections" 222 | version = "1.5.0" 223 | source = "registry+https://github.com/rust-lang/crates.io-index" 224 | checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" 225 | dependencies = [ 226 | "displaydoc", 227 | "yoke", 228 | "zerofrom", 229 | "zerovec", 230 | ] 231 | 232 | [[package]] 233 | name = "icu_locid" 234 | version = "1.5.0" 235 | source = "registry+https://github.com/rust-lang/crates.io-index" 236 | checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" 237 | dependencies = [ 238 | "displaydoc", 239 | "litemap", 240 | "tinystr", 241 | "writeable", 242 | "zerovec", 243 | ] 244 | 245 | [[package]] 246 | name = "icu_locid_transform" 247 | version = "1.5.0" 248 | source = "registry+https://github.com/rust-lang/crates.io-index" 249 | checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" 250 | dependencies = [ 251 | "displaydoc", 252 | "icu_locid", 253 | "icu_locid_transform_data", 254 | "icu_provider", 255 | "tinystr", 256 | "zerovec", 257 | ] 258 | 259 | [[package]] 260 | name = "icu_locid_transform_data" 261 | version = "1.5.1" 262 | source = "registry+https://github.com/rust-lang/crates.io-index" 263 | checksum = "7515e6d781098bf9f7205ab3fc7e9709d34554ae0b21ddbcb5febfa4bc7df11d" 264 | 265 | [[package]] 266 | name = "icu_normalizer" 267 | version = "1.5.0" 268 | source = "registry+https://github.com/rust-lang/crates.io-index" 269 | checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" 270 | dependencies = [ 271 | "displaydoc", 272 | "icu_collections", 273 | "icu_normalizer_data", 274 | "icu_properties", 275 | "icu_provider", 276 | "smallvec", 277 | "utf16_iter", 278 | "utf8_iter", 279 | "write16", 280 | "zerovec", 281 | ] 282 | 283 | [[package]] 284 | name = "icu_normalizer_data" 285 | version = "1.5.1" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | checksum = "c5e8338228bdc8ab83303f16b797e177953730f601a96c25d10cb3ab0daa0cb7" 288 | 289 | [[package]] 290 | name = "icu_properties" 291 | version = "1.5.1" 292 | source = "registry+https://github.com/rust-lang/crates.io-index" 293 | checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" 294 | dependencies = [ 295 | "displaydoc", 296 | "icu_collections", 297 | "icu_locid_transform", 298 | "icu_properties_data", 299 | "icu_provider", 300 | "tinystr", 301 | "zerovec", 302 | ] 303 | 304 | [[package]] 305 | name = "icu_properties_data" 306 | version = "1.5.1" 307 | source = "registry+https://github.com/rust-lang/crates.io-index" 308 | checksum = "85fb8799753b75aee8d2a21d7c14d9f38921b54b3dbda10f5a3c7a7b82dba5e2" 309 | 310 | [[package]] 311 | name = "icu_provider" 312 | version = "1.5.0" 313 | source = "registry+https://github.com/rust-lang/crates.io-index" 314 | checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" 315 | dependencies = [ 316 | "displaydoc", 317 | "icu_locid", 318 | "icu_provider_macros", 319 | "stable_deref_trait", 320 | "tinystr", 321 | "writeable", 322 | "yoke", 323 | "zerofrom", 324 | "zerovec", 325 | ] 326 | 327 | [[package]] 328 | name = "icu_provider_macros" 329 | version = "1.5.0" 330 | source = "registry+https://github.com/rust-lang/crates.io-index" 331 | checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" 332 | dependencies = [ 333 | "proc-macro2", 334 | "quote", 335 | "syn", 336 | ] 337 | 338 | [[package]] 339 | name = "idna" 340 | version = "1.0.3" 341 | source = "registry+https://github.com/rust-lang/crates.io-index" 342 | checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" 343 | dependencies = [ 344 | "idna_adapter", 345 | "smallvec", 346 | "utf8_iter", 347 | ] 348 | 349 | [[package]] 350 | name = "idna_adapter" 351 | version = "1.2.0" 352 | source = "registry+https://github.com/rust-lang/crates.io-index" 353 | checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" 354 | dependencies = [ 355 | "icu_normalizer", 356 | "icu_properties", 357 | ] 358 | 359 | [[package]] 360 | name = "ipnet" 361 | version = "2.11.0" 362 | source = "registry+https://github.com/rust-lang/crates.io-index" 363 | checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" 364 | 365 | [[package]] 366 | name = "itoa" 367 | version = "1.0.15" 368 | source = "registry+https://github.com/rust-lang/crates.io-index" 369 | checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" 370 | 371 | [[package]] 372 | name = "js-sys" 373 | version = "0.3.77" 374 | source = "registry+https://github.com/rust-lang/crates.io-index" 375 | checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" 376 | dependencies = [ 377 | "once_cell", 378 | "wasm-bindgen", 379 | ] 380 | 381 | [[package]] 382 | name = "libc" 383 | version = "0.2.172" 384 | source = "registry+https://github.com/rust-lang/crates.io-index" 385 | checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" 386 | 387 | [[package]] 388 | name = "litemap" 389 | version = "0.7.5" 390 | source = "registry+https://github.com/rust-lang/crates.io-index" 391 | checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856" 392 | 393 | [[package]] 394 | name = "log" 395 | version = "0.4.27" 396 | source = "registry+https://github.com/rust-lang/crates.io-index" 397 | checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" 398 | 399 | [[package]] 400 | name = "memchr" 401 | version = "2.7.4" 402 | source = "registry+https://github.com/rust-lang/crates.io-index" 403 | checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" 404 | 405 | [[package]] 406 | name = "mime" 407 | version = "0.3.17" 408 | source = "registry+https://github.com/rust-lang/crates.io-index" 409 | checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" 410 | 411 | [[package]] 412 | name = "miniz_oxide" 413 | version = "0.8.8" 414 | source = "registry+https://github.com/rust-lang/crates.io-index" 415 | checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" 416 | dependencies = [ 417 | "adler2", 418 | ] 419 | 420 | [[package]] 421 | name = "mio" 422 | version = "1.0.3" 423 | source = "registry+https://github.com/rust-lang/crates.io-index" 424 | checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" 425 | dependencies = [ 426 | "libc", 427 | "wasi", 428 | "windows-sys", 429 | ] 430 | 431 | [[package]] 432 | name = "object" 433 | version = "0.36.7" 434 | source = "registry+https://github.com/rust-lang/crates.io-index" 435 | checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" 436 | dependencies = [ 437 | "memchr", 438 | ] 439 | 440 | [[package]] 441 | name = "once_cell" 442 | version = "1.21.3" 443 | source = "registry+https://github.com/rust-lang/crates.io-index" 444 | checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" 445 | 446 | [[package]] 447 | name = "percent-encoding" 448 | version = "2.3.1" 449 | source = "registry+https://github.com/rust-lang/crates.io-index" 450 | checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" 451 | 452 | [[package]] 453 | name = "pin-project-lite" 454 | version = "0.2.16" 455 | source = "registry+https://github.com/rust-lang/crates.io-index" 456 | checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" 457 | 458 | [[package]] 459 | name = "pin-utils" 460 | version = "0.1.0" 461 | source = "registry+https://github.com/rust-lang/crates.io-index" 462 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 463 | 464 | [[package]] 465 | name = "proc-macro2" 466 | version = "1.0.95" 467 | source = "registry+https://github.com/rust-lang/crates.io-index" 468 | checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" 469 | dependencies = [ 470 | "unicode-ident", 471 | ] 472 | 473 | [[package]] 474 | name = "quote" 475 | version = "1.0.40" 476 | source = "registry+https://github.com/rust-lang/crates.io-index" 477 | checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" 478 | dependencies = [ 479 | "proc-macro2", 480 | ] 481 | 482 | [[package]] 483 | name = "reqwest" 484 | version = "0.12.15" 485 | source = "registry+https://github.com/rust-lang/crates.io-index" 486 | checksum = "d19c46a6fdd48bc4dab94b6103fccc55d34c67cc0ad04653aad4ea2a07cd7bbb" 487 | dependencies = [ 488 | "base64", 489 | "bytes", 490 | "futures-core", 491 | "futures-util", 492 | "http", 493 | "http-body", 494 | "http-body-util", 495 | "hyper", 496 | "hyper-util", 497 | "ipnet", 498 | "js-sys", 499 | "log", 500 | "mime", 501 | "once_cell", 502 | "percent-encoding", 503 | "pin-project-lite", 504 | "serde", 505 | "serde_json", 506 | "serde_urlencoded", 507 | "sync_wrapper", 508 | "tokio", 509 | "tower", 510 | "tower-service", 511 | "url", 512 | "wasm-bindgen", 513 | "wasm-bindgen-futures", 514 | "web-sys", 515 | "windows-registry", 516 | ] 517 | 518 | [[package]] 519 | name = "reqwest-middleware" 520 | version = "0.4.2" 521 | source = "registry+https://github.com/rust-lang/crates.io-index" 522 | checksum = "57f17d28a6e6acfe1733fe24bcd30774d13bffa4b8a22535b4c8c98423088d4e" 523 | dependencies = [ 524 | "anyhow", 525 | "async-trait", 526 | "http", 527 | "reqwest", 528 | "serde", 529 | "thiserror", 530 | "tower-service", 531 | ] 532 | 533 | [[package]] 534 | name = "reqwest-ratelimit" 535 | version = "0.3.0" 536 | dependencies = [ 537 | "async-trait", 538 | "http", 539 | "reqwest", 540 | "reqwest-middleware", 541 | ] 542 | 543 | [[package]] 544 | name = "rustc-demangle" 545 | version = "0.1.24" 546 | source = "registry+https://github.com/rust-lang/crates.io-index" 547 | checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" 548 | 549 | [[package]] 550 | name = "rustversion" 551 | version = "1.0.20" 552 | source = "registry+https://github.com/rust-lang/crates.io-index" 553 | checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" 554 | 555 | [[package]] 556 | name = "ryu" 557 | version = "1.0.20" 558 | source = "registry+https://github.com/rust-lang/crates.io-index" 559 | checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" 560 | 561 | [[package]] 562 | name = "serde" 563 | version = "1.0.219" 564 | source = "registry+https://github.com/rust-lang/crates.io-index" 565 | checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" 566 | dependencies = [ 567 | "serde_derive", 568 | ] 569 | 570 | [[package]] 571 | name = "serde_derive" 572 | version = "1.0.219" 573 | source = "registry+https://github.com/rust-lang/crates.io-index" 574 | checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" 575 | dependencies = [ 576 | "proc-macro2", 577 | "quote", 578 | "syn", 579 | ] 580 | 581 | [[package]] 582 | name = "serde_json" 583 | version = "1.0.140" 584 | source = "registry+https://github.com/rust-lang/crates.io-index" 585 | checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" 586 | dependencies = [ 587 | "itoa", 588 | "memchr", 589 | "ryu", 590 | "serde", 591 | ] 592 | 593 | [[package]] 594 | name = "serde_urlencoded" 595 | version = "0.7.1" 596 | source = "registry+https://github.com/rust-lang/crates.io-index" 597 | checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" 598 | dependencies = [ 599 | "form_urlencoded", 600 | "itoa", 601 | "ryu", 602 | "serde", 603 | ] 604 | 605 | [[package]] 606 | name = "smallvec" 607 | version = "1.15.0" 608 | source = "registry+https://github.com/rust-lang/crates.io-index" 609 | checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" 610 | 611 | [[package]] 612 | name = "socket2" 613 | version = "0.5.9" 614 | source = "registry+https://github.com/rust-lang/crates.io-index" 615 | checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef" 616 | dependencies = [ 617 | "libc", 618 | "windows-sys", 619 | ] 620 | 621 | [[package]] 622 | name = "stable_deref_trait" 623 | version = "1.2.0" 624 | source = "registry+https://github.com/rust-lang/crates.io-index" 625 | checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" 626 | 627 | [[package]] 628 | name = "syn" 629 | version = "2.0.100" 630 | source = "registry+https://github.com/rust-lang/crates.io-index" 631 | checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" 632 | dependencies = [ 633 | "proc-macro2", 634 | "quote", 635 | "unicode-ident", 636 | ] 637 | 638 | [[package]] 639 | name = "sync_wrapper" 640 | version = "1.0.2" 641 | source = "registry+https://github.com/rust-lang/crates.io-index" 642 | checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" 643 | dependencies = [ 644 | "futures-core", 645 | ] 646 | 647 | [[package]] 648 | name = "synstructure" 649 | version = "0.13.1" 650 | source = "registry+https://github.com/rust-lang/crates.io-index" 651 | checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" 652 | dependencies = [ 653 | "proc-macro2", 654 | "quote", 655 | "syn", 656 | ] 657 | 658 | [[package]] 659 | name = "thiserror" 660 | version = "1.0.69" 661 | source = "registry+https://github.com/rust-lang/crates.io-index" 662 | checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" 663 | dependencies = [ 664 | "thiserror-impl", 665 | ] 666 | 667 | [[package]] 668 | name = "thiserror-impl" 669 | version = "1.0.69" 670 | source = "registry+https://github.com/rust-lang/crates.io-index" 671 | checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" 672 | dependencies = [ 673 | "proc-macro2", 674 | "quote", 675 | "syn", 676 | ] 677 | 678 | [[package]] 679 | name = "tinystr" 680 | version = "0.7.6" 681 | source = "registry+https://github.com/rust-lang/crates.io-index" 682 | checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" 683 | dependencies = [ 684 | "displaydoc", 685 | "zerovec", 686 | ] 687 | 688 | [[package]] 689 | name = "tokio" 690 | version = "1.44.2" 691 | source = "registry+https://github.com/rust-lang/crates.io-index" 692 | checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48" 693 | dependencies = [ 694 | "backtrace", 695 | "libc", 696 | "mio", 697 | "pin-project-lite", 698 | "socket2", 699 | "windows-sys", 700 | ] 701 | 702 | [[package]] 703 | name = "tower" 704 | version = "0.5.2" 705 | source = "registry+https://github.com/rust-lang/crates.io-index" 706 | checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" 707 | dependencies = [ 708 | "futures-core", 709 | "futures-util", 710 | "pin-project-lite", 711 | "sync_wrapper", 712 | "tokio", 713 | "tower-layer", 714 | "tower-service", 715 | ] 716 | 717 | [[package]] 718 | name = "tower-layer" 719 | version = "0.3.3" 720 | source = "registry+https://github.com/rust-lang/crates.io-index" 721 | checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" 722 | 723 | [[package]] 724 | name = "tower-service" 725 | version = "0.3.3" 726 | source = "registry+https://github.com/rust-lang/crates.io-index" 727 | checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" 728 | 729 | [[package]] 730 | name = "tracing" 731 | version = "0.1.41" 732 | source = "registry+https://github.com/rust-lang/crates.io-index" 733 | checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" 734 | dependencies = [ 735 | "pin-project-lite", 736 | "tracing-core", 737 | ] 738 | 739 | [[package]] 740 | name = "tracing-core" 741 | version = "0.1.33" 742 | source = "registry+https://github.com/rust-lang/crates.io-index" 743 | checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" 744 | dependencies = [ 745 | "once_cell", 746 | ] 747 | 748 | [[package]] 749 | name = "try-lock" 750 | version = "0.2.5" 751 | source = "registry+https://github.com/rust-lang/crates.io-index" 752 | checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" 753 | 754 | [[package]] 755 | name = "unicode-ident" 756 | version = "1.0.18" 757 | source = "registry+https://github.com/rust-lang/crates.io-index" 758 | checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" 759 | 760 | [[package]] 761 | name = "url" 762 | version = "2.5.4" 763 | source = "registry+https://github.com/rust-lang/crates.io-index" 764 | checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" 765 | dependencies = [ 766 | "form_urlencoded", 767 | "idna", 768 | "percent-encoding", 769 | ] 770 | 771 | [[package]] 772 | name = "utf16_iter" 773 | version = "1.0.5" 774 | source = "registry+https://github.com/rust-lang/crates.io-index" 775 | checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" 776 | 777 | [[package]] 778 | name = "utf8_iter" 779 | version = "1.0.4" 780 | source = "registry+https://github.com/rust-lang/crates.io-index" 781 | checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" 782 | 783 | [[package]] 784 | name = "want" 785 | version = "0.3.1" 786 | source = "registry+https://github.com/rust-lang/crates.io-index" 787 | checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" 788 | dependencies = [ 789 | "try-lock", 790 | ] 791 | 792 | [[package]] 793 | name = "wasi" 794 | version = "0.11.0+wasi-snapshot-preview1" 795 | source = "registry+https://github.com/rust-lang/crates.io-index" 796 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 797 | 798 | [[package]] 799 | name = "wasm-bindgen" 800 | version = "0.2.100" 801 | source = "registry+https://github.com/rust-lang/crates.io-index" 802 | checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" 803 | dependencies = [ 804 | "cfg-if", 805 | "once_cell", 806 | "rustversion", 807 | "wasm-bindgen-macro", 808 | ] 809 | 810 | [[package]] 811 | name = "wasm-bindgen-backend" 812 | version = "0.2.100" 813 | source = "registry+https://github.com/rust-lang/crates.io-index" 814 | checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" 815 | dependencies = [ 816 | "bumpalo", 817 | "log", 818 | "proc-macro2", 819 | "quote", 820 | "syn", 821 | "wasm-bindgen-shared", 822 | ] 823 | 824 | [[package]] 825 | name = "wasm-bindgen-futures" 826 | version = "0.4.50" 827 | source = "registry+https://github.com/rust-lang/crates.io-index" 828 | checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" 829 | dependencies = [ 830 | "cfg-if", 831 | "js-sys", 832 | "once_cell", 833 | "wasm-bindgen", 834 | "web-sys", 835 | ] 836 | 837 | [[package]] 838 | name = "wasm-bindgen-macro" 839 | version = "0.2.100" 840 | source = "registry+https://github.com/rust-lang/crates.io-index" 841 | checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" 842 | dependencies = [ 843 | "quote", 844 | "wasm-bindgen-macro-support", 845 | ] 846 | 847 | [[package]] 848 | name = "wasm-bindgen-macro-support" 849 | version = "0.2.100" 850 | source = "registry+https://github.com/rust-lang/crates.io-index" 851 | checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" 852 | dependencies = [ 853 | "proc-macro2", 854 | "quote", 855 | "syn", 856 | "wasm-bindgen-backend", 857 | "wasm-bindgen-shared", 858 | ] 859 | 860 | [[package]] 861 | name = "wasm-bindgen-shared" 862 | version = "0.2.100" 863 | source = "registry+https://github.com/rust-lang/crates.io-index" 864 | checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" 865 | dependencies = [ 866 | "unicode-ident", 867 | ] 868 | 869 | [[package]] 870 | name = "web-sys" 871 | version = "0.3.77" 872 | source = "registry+https://github.com/rust-lang/crates.io-index" 873 | checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" 874 | dependencies = [ 875 | "js-sys", 876 | "wasm-bindgen", 877 | ] 878 | 879 | [[package]] 880 | name = "windows-link" 881 | version = "0.1.1" 882 | source = "registry+https://github.com/rust-lang/crates.io-index" 883 | checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" 884 | 885 | [[package]] 886 | name = "windows-registry" 887 | version = "0.4.0" 888 | source = "registry+https://github.com/rust-lang/crates.io-index" 889 | checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" 890 | dependencies = [ 891 | "windows-result", 892 | "windows-strings", 893 | "windows-targets 0.53.0", 894 | ] 895 | 896 | [[package]] 897 | name = "windows-result" 898 | version = "0.3.2" 899 | source = "registry+https://github.com/rust-lang/crates.io-index" 900 | checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" 901 | dependencies = [ 902 | "windows-link", 903 | ] 904 | 905 | [[package]] 906 | name = "windows-strings" 907 | version = "0.3.1" 908 | source = "registry+https://github.com/rust-lang/crates.io-index" 909 | checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319" 910 | dependencies = [ 911 | "windows-link", 912 | ] 913 | 914 | [[package]] 915 | name = "windows-sys" 916 | version = "0.52.0" 917 | source = "registry+https://github.com/rust-lang/crates.io-index" 918 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 919 | dependencies = [ 920 | "windows-targets 0.52.6", 921 | ] 922 | 923 | [[package]] 924 | name = "windows-targets" 925 | version = "0.52.6" 926 | source = "registry+https://github.com/rust-lang/crates.io-index" 927 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 928 | dependencies = [ 929 | "windows_aarch64_gnullvm 0.52.6", 930 | "windows_aarch64_msvc 0.52.6", 931 | "windows_i686_gnu 0.52.6", 932 | "windows_i686_gnullvm 0.52.6", 933 | "windows_i686_msvc 0.52.6", 934 | "windows_x86_64_gnu 0.52.6", 935 | "windows_x86_64_gnullvm 0.52.6", 936 | "windows_x86_64_msvc 0.52.6", 937 | ] 938 | 939 | [[package]] 940 | name = "windows-targets" 941 | version = "0.53.0" 942 | source = "registry+https://github.com/rust-lang/crates.io-index" 943 | checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b" 944 | dependencies = [ 945 | "windows_aarch64_gnullvm 0.53.0", 946 | "windows_aarch64_msvc 0.53.0", 947 | "windows_i686_gnu 0.53.0", 948 | "windows_i686_gnullvm 0.53.0", 949 | "windows_i686_msvc 0.53.0", 950 | "windows_x86_64_gnu 0.53.0", 951 | "windows_x86_64_gnullvm 0.53.0", 952 | "windows_x86_64_msvc 0.53.0", 953 | ] 954 | 955 | [[package]] 956 | name = "windows_aarch64_gnullvm" 957 | version = "0.52.6" 958 | source = "registry+https://github.com/rust-lang/crates.io-index" 959 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 960 | 961 | [[package]] 962 | name = "windows_aarch64_gnullvm" 963 | version = "0.53.0" 964 | source = "registry+https://github.com/rust-lang/crates.io-index" 965 | checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" 966 | 967 | [[package]] 968 | name = "windows_aarch64_msvc" 969 | version = "0.52.6" 970 | source = "registry+https://github.com/rust-lang/crates.io-index" 971 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 972 | 973 | [[package]] 974 | name = "windows_aarch64_msvc" 975 | version = "0.53.0" 976 | source = "registry+https://github.com/rust-lang/crates.io-index" 977 | checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" 978 | 979 | [[package]] 980 | name = "windows_i686_gnu" 981 | version = "0.52.6" 982 | source = "registry+https://github.com/rust-lang/crates.io-index" 983 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 984 | 985 | [[package]] 986 | name = "windows_i686_gnu" 987 | version = "0.53.0" 988 | source = "registry+https://github.com/rust-lang/crates.io-index" 989 | checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" 990 | 991 | [[package]] 992 | name = "windows_i686_gnullvm" 993 | version = "0.52.6" 994 | source = "registry+https://github.com/rust-lang/crates.io-index" 995 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 996 | 997 | [[package]] 998 | name = "windows_i686_gnullvm" 999 | version = "0.53.0" 1000 | source = "registry+https://github.com/rust-lang/crates.io-index" 1001 | checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" 1002 | 1003 | [[package]] 1004 | name = "windows_i686_msvc" 1005 | version = "0.52.6" 1006 | source = "registry+https://github.com/rust-lang/crates.io-index" 1007 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 1008 | 1009 | [[package]] 1010 | name = "windows_i686_msvc" 1011 | version = "0.53.0" 1012 | source = "registry+https://github.com/rust-lang/crates.io-index" 1013 | checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" 1014 | 1015 | [[package]] 1016 | name = "windows_x86_64_gnu" 1017 | version = "0.52.6" 1018 | source = "registry+https://github.com/rust-lang/crates.io-index" 1019 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 1020 | 1021 | [[package]] 1022 | name = "windows_x86_64_gnu" 1023 | version = "0.53.0" 1024 | source = "registry+https://github.com/rust-lang/crates.io-index" 1025 | checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" 1026 | 1027 | [[package]] 1028 | name = "windows_x86_64_gnullvm" 1029 | version = "0.52.6" 1030 | source = "registry+https://github.com/rust-lang/crates.io-index" 1031 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 1032 | 1033 | [[package]] 1034 | name = "windows_x86_64_gnullvm" 1035 | version = "0.53.0" 1036 | source = "registry+https://github.com/rust-lang/crates.io-index" 1037 | checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" 1038 | 1039 | [[package]] 1040 | name = "windows_x86_64_msvc" 1041 | version = "0.52.6" 1042 | source = "registry+https://github.com/rust-lang/crates.io-index" 1043 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 1044 | 1045 | [[package]] 1046 | name = "windows_x86_64_msvc" 1047 | version = "0.53.0" 1048 | source = "registry+https://github.com/rust-lang/crates.io-index" 1049 | checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" 1050 | 1051 | [[package]] 1052 | name = "write16" 1053 | version = "1.0.0" 1054 | source = "registry+https://github.com/rust-lang/crates.io-index" 1055 | checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" 1056 | 1057 | [[package]] 1058 | name = "writeable" 1059 | version = "0.5.5" 1060 | source = "registry+https://github.com/rust-lang/crates.io-index" 1061 | checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" 1062 | 1063 | [[package]] 1064 | name = "yoke" 1065 | version = "0.7.5" 1066 | source = "registry+https://github.com/rust-lang/crates.io-index" 1067 | checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" 1068 | dependencies = [ 1069 | "serde", 1070 | "stable_deref_trait", 1071 | "yoke-derive", 1072 | "zerofrom", 1073 | ] 1074 | 1075 | [[package]] 1076 | name = "yoke-derive" 1077 | version = "0.7.5" 1078 | source = "registry+https://github.com/rust-lang/crates.io-index" 1079 | checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" 1080 | dependencies = [ 1081 | "proc-macro2", 1082 | "quote", 1083 | "syn", 1084 | "synstructure", 1085 | ] 1086 | 1087 | [[package]] 1088 | name = "zerofrom" 1089 | version = "0.1.6" 1090 | source = "registry+https://github.com/rust-lang/crates.io-index" 1091 | checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" 1092 | dependencies = [ 1093 | "zerofrom-derive", 1094 | ] 1095 | 1096 | [[package]] 1097 | name = "zerofrom-derive" 1098 | version = "0.1.6" 1099 | source = "registry+https://github.com/rust-lang/crates.io-index" 1100 | checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" 1101 | dependencies = [ 1102 | "proc-macro2", 1103 | "quote", 1104 | "syn", 1105 | "synstructure", 1106 | ] 1107 | 1108 | [[package]] 1109 | name = "zerovec" 1110 | version = "0.10.4" 1111 | source = "registry+https://github.com/rust-lang/crates.io-index" 1112 | checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" 1113 | dependencies = [ 1114 | "yoke", 1115 | "zerofrom", 1116 | "zerovec-derive", 1117 | ] 1118 | 1119 | [[package]] 1120 | name = "zerovec-derive" 1121 | version = "0.10.3" 1122 | source = "registry+https://github.com/rust-lang/crates.io-index" 1123 | checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" 1124 | dependencies = [ 1125 | "proc-macro2", 1126 | "quote", 1127 | "syn", 1128 | ] 1129 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "reqwest-ratelimit" 3 | authors = ["Darksome "] 4 | version = "0.4.1" 5 | edition = "2021" 6 | description = "Rate-limit middleware for reqwest." 7 | repository = "https://github.com/xDarksome/reqwest-ratelimit" 8 | license = "MIT" 9 | keywords = ["reqwest", "http", "middleware", "ratelimit"] 10 | categories = ["web-programming::http-client"] 11 | 12 | [dependencies] 13 | async-trait = "0.1" 14 | http = "1.1.0" 15 | reqwest = { version = "0.12.0", default-features = false } 16 | reqwest-middleware = "0.4.0" 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 xDarksome 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 | # reqwest-ratelimit 2 | 3 | Rate-limit middleware implementation for 4 | [`reqwest-middleware`](https://crates.io/crates/reqwest-middleware). 5 | 6 | This crate is glue code for implementing custom ratelimiters. 7 | For a batteries included example please refer to [reqwest-leaky-bucket](https://crates.io/crates/reqwest-leaky-bucket). 8 | 9 | [![Crates.io](https://img.shields.io/crates/v/reqwest-ratelimit.svg)](https://crates.io/crates/reqwest-ratelimit) 10 | [![Docs.rs](https://docs.rs/reqwest-ratelimit/badge.svg)](https://docs.rs/reqwest-ratelimit) 11 | 12 | ## Usage 13 | 14 | ```rust 15 | use std::future::Future; 16 | use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; 17 | 18 | struct RateLimiter; 19 | 20 | impl reqwest_ratelimit::RateLimiter for RateLimiter { 21 | async fn acquire_permit(&self) { 22 | // noop 23 | } 24 | } 25 | 26 | async fn run() { 27 | let client = ClientBuilder::new(reqwest::Client::new()) 28 | .with(reqwest_ratelimit::all(RateLimiter)) 29 | .build(); 30 | 31 | client.get("https://crates.io").send().await.unwrap(); 32 | } 33 | ``` 34 | -------------------------------------------------------------------------------- /src/example.rs: -------------------------------------------------------------------------------- 1 | use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; 2 | use std::future::Future; 3 | 4 | struct RateLimiter; 5 | 6 | impl reqwest_ratelimit::RateLimiter for RateLimiter { 7 | async fn acquire_permit(&self) { 8 | // noop 9 | } 10 | } 11 | 12 | async fn run() { 13 | let client = ClientBuilder::new(reqwest::Client::new()) 14 | .with(reqwest_ratelimit::all(RateLimiter)) 15 | .build(); 16 | 17 | client.get("https://crates.io").send().await.unwrap(); 18 | } 19 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Middleware to rate-limit requests built on [`reqwest_middleware`]. 2 | //! 3 | //! You're expected to provide your own [`RateLimiter`] implementation. 4 | //! 5 | //! ## Example 6 | //! 7 | //! ``` 8 | #![doc = include_str!("example.rs")] 9 | //! ``` 10 | use std::future::Future; 11 | 12 | use async_trait::async_trait; 13 | use http::Extensions; 14 | use reqwest::{Request, Response}; 15 | use reqwest_middleware::{Next, Result}; 16 | 17 | /// Request rate limiter. 18 | pub trait RateLimiter: Send + Sync + 'static { 19 | /// Acquires a permit to issue the next request. 20 | fn acquire_permit(&self) -> impl Future + Send + '_; 21 | } 22 | 23 | /// Creates a new [`Middleware`] rate-limiting all requests using the provided [`RateLimiter`]. 24 | pub fn all(rate_limiter: R) -> Middleware { 25 | Middleware { rate_limiter } 26 | } 27 | 28 | /// Request rate-limiting middleware. 29 | pub struct Middleware { 30 | rate_limiter: R, 31 | } 32 | 33 | #[async_trait] 34 | impl reqwest_middleware::Middleware for Middleware { 35 | async fn handle( 36 | &self, 37 | req: Request, 38 | extensions: &'_ mut Extensions, 39 | next: Next<'_>, 40 | ) -> Result { 41 | self.rate_limiter.acquire_permit().await; 42 | next.run(req, extensions).await 43 | } 44 | } 45 | --------------------------------------------------------------------------------