pub struct ArenaItems<C: Component> { /* private fields */ }
Expand description

A (mostly read-only) inner container holding Arena items. While Arena itself is unique (i.e. non-clonable) object, arena ‘items’ could be cloned.

Implementations§

source§

impl<C: Component> ArenaItems<C>

source

pub const fn item_size() -> usize

An amount of memory required to hold one component.

This information can be useful for memory management fine-tuning.

source

pub const fn item_align() -> usize

An alignment of a cell, holding a component with all required metadata.

This information can be useful for memory management fine-tuning.

source

pub fn allocator(&self) -> &C::Alloc

Returns a reference to the underlying allocator.

source

pub fn capacity(&self) -> usize

Returns the number of elements the arena can hold without reallocating.

source

pub fn len(&self) -> usize

Returns the number of elements in the arena.

This function has linear worst-case complexity.

source

pub fn len_equals_to_min_capacity(&self) -> bool

Returns true iff the number of elements in the arena equals the maximum number of elements ever in the arena.

Because the arena capacity cannot be less than min_capacity, the returned false means there is space for at least one more item.

The returned value equals to self.len() == self.min_capacity(), but unlike len this function has constant complexity.

source

pub fn is_empty(&self) -> bool

Returns true if the arena contains no elements.

This function has linear worst-case complexity.

source

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);
source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn get_id_value(&self, index: usize) -> Option<(Id<C>, &C)>

Returns reference to the 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().

source

pub fn get_id_value_mut(&mut self, index: usize) -> Option<(Id<C>, &mut C)>

Returns mutable reference to the 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().

source

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().

source

pub fn get_value(&self, index: usize) -> Option<&C>

Returns reference to the item occupying index place, or None if there is no such.

§Panics

Panics if index is greater than or equal to min_capacity().

source

pub fn get_value_mut(&mut self, index: usize) -> Option<&mut C>

Returns mutable reference to the item occupying index place, or None if there is no such.

§Panics

Panics if index is greater than or equal to min_capacity().

source

pub fn ids(&self) -> ArenaItemsIds<'_, C>

Returns an iterator over all item ids.

source

pub fn values(&self) -> ArenaItemsValues<'_, C>

Returns an iterator over all items.

source

pub fn values_mut(&mut self) -> ArenaItemsValuesMut<'_, C>

Returns a mutable iterator over all items.

source

pub fn iter(&self) -> ArenaItemsIter<'_, C>

Returns an iterator over all items combined with their ids.

source

pub fn iter_mut(&mut self) -> ArenaItemsIterMut<'_, C>

Returns a mutable iterator over all items combined with their ids.

source

pub fn into_ids(self) -> ArenaItemsIntoIds<C>

Transforms the container into an iterator over all items ids.

source

pub fn into_values(self) -> ArenaItemsIntoValues<C>

Transforms the container into an iterator over all items.

Trait Implementations§

source§

impl<C: Clone + Component> Clone for ArenaItems<C>
where C::Alloc: Clone,

source§

fn clone(&self) -> ArenaItems<C>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<C: Debug + Component> Debug for ArenaItems<C>
where C::Alloc: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, C: Component> IntoIterator for &'a ArenaItems<C>

§

type Item = (Id<C>, &'a C)

The type of the elements being iterated over.
§

type IntoIter = ArenaItemsIter<'a, C>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<C: Component> IntoIterator for ArenaItems<C>

§

type Item = (Id<C>, C)

The type of the elements being iterated over.
§

type IntoIter = ArenaItemsIntoIter<C>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<C> RefUnwindSafe for ArenaItems<C>

§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.