Skip to main content

Gate

Struct Gate 

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

闸。单实例持有若干委托及其账本/撤销/重放/策略状态。

Implementations§

Source§

impl Gate

Source

pub fn new(clock: SharedClock) -> Self

用给定时钟建闸。

Source

pub fn with_system_clock() -> Self

用系统时钟建闸(生产路径)。

Source

pub fn clock(&self) -> &SharedClock

Source

pub fn with_clock(self, clock: SharedClock) -> Self

换时钟句柄(断点续跑用):闸的委托/账本/撤销/nonce 状态都不含时钟, 句柄可整体替换——回放对账时用记录 ts 驱动的 [MockClock],校验过后 换回系统时钟继续服务,状态原封不动。

Source

pub fn register_delegation( &mut self, delegation: Delegation, ) -> Result<(), CoreError>

注册一份委托(fail-closed:校验不过 / id 重复 → 拒收)。

nonce_scope 允许与既有委托相同(同一 agent 多份委托共享 nonce 序列,属预期设计)。

Source

pub fn revoke(&mut self, delegation_id: &str) -> Result<(), CoreError>

撤销委托(kill switch,单向,幂等)。未知委托 → 错误。

Source

pub fn is_revoked(&self, delegation_id: &str) -> bool

Source

pub fn delegation(&self, delegation_id: &str) -> Option<&Delegation>

Source

pub fn delegations(&self) -> impl Iterator<Item = &Delegation>

全部已注册委托(有序,供状态哈希/审计导出)。

Source

pub fn spent_cents(&self, delegation_id: &str) -> Option<u64>

某委托已累计消费(分);未知委托返回 None。

Source

pub fn remaining_cents(&self, delegation_id: &str) -> Option<u64>

某委托剩余预算(分);未知委托返回 None。

Source

pub fn revocations(&self) -> &RevocationSet

Source

pub fn replay_registry(&self) -> &ReplayRegistry

Source

pub fn ledger(&self) -> &BudgetLedger

Source

pub fn velocity_stamps(&self, delegation_id: &str) -> &[u64]

某委托的速率窗口成功放行时刻(全量保留,升序);未启用速率或无记录 → 空切片。

Source

pub fn category_spent_cents( &self, delegation_id: &str, category: &str, ) -> Option<u64>

某委托某类目的累计消费(分);未设上限(无台账)或无记录 → None。

Source

pub fn policy_states(&self) -> impl Iterator<Item = (&String, &PolicyState)>

全部策略运行时状态(有序,供状态哈希/审计导出)。

Source

pub fn evaluate(&self, intent: &SpendIntent) -> GateDecision

纯检查:不修改任何状态(写审计层在放行时先落 WAL 再 commit)。

Source

pub fn commit(&mut self, intent: &SpendIntent) -> Result<u64, CoreError>

落地一笔已放行的意图:扣减预算 + 消耗 nonce + 记策略状态。 返回扣减后的累计消费(分)。

前置条件:evaluate 对同一意图返回 Allow(WanningState 的 write-ahead 顺序 依赖这一点)。commit 自身仍会重新 evaluate 防御 API 误用。

Source

pub fn decide(&mut self, intent: &SpendIntent) -> GateDecision

判定并落地(便捷入口,任务书 W-03 指定签名)。

时钟只读一次:evaluate 与 commit 用同一 now,否则跨秒边界时 WAL 记录的 ts 与速率窗口时刻可能不一致,回放对账 fail-closed。

Trait Implementations§

Source§

impl Debug for Gate

Source§

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

Formats the value using the given formatter. Read more

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> 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 = !

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.