throttlecrab_server/
types.rs1use serde::{Deserialize, Serialize};
2use std::time::SystemTime;
3use throttlecrab::RateLimitResult;
4
5#[derive(Debug, Clone)]
6pub struct ThrottleRequest {
7 pub key: String,
8 pub max_burst: i64,
9 pub count_per_period: i64,
10 pub period: i64, pub quantity: i64,
12 pub timestamp: SystemTime,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct ThrottleResponse {
17 pub allowed: bool,
18 pub limit: i64,
19 pub remaining: i64,
20 pub reset_after: i64, pub retry_after: i64, }
23
24impl From<(bool, RateLimitResult)> for ThrottleResponse {
25 fn from((allowed, result): (bool, RateLimitResult)) -> Self {
26 ThrottleResponse {
27 allowed,
28 limit: result.limit,
29 remaining: result.remaining,
30 reset_after: result.reset_after.as_secs() as i64,
31 retry_after: result.retry_after.as_secs() as i64,
32 }
33 }
34}