Skip to main content

RateLimitConfigBuilder

Struct RateLimitConfigBuilder 

Source
pub struct RateLimitConfigBuilder { /* private fields */ }
Expand description

限流配置构建器

链式 API 构建限流配置。

§示例

use sz_orm_limit::config_builder::{RateLimitConfigBuilder, LimitAlgorithm};

let config = RateLimitConfigBuilder::new()
    .algorithm(LimitAlgorithm::TokenBucket)
    .capacity(100)
    .rate(10.0)
    .max_keys(5000)
    .build();

Implementations§

Source§

impl RateLimitConfigBuilder

Source

pub fn new() -> Self

创建构建器

Source

pub fn algorithm(self, algo: LimitAlgorithm) -> Self

设置算法类型

Source

pub fn capacity(self, cap: u64) -> Self

设置容量

Source

pub fn rate(self, rate: f64) -> Self

设置速率

Source

pub fn window_ms(self, ms: u64) -> Self

设置窗口大小(毫秒)

Source

pub fn window_secs(self, secs: u64) -> Self

设置窗口大小(秒)

Source

pub fn max_keys(self, max: usize) -> Self

设置最大 key 数量

Source

pub fn build(self) -> RateLimitConfig

构建配置(不校验)

Source

pub fn build_checked(self) -> Result<RateLimitConfig, ConfigError>

构建配置并校验

Source

pub fn build_token_bucket(&self) -> TokenBucketRateLimiter

从配置构建令牌桶限流器

Source

pub fn build_sliding_window(&self) -> SlidingWindowRateLimiter

从配置构建滑动窗口限流器

Source

pub fn build_fixed_window(&self) -> FixedWindowRateLimiter

从配置构建固定窗口限流器

Source

pub fn build_leaky_bucket(&self) -> LeakyBucketLimiter

从配置构建漏桶限流器

Source

pub fn build_sliding_window_log(&self) -> SlidingWindowLogLimiter

从配置构建滑动窗口日志限流器

Trait Implementations§

Source§

impl Default for RateLimitConfigBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.