From bddce47896dc501ae222b0ed1ff154cd63581634 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Fri, 7 Apr 2023 21:51:50 +0200 Subject: [PATCH] replace Box<> with VecDeque<> --- src/limit.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/limit.rs b/src/limit.rs index 7efc3f5..dff43c8 100644 --- a/src/limit.rs +++ b/src/limit.rs @@ -1,4 +1,5 @@ use reqwest::{Client, Request}; +use std::collections::VecDeque; struct Limit { limit: i64, @@ -6,22 +7,26 @@ struct Limit { reset: i64, } -pub struct Ratelimiter { +pub struct LimitedRequester { http: Client, limit: Limit, - requests: Box<[Request]>, // wow, amazing + requests: VecDeque, // wow, amazing } -impl Ratelimiter { +impl LimitedRequester { + /// Create a new `LimitedRequester`. `LimitedRequester`s use a `VecDeque` to store requests and + /// send them to the server using a `Client`. It keeps track of the remaining requests that can + /// be send within the `Limit` of an external API Ratelimiter, and looks at the returned request + /// headers to see if it can find Ratelimit info to update itself. pub fn new() -> Self { - Ratelimiter { + LimitedRequester { limit: Limit { limit: 1, remaining: 1, reset: 0, }, http: Client::new(), - requests: Box::new([]), + requests: VecDeque::new(), } } }