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

Change the API for check_n / check_n_keyed / until_n / until_n_keyed #158

Closed antifuchs closed 1 year ago

antifuchs commented 1 year ago

Previously, it returned an enum whose variants had different jobs: one to indicate that a usage error had occurred and one to indicate the rate limiting result. That's not ideal as it complicated every use of the rate limiter.

Instead, return a nested result: The outermost can be used with the try/? operator, to ensure usage errors get propagated through, and then the one can be used like you would a non-n usage of the rate limiter.

This is pretty incompatible to what was there before, so next release is a major one if this goes in.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.02 :warning:

Comparison is base (6894267) 97.51% compared to head (be49046) 97.50%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #158 +/- ## ========================================== - Coverage 97.51% 97.50% -0.02% ========================================== Files 30 30 Lines 2209 2200 -9 ========================================== - Hits 2154 2145 -9 Misses 55 55 ``` | [Impacted Files](https://codecov.io/gh/antifuchs/governor/pull/158?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs) | Coverage Δ | | |---|---|---| | [governor/src/errors.rs](https://codecov.io/gh/antifuchs/governor/pull/158?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs#diff-Z292ZXJub3Ivc3JjL2Vycm9ycy5ycw==) | `100.00% <100.00%> (ø)` | | | [governor/src/gcra.rs](https://codecov.io/gh/antifuchs/governor/pull/158?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs#diff-Z292ZXJub3Ivc3JjL2djcmEucnM=) | `100.00% <100.00%> (ø)` | | | [governor/src/state/direct.rs](https://codecov.io/gh/antifuchs/governor/pull/158?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/direct/future.rs](https://codecov.io/gh/antifuchs/governor/pull/158?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs#diff-Z292ZXJub3Ivc3JjL3N0YXRlL2RpcmVjdC9mdXR1cmUucnM=) | `100.00% <100.00%> (ø)` | | | [governor/src/state/keyed.rs](https://codecov.io/gh/antifuchs/governor/pull/158?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/tests/direct.rs](https://codecov.io/gh/antifuchs/governor/pull/158?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andreas+Fuchs#diff-Z292ZXJub3IvdGVzdHMvZGlyZWN0LnJz) | `100.00% <100.00%> (ø)` | | | [governor/tests/keyed\_dashmap.rs](https://codecov.io/gh/antifuchs/governor/pull/158?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/158?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.

antifuchs commented 1 year ago

bors merge

bors[bot] commented 1 year ago

Build succeeded: