Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to find out the quota after a rate limiter is created? #120

Open
conorbros opened this issue Mar 15, 2022 · 1 comment
Open

How to find out the quota after a rate limiter is created? #120

conorbros opened this issue Mar 15, 2022 · 1 comment

Comments

@conorbros
Copy link

Essentially I want to do this. It's a simple example that doesn't account for the other possible constructors for Quota.

use std::num::NonZeroU32;
use nonzero_ext::*;
use governor::{Quota, RateLimiter};

let mut lim = RateLimiter::direct(Quota::per_second(nonzero!(50u32))); // Allow 50 units per second

assert_eq!(lim.get_quota(), nonzero!(50u32));
@antifuchs
Copy link
Collaborator

antifuchs commented Mar 16, 2022

Hah! Fun question. There's no quota accessor on rate-limiters yet, because i haven't found a need for one so far (if you want to provide information to a user being rate-limited, check out the StateInformationMiddleware!)...

I think some janky ways exist to get at a StateSnapshot without the state information middleware, but if all you need is just the literal quota - I guess a thing that works like StateSnapshot::quota would be a great addition. I can probably add this later this week, or I'm happy to apply a PR you submit if you get to it first!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants