Struct components_arena::Arena
source · [−]pub struct Arena<C: Component> { /* private fields */ }Expand description
Unordered container with random access.
Implementations
sourceimpl<C: Component> Arena<C>
impl<C: Component> Arena<C>
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an arena instance with the specified initial capacity.
sourcepub fn into_items(self) -> ArenaItems<C>
pub fn into_items(self) -> ArenaItems<C>
Returns contained items packed in a special container. While arena itself is unique (i.e. non-clonable) object, this special container could be cloned.
sourcepub fn items(&self) -> &ArenaItems<C>
pub fn items(&self) -> &ArenaItems<C>
Returns reference to contained items packed in a special container. While arena itself is unique (i.e. non-clonable) object, this special container could be cloned.
sourcepub fn items_mut(&mut self) -> &mut ArenaItems<C>
pub fn items_mut(&mut self) -> &mut ArenaItems<C>
Returns mutable reference to contained items packed in a (mostly readonly) special container. While arena itself is unique (i.e. non-clonable) object, this special container could be cloned.
sourcepub fn capacity(&self) -> usize
👎 Deprecated: use items().capacity instead
pub fn capacity(&self) -> usize
use items().capacity instead
Returns the number of elements the arena can hold without reallocating.
sourcepub fn len(&self) -> usize
👎 Deprecated: use items().len instead
pub fn len(&self) -> usize
use items().len instead
Returns the number of elements in the arena.
This function has linear worst-case complexity.
sourcepub fn is_empty(&self) -> bool
👎 Deprecated: use items().is_empty instead
pub fn is_empty(&self) -> bool
use items().is_empty instead
Returns true if the arena contains no elements.
This function has linear worst-case complexity.
sourcepub fn min_capacity(&self) -> usize
👎 Deprecated: use items().min_capacity instead
pub fn min_capacity(&self) -> usize
use items().min_capacity instead
Returns the maximum number of elements ever in the arena.
The arena capacity cannot be less than min_capacity.
Arena min_capacity never decreases.
sourcepub fn reserve(&mut self, additional: usize)
👎 Deprecated: use items_mut().reserve instead
pub fn reserve(&mut self, additional: usize)
use items_mut().reserve instead
Reserves capacity for at least additional more elements.
The collection may reserve more space to avoid frequent reallocations.
After calling reserve, capacity will be greater than or equal to
self.min_capacity() + additional. Does nothing if capacity is already sufficient.
Panics
Panics if the new capacity overflows usize.
sourcepub fn reserve_exact(&mut self, additional: usize)
👎 Deprecated: use items_mut().reserve_exact instead
pub fn reserve_exact(&mut self, additional: usize)
use items_mut().reserve_exact instead
Reserves the minimum capacity for exactly additional more elements.
After calling reserve_exact, capacity will be greater than or equal to
self.min_capacity() + additional. Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it requests.
Therefore, capacity can not be relied upon to be precisely minimal.
Prefer reserve if future insertions are expected.
Panics
Panics if the new capacity overflows usize.
sourcepub fn shrink_to(&mut self, min_capacity: usize)
👎 Deprecated: use items_mut().shrink_to instead
pub fn shrink_to(&mut self, min_capacity: usize)
use items_mut().shrink_to instead
Shrinks the capacity of the arena with a lower bound.
The capacity will remain at least as large as both the min_capacity
and the supplied value.
sourcepub fn shrink_to_fit(&mut self)
👎 Deprecated: use items_mut().shrink_to_fit instead
pub fn shrink_to_fit(&mut self)
use items_mut().shrink_to_fit instead
Shrinks the capacity of the vector as much as possible.
It will drop down as close as possible to the min_capacity
but the allocator may still inform the arena that there is space for a few more elements.
sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
👎 Deprecated: use items_mut().try_reserve instead
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
use items_mut().try_reserve instead
Tries to reserve capacity for at least additional more elements.
The collection may reserve more space to avoid frequent reallocations.
After calling try_reserve, capacity will be greater than or equal
to self.min_capacity() + additional. Does nothing if capacity is already sufficient.
Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
sourcepub fn try_reserve_exact(
&mut self,
additional: usize
) -> Result<(), TryReserveError>
👎 Deprecated: use items_mut().try_reserve_exact instead
pub fn try_reserve_exact(
&mut self,
additional: usize
) -> Result<(), TryReserveError>
use items_mut().try_reserve_exact instead
Tries to reserve capacity for exactly additional more elements.
The collection may reserve more space to avoid frequent reallocations.
After calling try_reserve_exact, capacity will be greater than or equal
to self.min_capacity() + additional. Does nothing if capacity is already sufficient.
Note that the allocator may give the collection more space than it requests.
Therefore, capacity can not be relied upon to be precisely minimal.
Prefer try_reserve if future insertions are expected.
Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
sourcepub fn insert<T>(&mut self, component: impl FnOnce(Id<C>) -> (C, T)) -> T
pub fn insert<T>(&mut self, component: impl FnOnce(Id<C>) -> (C, T)) -> T
Place new component into the arena.
Examples
let mut arena = Arena::new();
let new_component_id = arena.insert(|id| (MyComponent { /* ... */ }, id));sourcepub fn remove(&mut self, id: Id<C>) -> C
pub fn remove(&mut self, id: Id<C>) -> C
Removes component with provided id.
The arena tries to detect invalid provided id (i. e. foreign, or previously dropped), and panics if such detection hits. But it is important to pay respect to the fact there is small probability that invalid id will not be intercepted.
Trait Implementations
Auto Trait Implementations
impl<C> RefUnwindSafe for Arena<C> where
C: RefUnwindSafe,
impl<C> Send for Arena<C> where
C: Send,
impl<C> Sync for Arena<C> where
C: Sync,
impl<C> Unpin for Arena<C> where
C: Unpin,
impl<C> UnwindSafe for Arena<C> where
C: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more