pub struct BudgetTracker { /* private fields */ }Expand description
Cumulative USD budget tracker with threshold callbacks.
See the module docs for the full design.
Implementations§
Source§impl BudgetTracker
impl BudgetTracker
Sourcepub fn builder() -> BudgetBuilder
pub fn builder() -> BudgetBuilder
Start building a tracker.
Sourcepub fn record(&self, cost_usd: f64)
pub fn record(&self, cost_usd: f64)
Record an additional cost in USD. Fires on_warning the first
time the running total reaches warn_at_usd, and on_exceeded
the first time it reaches max_usd.
Sourcepub fn check(&self) -> Result<()>
pub fn check(&self) -> Result<()>
Return Err(Error::BudgetExceeded) if the running total is at
or above the configured max_usd. Returns Ok(()) when no
ceiling is set.
Sourcepub fn remaining_usd(&self) -> Option<f64>
pub fn remaining_usd(&self) -> Option<f64>
Remaining budget in USD, if a ceiling is set. Clamped at zero once the ceiling is reached.
Sourcepub fn warn_at_usd(&self) -> Option<f64>
pub fn warn_at_usd(&self) -> Option<f64>
Configured warning threshold, if any.
Trait Implementations§
Source§impl Clone for BudgetTracker
impl Clone for BudgetTracker
Source§fn clone(&self) -> BudgetTracker
fn clone(&self) -> BudgetTracker
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for BudgetTracker
impl !RefUnwindSafe for BudgetTracker
impl Send for BudgetTracker
impl Sync for BudgetTracker
impl Unpin for BudgetTracker
impl UnsafeUnpin for BudgetTracker
impl !UnwindSafe for BudgetTracker
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