pub struct Permits { /* private fields */ }
Implementations§
Source§impl Permits
impl Permits
Sourcepub fn new(limit: usize) -> Self
pub fn new(limit: usize) -> Self
Make a new set of permits with limit
maximum concurrent permits available.
Sourcepub fn get(&self) -> Option<Permit>
pub fn get(&self) -> Option<Permit>
Attempts to get a permit. Returns None if there are no permits available.
Sourcepub fn get_revokable(
&self,
revoked_fn: impl FnOnce() -> Permit + 'static + Send,
) -> Option<Permit>
pub fn get_revokable( &self, revoked_fn: impl FnOnce() -> Permit + 'static + Send, ) -> Option<Permit>
Attempts to get a permit that is revokable. Revokable permits can be revoked at any time
after this function returns and must return the Permit when asked. revoked_fn
will be
called to retrieve the permit when it is revoked.
Sourcepub fn take(&self) -> Option<Permit>
pub fn take(&self) -> Option<Permit>
Attempts to get a permit. If a permit isn’t available, but one can be revoked, one will be revoked to return a permit. Revoked permits are returned here before reservations are filled.
Sourcepub fn seize(&self) -> Vec<Permit>
pub fn seize(&self) -> Vec<Permit>
Attempts to reserve all permits, including revoking any permits to do so. Permits that are seized are prioritized over any reservations.
Sourcepub fn reserve(&self) -> Reservation ⓘ
pub fn reserve(&self) -> Reservation ⓘ
Reserve a spot in line to receive a permit once one becomes available. Returns a future that resolves to a permit Reservations are first-come-first-serve, but permits that are revoked ignore reservations.
Sourcepub fn reserve_revokable(
&self,
revoked_fn: impl FnOnce() -> Permit + 'static + Send,
) -> Reservation ⓘ
pub fn reserve_revokable( &self, revoked_fn: impl FnOnce() -> Permit + 'static + Send, ) -> Reservation ⓘ
Reserve a spot in line to receive a permit once one becomes available. Returns a future that resovles to a revokable permit. Once the permit has been returned from the Reservation, it can be revoked at any time afterwards.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Permits
impl !RefUnwindSafe for Permits
impl Send for Permits
impl Sync for Permits
impl Unpin for Permits
impl !UnwindSafe for Permits
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)