Struct components_arena::ArenaItems
source · [−]pub struct ArenaItems<C: Component> { /* private fields */ }
Expand description
Implementations
sourceimpl<C: Component> ArenaItems<C>
impl<C: Component> ArenaItems<C>
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the arena can hold without reallocating.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the arena.
This function has linear worst-case complexity.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the arena contains no elements.
This function has linear worst-case complexity.
sourcepub fn min_capacity(&self) -> usize
pub fn min_capacity(&self) -> usize
Returns the maximum number of elements ever in the arena.
The arena capacity cannot be less than min_capacity
.
Arena min_capacity
never decreases.
Examples
let mut arena = Arena::new();
assert_eq!(arena.items().min_capacity(), 0);
let id_1 = arena.insert(|id| (MyComponent { /* ... */ }, id));
assert_eq!(arena.items().min_capacity(), 1);
let id_2 = arena.insert(|id| (MyComponent { /* ... */ }, id));
assert_eq!(arena.items().min_capacity(), 2);
arena.remove(id_1);
assert_eq!(arena.items().min_capacity(), 2);
let id_3 = arena.insert(|id| (MyComponent { /* ... */ }, id));
assert_eq!(arena.items().min_capacity(), 2);
let id_4 = arena.insert(|id| (MyComponent { /* ... */ }, id));
assert_eq!(arena.items().min_capacity(), 3);
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
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)
pub fn reserve_exact(&mut self, additional: usize)
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)
pub fn shrink_to(&mut self, min_capacity: usize)
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)
pub fn shrink_to_fit(&mut self)
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>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
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>
pub fn try_reserve_exact(
&mut self,
additional: usize
) -> Result<(), TryReserveError>
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 get_id_value(&self, index: usize) -> Option<(Id<C>, &C)>
pub fn get_id_value(&self, index: usize) -> Option<(Id<C>, &C)>
Returns item occupying index
place with its Id
, or None
if there is no such.
Panics
Panics if index
is greater than or equal to min_capacity()
.
sourcepub fn get_id(&self, index: usize) -> Option<Id<C>>
pub fn get_id(&self, index: usize) -> Option<Id<C>>
Returns Id
of item occupying index
place, or None
if there is no such.
Panics
Panics if index
is greater than or equal to min_capacity()
.
sourcepub fn get_value(&self, index: usize) -> Option<&C>
pub fn get_value(&self, index: usize) -> Option<&C>
Returns item occupying index
place, or None
if there is no such.
Panics
Panics if index
is greater than or equal to min_capacity()
.
sourcepub fn ids(&self) -> ArenaItemsIds<'_, C>ⓘNotable traits for ArenaItemsIds<'a, C>impl<'a, C: Component> Iterator for ArenaItemsIds<'a, C> type Item = Id<C>;
pub fn ids(&self) -> ArenaItemsIds<'_, C>ⓘNotable traits for ArenaItemsIds<'a, C>impl<'a, C: Component> Iterator for ArenaItemsIds<'a, C> type Item = Id<C>;
Returns an iterator over all item ids.
sourcepub fn values(&self) -> ArenaItemsValues<'_, C>ⓘNotable traits for ArenaItemsValues<'a, C>impl<'a, C: Component> Iterator for ArenaItemsValues<'a, C> type Item = &'a C;
pub fn values(&self) -> ArenaItemsValues<'_, C>ⓘNotable traits for ArenaItemsValues<'a, C>impl<'a, C: Component> Iterator for ArenaItemsValues<'a, C> type Item = &'a C;
Returns an iterator over all items.
sourcepub fn iter(&self) -> ArenaItemsIter<'_, C>ⓘNotable traits for ArenaItemsIter<'a, C>impl<'a, C: Component> Iterator for ArenaItemsIter<'a, C> type Item = (Id<C>, &'a C);
pub fn iter(&self) -> ArenaItemsIter<'_, C>ⓘNotable traits for ArenaItemsIter<'a, C>impl<'a, C: Component> Iterator for ArenaItemsIter<'a, C> type Item = (Id<C>, &'a C);
Returns an iterator over all items combined with their ids.
sourcepub fn into_ids(self) -> ArenaItemsIntoIds<C>ⓘNotable traits for ArenaItemsIntoIds<C>impl<C: Component> Iterator for ArenaItemsIntoIds<C> type Item = Id<C>;
pub fn into_ids(self) -> ArenaItemsIntoIds<C>ⓘNotable traits for ArenaItemsIntoIds<C>impl<C: Component> Iterator for ArenaItemsIntoIds<C> type Item = Id<C>;
Transforms the container into an iterator over all items ids.
sourcepub fn into_values(self) -> ArenaItemsIntoValues<C>ⓘNotable traits for ArenaItemsIntoValues<C>impl<C: Component> Iterator for ArenaItemsIntoValues<C> type Item = C;
pub fn into_values(self) -> ArenaItemsIntoValues<C>ⓘNotable traits for ArenaItemsIntoValues<C>impl<C: Component> Iterator for ArenaItemsIntoValues<C> type Item = C;
Transforms the container into an iterator over all items.
Trait Implementations
sourceimpl<C: Clone + Component> Clone for ArenaItems<C> where
C::Alloc: Clone,
impl<C: Clone + Component> Clone for ArenaItems<C> where
C::Alloc: Clone,
sourcefn clone(&self) -> ArenaItems<C>
fn clone(&self) -> ArenaItems<C>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<C: Component> IntoIterator for ArenaItems<C>
impl<C: Component> IntoIterator for ArenaItems<C>
sourceimpl<'a, C: Component> IntoIterator for &'a ArenaItems<C>
impl<'a, C: Component> IntoIterator for &'a ArenaItems<C>
Auto Trait Implementations
impl<C> RefUnwindSafe for ArenaItems<C> where
C: RefUnwindSafe,
<C as Component>::Alloc: RefUnwindSafe,
impl<C> Send for ArenaItems<C> where
C: Send,
<C as Component>::Alloc: Send,
impl<C> Sync for ArenaItems<C> where
C: Sync,
<C as Component>::Alloc: Sync,
impl<C> Unpin for ArenaItems<C> where
C: Unpin,
<C as Component>::Alloc: Unpin,
impl<C> UnwindSafe for ArenaItems<C> where
C: UnwindSafe,
<C as Component>::Alloc: 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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more