pub struct ResourcePool { /* private fields */ }Expand description
The main resource pool that tracks multiple resource types.
Implementations§
Source§impl ResourcePool
impl ResourcePool
Sourcepub fn register(&mut self, descriptor: ResourceDescriptor)
pub fn register(&mut self, descriptor: ResourceDescriptor)
Register a resource with the pool.
Sourcepub fn allocate(
&mut self,
request: &ResourceRequest,
) -> Result<AllocationToken, PoolError>
pub fn allocate( &mut self, request: &ResourceRequest, ) -> Result<AllocationToken, PoolError>
Attempt to allocate a resource, returning a token on success.
§Errors
Returns PoolError if the resource is not found or has insufficient capacity.
Sourcepub fn release(&mut self, token_id: u64) -> Result<(), PoolError>
pub fn release(&mut self, token_id: u64) -> Result<(), PoolError>
Release a previous allocation using its token.
§Errors
Returns PoolError::InvalidToken if the token does not match any active allocation.
Sourcepub fn snapshot(&self) -> Vec<ResourceDescriptor>
pub fn snapshot(&self) -> Vec<ResourceDescriptor>
Return a snapshot of all resources and their current state.
Sourcepub fn get_resource(&self, id: &ResourceId) -> Option<&ResourceDescriptor>
pub fn get_resource(&self, id: &ResourceId) -> Option<&ResourceDescriptor>
Return the descriptor for a specific resource.
Sourcepub fn active_allocations(&self) -> usize
pub fn active_allocations(&self) -> usize
Return the number of active allocations.
Sourcepub fn resource_count(&self) -> usize
pub fn resource_count(&self) -> usize
Return the total number of registered resources.
Sourcepub fn can_satisfy(&self, request: &ResourceRequest) -> bool
pub fn can_satisfy(&self, request: &ResourceRequest) -> bool
Check whether a request can be satisfied without actually allocating.
Trait Implementations§
Source§impl Debug for ResourcePool
impl Debug for ResourcePool
Auto Trait Implementations§
impl Freeze for ResourcePool
impl RefUnwindSafe for ResourcePool
impl Send for ResourcePool
impl Sync for ResourcePool
impl Unpin for ResourcePool
impl UnsafeUnpin for ResourcePool
impl UnwindSafe for ResourcePool
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