From d837d4ab0f55a241341d612e0658355784f6726f Mon Sep 17 00:00:00 2001 From: Tim Vilgot Mikael Fredenberg Date: Fri, 24 Oct 2025 17:44:22 +0200 Subject: [PATCH] feat(http-ratelimiting): add convencince methods to `Bucket` --- twilight-http-ratelimiting/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/twilight-http-ratelimiting/src/lib.rs b/twilight-http-ratelimiting/src/lib.rs index 3607ed09c1..b7a5ac1fb9 100644 --- a/twilight-http-ratelimiting/src/lib.rs +++ b/twilight-http-ratelimiting/src/lib.rs @@ -250,6 +250,18 @@ pub struct Bucket { pub reset_at: Instant, } +impl Bucket { + /// Whether the bucket is exhausted. + pub const fn is_exhausted(&self) -> bool { + self.remaining == 0 + } + + /// Duration until the bucket resets. + pub fn reset_after(&self) -> Duration { + self.reset_at.saturating_duration_since(Instant::now()) + } +} + /// Actor run closure pre-enqueue for early [`MaybePermitFuture`] cancellation. type Predicate = Box) -> bool + Send>;