pub struct Fuel { /* private fields */ }Expand description
A decrementing resource budget shared across algorithm invocations.
Clone produces a new handle to the same underlying counter; consumption
on any clone is observed by all clones. Use this to thread a single budget
through nested calls without passing &Fuel everywhere.
Implementations§
Source§impl Fuel
impl Fuel
Sourcepub fn consume(&self, n: usize)
pub fn consume(&self, n: usize)
Consume n units. If the remaining budget would drop to zero or below,
the counter saturates at zero (subsequent Self::check fails). This
call is infallible — query the outcome with Self::check or read the
residual via Self::remaining.
Sourcepub fn check(&self) -> Result<()>
pub fn check(&self) -> Result<()>
Return Ok(()) if budget remains, Err(OutOfFuel) otherwise. Cheap
hot-path probe; use between small units of work to avoid an explicit
Self::consume on every iteration.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Fuel
impl RefUnwindSafe for Fuel
impl Send for Fuel
impl Sync for Fuel
impl Unpin for Fuel
impl UnsafeUnpin for Fuel
impl UnwindSafe for Fuel
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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