pub struct SpendControl { /* private fields */ }Expand description
Spend controller that enforces budget limits.
Implementations§
Source§impl SpendControl
impl SpendControl
pub fn new(limits: SpendLimits) -> Self
Sourcepub fn check(&self, estimated_cost_usd: f64) -> Result<(), SpendLimitExceeded>
pub fn check(&self, estimated_cost_usd: f64) -> Result<(), SpendLimitExceeded>
Check if a request with estimated cost would exceed any limit. Returns Ok(()) if allowed, Err(reason) if blocked.
Sourcepub fn spend_in_window(&self, now: u64, window_secs: u64) -> f64
pub fn spend_in_window(&self, now: u64, window_secs: u64) -> f64
Get total spend in a time window (seconds from now).
Sourcepub fn hourly_spend(&self) -> f64
pub fn hourly_spend(&self) -> f64
Get total spend in the last hour.
Sourcepub fn daily_spend(&self) -> f64
pub fn daily_spend(&self) -> f64
Get total spend in the last 24 hours.
Sourcepub fn status(&self) -> SpendStatus
pub fn status(&self) -> SpendStatus
Get spend status summary.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SpendControl
impl RefUnwindSafe for SpendControl
impl Send for SpendControl
impl Sync for SpendControl
impl Unpin for SpendControl
impl UnsafeUnpin for SpendControl
impl UnwindSafe for SpendControl
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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