pub struct TokenBudgetAspect { /* private fields */ }Expand description
Token-budget aspect.
The host system calls set_budget(session, max) once and bind(charge)
before each guarded invocation. The around advice debits the budget
if the call would still fit; otherwise it short-circuits with an error.
Implementations§
Source§impl TokenBudgetAspect
impl TokenBudgetAspect
Sourcepub fn set_budget(&self, session: impl Into<SessionId>, cap: u64)
pub fn set_budget(&self, session: impl Into<SessionId>, cap: u64)
Set or reset the budget cap for a session.
Sourcepub fn remaining(&self, session: &str) -> Option<u64>
pub fn remaining(&self, session: &str) -> Option<u64>
Read remaining tokens for a session. Returns None if no budget
has been declared.
Sourcepub fn bind(&self, charge: TokenCharge) -> u64
pub fn bind(&self, charge: TokenCharge) -> u64
Bind a charge to the next guarded invocation.
Trait Implementations§
Source§impl Aspect for TokenBudgetAspect
impl Aspect for TokenBudgetAspect
Source§fn around(
&self,
pjp: ProceedingJoinPoint<'_>,
) -> Result<Box<dyn Any>, AspectError>
fn around( &self, pjp: ProceedingJoinPoint<'_>, ) -> Result<Box<dyn Any>, AspectError>
Advice that wraps the entire target function execution. Read more
Source§fn after(&self, _ctx: &JoinPoint, _result: &(dyn Any + 'static))
fn after(&self, _ctx: &JoinPoint, _result: &(dyn Any + 'static))
Advice executed after the target function completes successfully. Read more
Source§fn after_error(&self, _ctx: &JoinPoint, _error: &AspectError)
fn after_error(&self, _ctx: &JoinPoint, _error: &AspectError)
Advice executed when the target function encounters an error. Read more
Source§impl Clone for TokenBudgetAspect
impl Clone for TokenBudgetAspect
Source§fn clone(&self) -> TokenBudgetAspect
fn clone(&self) -> TokenBudgetAspect
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for TokenBudgetAspect
impl Default for TokenBudgetAspect
Source§fn default() -> TokenBudgetAspect
fn default() -> TokenBudgetAspect
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TokenBudgetAspect
impl !RefUnwindSafe for TokenBudgetAspect
impl Send for TokenBudgetAspect
impl Sync for TokenBudgetAspect
impl Unpin for TokenBudgetAspect
impl UnsafeUnpin for TokenBudgetAspect
impl !UnwindSafe for TokenBudgetAspect
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