pub struct AiBudgetEngine { /* private fields */ }Expand description
The per-generation budget rules plus the reload-surviving ledger.
Implementations§
Source§impl AiBudgetEngine
impl AiBudgetEngine
Sourcepub fn compile(gateway: &Gateway) -> Self
pub fn compile(gateway: &Gateway) -> Self
Compile from the gateway config; the ledger starts empty.
Sourcepub fn compile_with_ledger(gateway: &Gateway, ledger: Arc<BudgetLedger>) -> Self
pub fn compile_with_ledger(gateway: &Gateway, ledger: Arc<BudgetLedger>) -> Self
Compile with a PREVIOUS generation’s ledger (reload: rules change, spend survives — except for holders the new generation can no longer derive, whose keys are pruned so carried state stays config-bounded).
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether any policy or consumer declares a budget (cheap dataplane skip).
Sourcepub fn ledger(&self) -> Arc<BudgetLedger>
pub fn ledger(&self) -> Arc<BudgetLedger>
The shared ledger (carried into the next generation).
Sourcepub fn resolve(
&self,
consumer: Option<&str>,
consumer_policies: &[String],
route_policies: &[String],
service_policies: &[String],
listener_policies: &[String],
global_policies: &[String],
) -> Option<BudgetGuard>
pub fn resolve( &self, consumer: Option<&str>, consumer_policies: &[String], route_policies: &[String], service_policies: &[String], listener_policies: &[String], global_policies: &[String], ) -> Option<BudgetGuard>
Resolve the binding budget for one request: the FIRST policy
carrying a token_budget in the frozen precedence chain
consumer > route > service > listener > global (a budget is a
limit-of-totals, so the most specific level governs — unlike
AND-composed rate rules). The ledger key is the consumer name
or, for a team budget (scope: policy), the policy name.
An ANONYMOUS request has no per-consumer window, so a consumer-scoped budget CANNOT bind it: that candidate is skipped and the walk CONTINUES — aborting here would silently unlimit the request even when a less-specific policy-scoped (team) budget later in the chain should govern it.
Trait Implementations§
Source§impl Debug for AiBudgetEngine
impl Debug for AiBudgetEngine
Source§impl Default for AiBudgetEngine
impl Default for AiBudgetEngine
Source§fn default() -> AiBudgetEngine
fn default() -> AiBudgetEngine
Auto Trait Implementations§
impl !Freeze for AiBudgetEngine
impl RefUnwindSafe for AiBudgetEngine
impl Send for AiBudgetEngine
impl Sync for AiBudgetEngine
impl Unpin for AiBudgetEngine
impl UnwindSafe for AiBudgetEngine
Blanket Implementations§
§impl<T> AnyExt for T
impl<T> AnyExt for T
§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind reference§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable reference§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointer§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointer§fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
T behind Box pointer§fn downcast_move<T>(this: Self) -> Option<T>
fn downcast_move<T>(this: Self) -> Option<T>
Self to T,
useful only in generic context as a workaround for specializationSource§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
§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more