pub struct Gate { /* private fields */ }Expand description
闸。单实例持有若干委托及其账本/撤销/重放/策略状态。
Implementations§
Source§impl Gate
impl Gate
Sourcepub fn new(clock: SharedClock) -> Self
pub fn new(clock: SharedClock) -> Self
用给定时钟建闸。
Sourcepub fn with_system_clock() -> Self
pub fn with_system_clock() -> Self
用系统时钟建闸(生产路径)。
pub fn clock(&self) -> &SharedClock
Sourcepub fn with_clock(self, clock: SharedClock) -> Self
pub fn with_clock(self, clock: SharedClock) -> Self
换时钟句柄(断点续跑用):闸的委托/账本/撤销/nonce 状态都不含时钟,
句柄可整体替换——回放对账时用记录 ts 驱动的 [MockClock],校验过后
换回系统时钟继续服务,状态原封不动。
Sourcepub fn register_delegation(
&mut self,
delegation: Delegation,
) -> Result<(), CoreError>
pub fn register_delegation( &mut self, delegation: Delegation, ) -> Result<(), CoreError>
注册一份委托(fail-closed:校验不过 / id 重复 → 拒收)。
nonce_scope 允许与既有委托相同(同一 agent 多份委托共享 nonce 序列,属预期设计)。
Sourcepub fn revoke(&mut self, delegation_id: &str) -> Result<(), CoreError>
pub fn revoke(&mut self, delegation_id: &str) -> Result<(), CoreError>
撤销委托(kill switch,单向,幂等)。未知委托 → 错误。
pub fn is_revoked(&self, delegation_id: &str) -> bool
pub fn delegation(&self, delegation_id: &str) -> Option<&Delegation>
Sourcepub fn delegations(&self) -> impl Iterator<Item = &Delegation>
pub fn delegations(&self) -> impl Iterator<Item = &Delegation>
全部已注册委托(有序,供状态哈希/审计导出)。
Sourcepub fn spent_cents(&self, delegation_id: &str) -> Option<u64>
pub fn spent_cents(&self, delegation_id: &str) -> Option<u64>
某委托已累计消费(分);未知委托返回 None。
Sourcepub fn remaining_cents(&self, delegation_id: &str) -> Option<u64>
pub fn remaining_cents(&self, delegation_id: &str) -> Option<u64>
某委托剩余预算(分);未知委托返回 None。
pub fn revocations(&self) -> &RevocationSet
pub fn replay_registry(&self) -> &ReplayRegistry
pub fn ledger(&self) -> &BudgetLedger
Sourcepub fn velocity_stamps(&self, delegation_id: &str) -> &[u64]
pub fn velocity_stamps(&self, delegation_id: &str) -> &[u64]
某委托的速率窗口成功放行时刻(全量保留,升序);未启用速率或无记录 → 空切片。
Sourcepub fn category_spent_cents(
&self,
delegation_id: &str,
category: &str,
) -> Option<u64>
pub fn category_spent_cents( &self, delegation_id: &str, category: &str, ) -> Option<u64>
某委托某类目的累计消费(分);未设上限(无台账)或无记录 → None。
Sourcepub fn policy_states(&self) -> impl Iterator<Item = (&String, &PolicyState)>
pub fn policy_states(&self) -> impl Iterator<Item = (&String, &PolicyState)>
全部策略运行时状态(有序,供状态哈希/审计导出)。
Sourcepub fn evaluate(&self, intent: &SpendIntent) -> GateDecision
pub fn evaluate(&self, intent: &SpendIntent) -> GateDecision
纯检查:不修改任何状态(写审计层在放行时先落 WAL 再 commit)。
Sourcepub fn commit(&mut self, intent: &SpendIntent) -> Result<u64, CoreError>
pub fn commit(&mut self, intent: &SpendIntent) -> Result<u64, CoreError>
落地一笔已放行的意图:扣减预算 + 消耗 nonce + 记策略状态。 返回扣减后的累计消费(分)。
前置条件:evaluate 对同一意图返回 Allow(WanningState 的 write-ahead 顺序
依赖这一点)。commit 自身仍会重新 evaluate 防御 API 误用。
Sourcepub fn decide(&mut self, intent: &SpendIntent) -> GateDecision
pub fn decide(&mut self, intent: &SpendIntent) -> GateDecision
判定并落地(便捷入口,任务书 W-03 指定签名)。
时钟只读一次:evaluate 与 commit 用同一 now,否则跨秒边界时
WAL 记录的 ts 与速率窗口时刻可能不一致,回放对账 fail-closed。
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Gate
impl !UnwindSafe for Gate
impl Freeze for Gate
impl Send for Gate
impl Sync for Gate
impl Unpin for Gate
impl UnsafeUnpin for Gate
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