replace Box<> with VecDeque<>

This commit is contained in:
bitfl0wer 2023-04-07 21:51:50 +02:00
parent ea11db8460
commit bddce47896
No known key found for this signature in database
GPG Key ID: 84BBB60DF895ABF2
1 changed files with 10 additions and 5 deletions

View File

@ -1,4 +1,5 @@
use reqwest::{Client, Request}; use reqwest::{Client, Request};
use std::collections::VecDeque;
struct Limit { struct Limit {
limit: i64, limit: i64,
@ -6,22 +7,26 @@ struct Limit {
reset: i64, reset: i64,
} }
pub struct Ratelimiter { pub struct LimitedRequester {
http: Client, http: Client,
limit: Limit, limit: Limit,
requests: Box<[Request]>, // wow, amazing requests: VecDeque<Request>, // 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 { pub fn new() -> Self {
Ratelimiter { LimitedRequester {
limit: Limit { limit: Limit {
limit: 1, limit: 1,
remaining: 1, remaining: 1,
reset: 0, reset: 0,
}, },
http: Client::new(), http: Client::new(),
requests: Box::new([]), requests: VecDeque::new(),
} }
} }
} }