How to find out the quota after a rate limiter is created?
conorbros opened this issue · comments
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));
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!