Skip to main content

ManagedResourcePermit

Struct ManagedResourcePermit 

Source
pub struct ManagedResourcePermit<R, Q = u64>{ /* private fields */ }
Expand description

Owns acquired capacity and returns it to its pool when dropped.

A permit may move across threads when its resource and quantity types allow that movement. Calling Self::release returns capacity early; otherwise normal Drop, early returns, ?, and panic unwinding all return it.

§Type Parameters

  • R - Caller-defined resource value retained by the owning pool.
  • Q - Exact unsigned quantity owned by this permit.

§Examples

use qubit_budget::ManagedResourcePool;

let pool = ManagedResourcePool::new("connections", 1_u64);
let permit = pool.try_acquire(1).expect("one connection should fit");
assert_eq!(permit.amount(), 1);
permit.release();
assert_eq!(pool.available(), 1);

Implementations§

Source§

impl<R, Q> ManagedResourcePermit<R, Q>

Source

pub fn resource(&self) -> &R

Returns the resource whose capacity this permit owns.

§Panics

Panics only if an internal invariant is violated and a live permit no longer retains its owning pool.

Source

pub const fn amount(&self) -> Q

Returns the quantity owned by this permit.

Source

pub fn release(self)

Returns this permit’s capacity before the end of its lexical scope.

Consuming self prevents callers from releasing the same permit twice.

Trait Implementations§

Source§

impl<R: Debug, Q> Debug for ManagedResourcePermit<R, Q>

Source§

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

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

impl<R, Q> Drop for ManagedResourcePermit<R, Q>

Source§

fn drop(&mut self)

Returns owned capacity without panicking during unwinding.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<R, Q> Freeze for ManagedResourcePermit<R, Q>
where Option<Arc<ManagedResourcePoolInner<R, Q>>>: Freeze, Q: Freeze,

§

impl<R, Q> RefUnwindSafe for ManagedResourcePermit<R, Q>
where Option<Arc<ManagedResourcePoolInner<R, Q>>>: RefUnwindSafe, Q: RefUnwindSafe,

§

impl<R, Q> Send for ManagedResourcePermit<R, Q>
where Option<Arc<ManagedResourcePoolInner<R, Q>>>: Send, Q: Send,

§

impl<R, Q> Sync for ManagedResourcePermit<R, Q>
where Option<Arc<ManagedResourcePoolInner<R, Q>>>: Sync, Q: Sync,

§

impl<R, Q> Unpin for ManagedResourcePermit<R, Q>
where Option<Arc<ManagedResourcePoolInner<R, Q>>>: Unpin, Q: Unpin,

§

impl<R, Q> UnsafeUnpin for ManagedResourcePermit<R, Q>
where Option<Arc<ManagedResourcePoolInner<R, Q>>>: UnsafeUnpin, Q: UnsafeUnpin,

§

impl<R, Q> UnwindSafe for ManagedResourcePermit<R, Q>
where Option<Arc<ManagedResourcePoolInner<R, Q>>>: UnwindSafe, Q: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.