pub struct Allocator<T: Clone> {
pub connection_pool: Vec<Option<T>>,
pub free_connections: VecDeque<usize>,
pub allocated_connections: VecDeque<usize>,
}
Expand description
An allocator for mapping an index to a value T.
§Fields
connection_pool
- A vector of optional values of type T that can be allocated and deallocated, and accessed by index.free_connections
- A queue of indices that have been deallocated and are available for allocation.allocated_connections
- A queue of indices that have been allocated and are currently in use.
Fields§
§connection_pool: Vec<Option<T>>
§free_connections: VecDeque<usize>
§allocated_connections: VecDeque<usize>
Implementations§
source§impl<T: Clone> Allocator<T>
impl<T: Clone> Allocator<T>
sourcepub fn yield_next_allocated_index(&mut self) -> Option<usize>
pub fn yield_next_allocated_index(&mut self) -> Option<usize>
Yields the next allocated index in the connection pool.
§Returns
The next allocated index in the connection pool. (empty if thee is no allocated connection available)
sourcepub fn extract_connection(
&self,
index: usize,
) -> Result<(T, usize), NanoServiceError>
pub fn extract_connection( &self, index: usize, ) -> Result<(T, usize), NanoServiceError>
sourcepub fn deallocate(&mut self, index: usize) -> Result<T, NanoServiceError>
pub fn deallocate(&mut self, index: usize) -> Result<T, NanoServiceError>
Deallocates a connection in the connection pool.
§Arguments
index
- The index of the connection to be deallocated.
sourcepub fn yield_connections(&self) -> Vec<T>
pub fn yield_connections(&self) -> Vec<T>
Yields all the connections in the connection pool.
§Returns
A vector of all the connections in the connection pool.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Allocator<T>
impl<T> RefUnwindSafe for Allocator<T>where
T: RefUnwindSafe,
impl<T> Send for Allocator<T>where
T: Send,
impl<T> Sync for Allocator<T>where
T: Sync,
impl<T> Unpin for Allocator<T>where
T: Unpin,
impl<T> UnwindSafe for Allocator<T>where
T: UnwindSafe,
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