Skip to main content

SemaphorePermit

Struct SemaphorePermit 

Source
pub struct SemaphorePermit<'a, P: Priority, Q: SemaphoreQueue<P>>(/* private fields */);
Expand description

A permit (or collection of permits) from a Semaphore

Acquired via Semaphore::acquire and associated fns.

Implementations§

Source§

impl<'a, P: Priority, Q: SemaphoreQueue<P>> SemaphorePermit<'a, P, Q>

Source

pub fn evicted(&mut self) -> impl Future<Output = ()>

Returns a future which resolves when / if a higher priority requester is waiting for permit acquisition. Available only if the evict flag is enabled.

Cancel Safety: This function is cancel safe.

Source

pub fn forget(self)

Remove these permits from the pool of permits in the semaphore.

Source

pub fn permits(&self) -> usize

The count of permits held

Source

pub fn belongs_to(&self, semaphore: &Semaphore<P, Q>) -> bool

Checks if self belongs to semaphore.

Source

pub fn split(&mut self, count: usize) -> Result<Self, InsufficientPermitsError>
where P: Clone,

Split into multiple permit guards / holder. The new guard will have the same priority for evictions.

P must implement Clone for this to succeed. If P is not Clone, split_with_priority may be used instead.

Source

pub fn split_with_priority( &mut self, count: usize, priority: P, ) -> Result<Self, InsufficientPermitsError>

Source

pub fn merge(&mut self, other: Self) -> Result<(), ()>

Merge another permit into this one. Returns an error if the other node belongs to another semaphore

Panics if the sum of their permits would exceed the max permit count

Trait Implementations§

Source§

impl<'a, P: Priority, Q: SemaphoreQueue<P>> Debug for SemaphorePermit<'a, P, Q>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, P: Priority, Q: SemaphoreQueue<P>> Drop for SemaphorePermit<'a, P, Q>

Source§

fn drop(&mut self)

Releases the permits back to the semaphore.

Source§

impl<'a, P: Priority, Q: SemaphoreQueue<P>> Send for SemaphorePermit<'a, P, Q>
where Semaphore<P, Q>: Sync, Q::Handle: Send,

Source§

impl<'a, P: Priority, Q: SemaphoreQueue<P>> Sync for SemaphorePermit<'a, P, Q>
where Semaphore<P, Q>: Sync, Q::Handle: Sync,

Auto Trait Implementations§

§

impl<'a, P, Q> Freeze for SemaphorePermit<'a, P, Q>

§

impl<'a, P, Q> RefUnwindSafe for SemaphorePermit<'a, P, Q>

§

impl<'a, P, Q> Unpin for SemaphorePermit<'a, P, Q>

§

impl<'a, P, Q> UnsafeUnpin for SemaphorePermit<'a, P, Q>

§

impl<'a, P, Q> UnwindSafe for SemaphorePermit<'a, P, Q>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.