pub struct RateLimitConfig {
pub algorithm: LimitAlgorithm,
pub capacity: u64,
pub rate: f64,
pub window_ms: u64,
pub max_keys: usize,
}Expand description
限流配置
描述一个限流器的完整配置,可序列化/反序列化。
Fields§
§algorithm: LimitAlgorithm算法类型
capacity: u64容量/最大请求数
rate: f64补充速率(令牌桶)/ 漏出速率(漏桶),单位:请求/秒
window_ms: u64窗口大小(毫秒),用于固定窗口和滑动窗口
max_keys: usize最大 key 数量
Implementations§
Source§impl RateLimitConfig
impl RateLimitConfig
Sourcepub fn from_json_str(s: &str) -> Result<Self, ConfigError>
pub fn from_json_str(s: &str) -> Result<Self, ConfigError>
从 JSON 字符串解析配置
Sourcepub fn to_json_string(&self) -> Result<String, ConfigError>
pub fn to_json_string(&self) -> Result<String, ConfigError>
序列化为 JSON 字符串
Sourcepub fn validate(&self) -> Result<(), ConfigError>
pub fn validate(&self) -> Result<(), ConfigError>
校验配置合理性
Trait Implementations§
Source§impl Clone for RateLimitConfig
impl Clone for RateLimitConfig
Source§fn clone(&self) -> RateLimitConfig
fn clone(&self) -> RateLimitConfig
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 moreSource§impl Debug for RateLimitConfig
impl Debug for RateLimitConfig
Source§impl Default for RateLimitConfig
impl Default for RateLimitConfig
Source§impl<'de> Deserialize<'de> for RateLimitConfig
impl<'de> Deserialize<'de> for RateLimitConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for RateLimitConfig
impl RefUnwindSafe for RateLimitConfig
impl Send for RateLimitConfig
impl Sync for RateLimitConfig
impl Unpin for RateLimitConfig
impl UnsafeUnpin for RateLimitConfig
impl UnwindSafe for RateLimitConfig
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