Skip to main content

ThrottleDecision

Enum ThrottleDecision 

Source
pub enum ThrottleDecision {
    Allow {
        remaining: u32,
    },
    Banned {
        until: u64,
    },
    Unavailable,
}

Variants§

§

Allow

放行,remaining 为窗口内剩余可失败次数(可写进 X-RateLimit-* 响应头)。

remaining == 0 表示本请求应被拒绝(额度已耗尽),不是「还能再试一次」; 调用方必须据此拒绝,否则最后一次额度形同虚设。仍叫 Allow 而非 Banned, 是因为此刻并没有封禁在生效 —— 例如 ban_secs = 0 的配置下,额度耗尽的 key 会一直落在这一支。

Fields

§remaining: u32
§

Banned

已封禁,until 是解封时刻(unix 秒)。now >= until 即视为已解封。

Fields

§until: u64
§

Unavailable

存储后端不可用,本模块不替调用方做决定。

与 session 模块的 fail-closed 有意不同:限流是纵深防御而非主认证闸门, 后端抖动时把全体用户挡在门外是自我 DoS,而放行只是暂时失去暴力破解防护 —— 主认证闸门(SessionGuard)仍然在拦。调用方拿到这个变体后自行选择 (建议:放行 + 告警)。

这条「不 fail-closed」是写死的设计,不是漏写的兜底:Throttle::check 里 只把 Err 映射到本变体,绝不映射到 Banned。

只由 guard::Throttle::check / guard::Throttle::check_any 产生。 guard::Throttle::record_failure 没有这个变体(它返回 ThrottleOutcome,故障走 Err),所以调用方不必为它写死分支。

Trait Implementations§

Source§

impl Clone for ThrottleDecision

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ThrottleDecision

Source§

impl Debug for ThrottleDecision

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ThrottleDecision

状态标签,与 Severity 同样用大写。

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ThrottleDecision

Source§

impl PartialEq for ThrottleDecision

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ThrottleDecision

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.