tokio_sync::semaphore

Struct Permit

Source
pub struct Permit { /* private fields */ }
Expand description

A semaphore permit

Tracks the lifecycle of a semaphore permit.

An instance of Permit is intended to be used with a single instance of Semaphore. Using a single instance of Permit with multiple semaphore instances will result in unexpected behavior.

Permit does not release the permit back to the semaphore on drop. It is the user’s responsibility to ensure that Permit::release is called before dropping the permit.

Implementations§

Source§

impl Permit

Source

pub fn new() -> Permit

Create a new Permit.

The permit begins in the “unacquired” state.

§Examples
use tokio_sync::semaphore::Permit;

let permit = Permit::new();
assert!(!permit.is_acquired());
Source

pub fn is_acquired(&self) -> bool

Returns true if the permit has been acquired

Source

pub fn poll_acquire(&mut self, semaphore: &Semaphore) -> Poll<(), AcquireError>

Try to acquire the permit. If no permits are available, the current task is notified once a new permit becomes available.

Source

pub fn try_acquire( &mut self, semaphore: &Semaphore, ) -> Result<(), TryAcquireError>

Try to acquire the permit.

Source

pub fn release(&mut self, semaphore: &Semaphore)

Release a permit back to the semaphore

Source

pub fn forget(&mut self)

Forget the permit without releasing it back to the semaphore.

After calling forget, poll_acquire is able to acquire new permit from the sempahore.

Repeatedly calling forget without associated calls to add_permit will result in the semaphore losing all permits.

Trait Implementations§

Source§

impl Debug for Permit

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Permit

§

impl !RefUnwindSafe for Permit

§

impl Send for Permit

§

impl Sync for Permit

§

impl Unpin for Permit

§

impl !UnwindSafe for Permit

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.