pub struct SimpleVecPool<T> { /* private fields */ }Expand description
Simple vector pool.
The pool holds used vectors while keeping their capacities to avoid frequent memory allocation.
Implementations§
Source§impl<T> SimpleVecPool<T>
impl<T> SimpleVecPool<T>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new empty vector pool.
§Examples
use my_ecs::ds::SimpleVecPool;
let mut pool = SimpleVecPool::<i32>::new();Sourcepub fn request(&mut self) -> usize
pub fn request(&mut self) -> usize
Returns an index to a vector of the pool.
The pool prefers to reuse vector, therefore caller will receive an index to a used vector if the pool contains used vectors. In that case, the vector is completed cleared while keeping its capacity. If the pool doesn’t have any used vectors in it, a new vector is created.
§Examples
use my_ecs::ds::SimpleVecPool;
let mut pool = SimpleVecPool::<i32>::new();
let index = pool.request();
let v = pool.get(index);
v.reserve(10);
drop(v);
pool.release(index);
let index = pool.request(); // pool will return the used vector
let v = pool.get(index);
assert!(v.is_empty());
assert!(v.capacity() >= 10);Sourcepub fn release(&mut self, index: usize)
pub fn release(&mut self, index: usize)
Lets the pool know the end of use of a vector.
§Examples
use my_ecs::ds::SimpleVecPool;
let mut pool = SimpleVecPool::<i32>::new();
let index0 = pool.request();
pool.release(index0);
let index1 = pool.request(); // pool will return the used vector
assert_eq!(index0, index1);Trait Implementations§
Source§impl<T: Debug> Debug for SimpleVecPool<T>
impl<T: Debug> Debug for SimpleVecPool<T>
Source§impl<T> Default for SimpleVecPool<T>
impl<T> Default for SimpleVecPool<T>
impl<T> Resource for SimpleVecPool<T>where
T: Send + 'static,
Auto Trait Implementations§
impl<T> Freeze for SimpleVecPool<T>
impl<T> RefUnwindSafe for SimpleVecPool<T>where
T: RefUnwindSafe,
impl<T> Send for SimpleVecPool<T>where
T: Send,
impl<T> Sync for SimpleVecPool<T>where
T: Sync,
impl<T> Unpin for SimpleVecPool<T>where
T: Unpin,
impl<T> UnwindSafe for SimpleVecPool<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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more