add .iter() to Limits

This commit is contained in:
bitfl0wer 2023-04-12 18:18:55 +02:00
parent ccff2b73c6
commit 58c5025afe
No known key found for this signature in database
GPG Key ID: 84BBB60DF895ABF2
1 changed files with 16 additions and 0 deletions

View File

@ -100,6 +100,7 @@ pub mod limits {
pub absoluteRate: AbsoluteRate, pub absoluteRate: AbsoluteRate,
} }
#[derive(Clone)]
pub struct Limit { pub struct Limit {
pub bucket: String, pub bucket: String,
pub limit: u64, pub limit: u64,
@ -130,6 +131,21 @@ pub mod limits {
} }
impl Limits { impl Limits {
pub fn iter(&self) -> std::vec::IntoIter<Limit> {
let mut limits: Vec<Limit> = Vec::new();
limits.push(self.limit_absolute_messages.clone());
limits.push(self.limit_absolute_register.clone());
limits.push(self.limit_auth_login.clone());
limits.push(self.limit_auth_register.clone());
limits.push(self.limit_ip.clone());
limits.push(self.limit_global.clone());
limits.push(self.limit_error.clone());
limits.push(self.limit_guild.clone());
limits.push(self.limit_webhook.clone());
limits.push(self.limit_channel.clone());
limits.into_iter()
}
/// check_limits uses the API to get the current request limits of the instance. /// check_limits uses the API to get the current request limits of the instance.
/// It returns a `Limits` struct containing all the limits. /// It returns a `Limits` struct containing all the limits.
pub async fn check_limits(api_url: String) -> Limits { pub async fn check_limits(api_url: String) -> Limits {