pub struct ManagedResourcePermit<R, Q = u64>where
Q: ResourceQuantity,{ /* 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>where
Q: ResourceQuantity,
impl<R, Q> ManagedResourcePermit<R, Q>where
Q: ResourceQuantity,
Trait Implementations§
Source§impl<R: Debug, Q> Debug for ManagedResourcePermit<R, Q>where
Q: ResourceQuantity + Debug,
impl<R: Debug, Q> Debug for ManagedResourcePermit<R, Q>where
Q: ResourceQuantity + Debug,
Source§impl<R, Q> Drop for ManagedResourcePermit<R, Q>where
Q: ResourceQuantity,
impl<R, Q> Drop for ManagedResourcePermit<R, Q>where
Q: ResourceQuantity,
Auto Trait Implementations§
impl<R, Q> Freeze for ManagedResourcePermit<R, Q>
impl<R, Q> RefUnwindSafe for ManagedResourcePermit<R, Q>
impl<R, Q> Send for ManagedResourcePermit<R, Q>
impl<R, Q> Sync for ManagedResourcePermit<R, Q>
impl<R, Q> Unpin for ManagedResourcePermit<R, Q>
impl<R, Q> UnsafeUnpin for ManagedResourcePermit<R, Q>
impl<R, Q> UnwindSafe for ManagedResourcePermit<R, Q>
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
Mutably borrows from an owned value. Read more