pub struct Permit {
bucket: Arc<AtomicTokenBucket>,
granted: u64,
}Expand description
Proof that the requested number of tokens were granted.
If dropped, any remaining tokens will be refunded hence why there is a reference to the shared bucket.
Fields§
§bucket: Arc<AtomicTokenBucket>The bucket the unclaimed tokens are refunded to when this permit is dropped.
granted: u64How many granted tokens this permit still has.
Lowered by the claim methods. What is left is refunded on drop.
Implementations§
Source§impl Permit
impl Permit
Sourcefn new(bucket: Arc<AtomicTokenBucket>, granted: u64) -> Self
fn new(bucket: Arc<AtomicTokenBucket>, granted: u64) -> Self
Construct a permit granting granted tokens.
We keep a reference to the bucket for a refund if any.
Sourcepub fn claim(&mut self, tokens: u64) -> Result<(), BwPoolError>
pub fn claim(&mut self, tokens: u64) -> Result<(), BwPoolError>
Claim tokens from this permit.
Returns true if the permit had at least tokens that are now claimed. Else,
return false and nothing is claimed as in the caller is trying to use more
than it was granted.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Permit
impl RefUnwindSafe for Permit
impl Send for Permit
impl Sync for Permit
impl Unpin for Permit
impl UnsafeUnpin for Permit
impl UnwindSafe for Permit
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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