pub struct RateLimitHeaders {
pub limit: u64,
pub remaining: u64,
pub reset: i64,
pub retry_after: Option<u64>,
}Expand description
限流响应头
生成标准的限流响应头,适用于 HTTP API 响应。
§标准头
X-RateLimit-Limit:窗口内最大请求数X-RateLimit-Remaining:剩余请求数X-RateLimit-Reset:窗口重置时间(Unix 秒)Retry-After:拒绝时建议的重试等待时间(秒),仅在拒绝时包含
Fields§
§limit: u64窗口内最大请求数
remaining: u64剩余请求数
reset: i64窗口重置时间(Unix 秒)
retry_after: Option<u64>重试等待时间(秒),仅在被拒绝时设置
Implementations§
Source§impl RateLimitHeaders
impl RateLimitHeaders
Sourcepub fn from_result(result: &RateLimitResult, limit: u64) -> Self
pub fn from_result(result: &RateLimitResult, limit: u64) -> Self
从限流结果创建响应头
result:限流结果limit:窗口内最大请求数
Sourcepub fn to_headers(&self) -> Vec<(String, String)>
pub fn to_headers(&self) -> Vec<(String, String)>
转换为 HTTP 头键值对
Trait Implementations§
Source§impl Clone for RateLimitHeaders
impl Clone for RateLimitHeaders
Source§fn clone(&self) -> RateLimitHeaders
fn clone(&self) -> RateLimitHeaders
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for RateLimitHeaders
impl RefUnwindSafe for RateLimitHeaders
impl Send for RateLimitHeaders
impl Sync for RateLimitHeaders
impl Unpin for RateLimitHeaders
impl UnsafeUnpin for RateLimitHeaders
impl UnwindSafe for RateLimitHeaders
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more