Skip to main content

LimitOutcome

Enum LimitOutcome 

Source
#[non_exhaustive]
pub enum LimitOutcome { Allow, ThroughputReject(String), WhitelistReject(String), ValueReject(String), Typed(LimitReason), }
Expand description

限额检查结果

v1.4.36 Bug #1 扩展:拒绝类型区分 Throughput vs Whitelist vs Value, 让 REST / gRPC middleware 能把不同类型映射到正确的 HTTP status:

  • Throughput(速率 / 日累计 / 时间窗)→ HTTP 429 Too Many Requests 客户端按 rate-limit 语义 backoff 重试即可
  • Whitelist(market / symbol / trd_side / acc_id 不在白名单)→ HTTP 403 Forbidden 客户端不该重试,是权限问题,需要改 key / 改请求参数
  • Value(单笔上限超 / NaN / inf / 负数)→ HTTP 403 Forbidden 同 Whitelist,不该重试;需要拆单或换 key

v1.4.106 codex 0542 F2 [P2 SECURITY]: *Reject(String) variants 现承载 audit_message() (内部 full-detail). client surface 应通过新 LimitReason 字段拿 public_message() (terse, no cap leak). 见 Self::reason_typed.

老代码用 Reject(String),保留作向后兼容 —— 但新检查应返对应 *Reject 类型。

v1.4.106 codex 0538 F1 (P1 SECURITY): ValueReject 内部带结构化原因, 让 fail-closed validation (NaN / inf / negative) 与 normal cap-exceeded 区分;display 消息仍 backward-compat 字符串格式。

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Allow

§

ThroughputReject(String)

速率 / 日累计 / 时间窗类拒绝(429 语义:客户端应 backoff 重试). String = LimitReason::audit_message().

§

WhitelistReject(String)

白名单类拒绝(403 语义:权限问题,不该重试). String = LimitReason::audit_message().

§

ValueReject(String)

金额上限拒绝(403 语义:不该重试;拆单或换 key). String = LimitReason::audit_message().

§

Typed(LimitReason)

v1.4.106 codex 0542 F2: typed reject — 推荐新代码用此 variant, caller 通过 LimitReason::public_message() / audit_message() / metric_label() 各自取所需视图. 与三个老 String variant 共存 (新代码 emit Typed, 老代码 emit *Reject(String) 仍工作).

Implementations§

Source§

impl LimitOutcome

Source

pub fn is_allow(&self) -> bool

是否拒绝(!is_allow 等价于“拒绝“)

Source

pub fn reason(&self) -> Option<String>

拒绝时的 reason 字符串(Allow 返 None).

v1.4.106 codex 0542 F2 调整: 现返 Option<String> (老 Option<&str> 兼容性 break, 但所有内部 caller 用 format!("{reason}") 不受影响). 走 Self::public_message 取 client surface 安全形式.

Source

pub fn reason_typed(&self) -> Option<&LimitReason>

v1.4.106 codex 0542 F2: typed reason (若 Typed(r) variant), 否则 None.

Source

pub fn public_message(&self) -> Option<String>

v1.4.106 codex 0542 F2: client-surface terse message.

Source

pub fn metric_label(&self) -> Option<&'static str>

v1.4.106 codex 0542 F2: prometheus metric_label (8 固定桶) 若 typed.

Source

pub fn http_status_code(&self) -> u16

适合此拒绝类型的 HTTP 状态码(REST / gRPC middleware 用)

  • Allow → 200
  • Throughput / typed throughput → 429
  • Whitelist / Value / typed whitelist/value → 403

Trait Implementations§

Source§

impl Clone for LimitOutcome

Source§

fn clone(&self) -> LimitOutcome

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for LimitOutcome

Source§

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

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

impl PartialEq for LimitOutcome

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for LimitOutcome

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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, 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more