#[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
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
impl LimitOutcome
Sourcepub fn reason(&self) -> Option<String>
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 安全形式.
Sourcepub fn reason_typed(&self) -> Option<&LimitReason>
pub fn reason_typed(&self) -> Option<&LimitReason>
v1.4.106 codex 0542 F2: typed reason (若 Typed(r) variant), 否则 None.
Sourcepub fn public_message(&self) -> Option<String>
pub fn public_message(&self) -> Option<String>
v1.4.106 codex 0542 F2: client-surface terse message.
Sourcepub fn metric_label(&self) -> Option<&'static str>
pub fn metric_label(&self) -> Option<&'static str>
v1.4.106 codex 0542 F2: prometheus metric_label (8 固定桶) 若 typed.
Sourcepub fn http_status_code(&self) -> u16
pub fn http_status_code(&self) -> u16
适合此拒绝类型的 HTTP 状态码(REST / gRPC middleware 用)
Allow→ 200Throughput/ typed throughput → 429Whitelist/Value/ typed whitelist/value → 403
Trait Implementations§
Source§impl Clone for LimitOutcome
impl Clone for LimitOutcome
Source§fn clone(&self) -> LimitOutcome
fn clone(&self) -> LimitOutcome
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more