pub struct ComponentArray<T> { /* private fields */ }
Expand description
ComponentArray is alternative to storing components in hashmap. Its considerable faster to access elements of course there is a cost for that. You cannot choose your own ids ComponentArray generates them for you. Model is surprisingly simple but powerful. To use this properly you have to ALWAYS remove no longer needed component unless you like memory leaks.
Implementations§
Source§impl<T> ComponentArray<T>
impl<T> ComponentArray<T>
pub fn new() -> Self
Sourcepub fn insert(&mut self, component: T) -> usize
pub fn insert(&mut self, component: T) -> usize
insert takes an value and returns id to is. (Its not really id but you can use it like it)
pub fn len(&self) -> usize
Sourcepub fn remove(&mut self, id: usize) -> T
pub fn remove(&mut self, id: usize) -> T
remove is important. Always remove the objects so memory can be reused for another one.
pub fn remove_if_present(&mut self, id: usize) -> Option<T>
Sourcepub unsafe fn get(&mut self, id: usize) -> Option<T>
pub unsafe fn get(&mut self, id: usize) -> Option<T>
get is not equivalent fo remove, if you do not put back what you taken you are leaking memory because ComponentArray still considers it occupied. Function is here to solve situations when you need mutable and immutable asses to array elements at the same time
Auto Trait Implementations§
impl<T> Freeze for ComponentArray<T>
impl<T> RefUnwindSafe for ComponentArray<T>where
T: RefUnwindSafe,
impl<T> Send for ComponentArray<T>where
T: Send,
impl<T> Sync for ComponentArray<T>where
T: Sync,
impl<T> Unpin for ComponentArray<T>where
T: Unpin,
impl<T> UnwindSafe for ComponentArray<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
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>
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>
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