boinkor-net / governor

A rate-limiting library for Rust (f.k.a. ratelimit_meter)
https://github.com/boinkor-net/governor
MIT License
579 stars 45 forks source link

Add a contains_key method #172

Open antifuchs opened 1 year ago

antifuchs commented 1 year ago

This should fix #171 - currently, we have no good way of letting people control the memory usage of keyed rate limiter states. This at least allows them to tell whether a test would add a new key (consuming memory) - and then rate-limit that.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.02 :tada:

Comparison is base (8577d05) 97.52% compared to head (dbfb73a) 97.55%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #172 +/- ## ========================================== + Coverage 97.52% 97.55% +0.02% ========================================== Files 31 31 Lines 2220 2247 +27 ========================================== + Hits 2165 2192 +27 Misses 55 55 ``` | [Impacted Files](https://codecov.io/gh/antifuchs/governor/pull/172?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs) | Coverage Δ | | |---|---|---| | [governor/src/state.rs](https://codecov.io/gh/antifuchs/governor/pull/172?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs#diff-Z292ZXJub3Ivc3JjL3N0YXRlLnJz) | `100.00% <ø> (ø)` | | | [governor/src/state/direct.rs](https://codecov.io/gh/antifuchs/governor/pull/172?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs#diff-Z292ZXJub3Ivc3JjL3N0YXRlL2RpcmVjdC5ycw==) | `100.00% <100.00%> (ø)` | | | [governor/src/state/in\_memory.rs](https://codecov.io/gh/antifuchs/governor/pull/172?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs#diff-Z292ZXJub3Ivc3JjL3N0YXRlL2luX21lbW9yeS5ycw==) | `100.00% <100.00%> (ø)` | | | [governor/src/state/keyed.rs](https://codecov.io/gh/antifuchs/governor/pull/172?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs#diff-Z292ZXJub3Ivc3JjL3N0YXRlL2tleWVkLnJz) | `100.00% <100.00%> (ø)` | | | [governor/src/state/keyed/dashmap.rs](https://codecov.io/gh/antifuchs/governor/pull/172?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs#diff-Z292ZXJub3Ivc3JjL3N0YXRlL2tleWVkL2Rhc2htYXAucnM=) | `100.00% <100.00%> (ø)` | | | [governor/src/state/keyed/hashmap.rs](https://codecov.io/gh/antifuchs/governor/pull/172?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs#diff-Z292ZXJub3Ivc3JjL3N0YXRlL2tleWVkL2hhc2htYXAucnM=) | `100.00% <100.00%> (ø)` | | | [governor/tests/keyed\_dashmap.rs](https://codecov.io/gh/antifuchs/governor/pull/172?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs#diff-Z292ZXJub3IvdGVzdHMva2V5ZWRfZGFzaG1hcC5ycw==) | `100.00% <100.00%> (ø)` | | | [governor/tests/keyed\_hashmap.rs](https://codecov.io/gh/antifuchs/governor/pull/172?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs#diff-Z292ZXJub3IvdGVzdHMva2V5ZWRfaGFzaG1hcC5ycw==) | `100.00% <100.00%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.