pub struct ClaimedTokens<'a, I> {
bucket: &'a mut TokenBucket<I>,
count: u64,
}Expand description
A handle to a number of claimed tokens.
Dropping this handle will commit the claim.
Fields§
§bucket: &'a mut TokenBucket<I>The bucket that the claim is for.
count: u64How many tokens to remove from the bucket.
Implementations§
Source§impl<'a, I> ClaimedTokens<'a, I>
impl<'a, I> ClaimedTokens<'a, I>
Sourcefn new(bucket: &'a mut TokenBucket<I>, count: u64) -> Self
fn new(bucket: &'a mut TokenBucket<I>, count: u64) -> Self
Create a new ClaimedTokens that will remove count tokens from the token bucket when
dropped.
Sourcepub fn commit(self) -> BecameEmpty
pub fn commit(self) -> BecameEmpty
Commit the claimed tokens.
This is equivalent to just dropping the ClaimedTokens, but also returns whether the
token bucket became empty or not.
Sourcepub fn reduce(&mut self, count: u64) -> Result<(), InsufficientTokensError>
pub fn reduce(&mut self, count: u64) -> Result<(), InsufficientTokensError>
Reduce the claim to a fewer number of tokens than the original claim.
If count is larger than the original claim, an error will be returned containing the
current number of claimed tokens.
Sourcefn commit_impl(&mut self) -> BecameEmpty
fn commit_impl(&mut self) -> BecameEmpty
The commit implementation.
After calling commit_impl(),
the ClaimedTokens should no longer be used and should be dropped immediately.
Trait Implementations§
Source§impl<'a, I: Debug> Debug for ClaimedTokens<'a, I>
impl<'a, I: Debug> Debug for ClaimedTokens<'a, I>
Source§impl<'a, I> Drop for ClaimedTokens<'a, I>
impl<'a, I> Drop for ClaimedTokens<'a, I>
Auto Trait Implementations§
impl<'a, I> !UnwindSafe for ClaimedTokens<'a, I>
impl<'a, I> Freeze for ClaimedTokens<'a, I>
impl<'a, I> RefUnwindSafe for ClaimedTokens<'a, I>where
I: RefUnwindSafe,
impl<'a, I> Send for ClaimedTokens<'a, I>where
I: Send,
impl<'a, I> Sync for ClaimedTokens<'a, I>where
I: Sync,
impl<'a, I> Unpin for ClaimedTokens<'a, I>
impl<'a, I> UnsafeUnpin for ClaimedTokens<'a, I>
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> 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