pub struct AtomicBudget { /* private fields */ }Expand description
Atomic, lock-free token-bucket budget.
Reference implementation of BudgetGuard. Backed by a single
AtomicU64 counter and CAS retries.
Implementations§
Source§impl AtomicBudget
impl AtomicBudget
Sourcepub fn utilization(&self) -> f64
pub fn utilization(&self) -> f64
Utilization in [0, 1]. Useful for telemetry gauges.
Trait Implementations§
Source§impl BudgetGuard for AtomicBudget
impl BudgetGuard for AtomicBudget
Source§fn try_reserve<'life0, 'async_trait>(
&'life0 self,
cost: u64,
) -> Pin<Box<dyn Future<Output = Result<bool, BudgetError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn try_reserve<'life0, 'async_trait>(
&'life0 self,
cost: u64,
) -> Pin<Box<dyn Future<Output = Result<bool, BudgetError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Try to reserve
cost units of budget for an upcoming operation.
Returns Ok(true) on success, Ok(false) on soft denial.Auto Trait Implementations§
impl !Freeze for AtomicBudget
impl RefUnwindSafe for AtomicBudget
impl Send for AtomicBudget
impl Sync for AtomicBudget
impl Unpin for AtomicBudget
impl UnsafeUnpin for AtomicBudget
impl UnwindSafe for AtomicBudget
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