[][src]Struct components_arena::Arena

pub struct Arena<C: Component> { /* fields omitted */ }

Unordered container with random access.

Implementations

impl<C: Component> Arena<C>[src]

pub fn new(class: &mut ComponentClassToken<C::Class>) -> Self[src]

Creates an arena instance.

pub fn with_capacity(
    capacity: usize,
    class: &mut ComponentClassToken<C::Class>
) -> Self
[src]

Creates an arena instance with the specified initial capacity.

pub fn capacity(&self) -> usize[src]

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

pub fn len(&self) -> usize[src]

Returns the number of elements in the arena.

This function has linear worst-case complexity.

pub fn is_empty(&self) -> bool[src]

Returns true if the arena contains no elements.

This function has linear worst-case complexity.

pub fn min_capacity(&self) -> usize[src]

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(&mut MY_COMPONENT.lock().unwrap());
assert_eq!(arena.min_capacity(), 0);
let id_1 = arena.insert(|id| (MyComponent { /* ... */ }, id));
assert_eq!(arena.min_capacity(), 1);
let id_2 = arena.insert(|id| (MyComponent { /* ... */ }, id));
assert_eq!(arena.min_capacity(), 2);
arena.remove(id_1);
assert_eq!(arena.min_capacity(), 2);
let id_3 = arena.insert(|id| (MyComponent { /* ... */ }, id));
assert_eq!(arena.min_capacity(), 2);
let id_4 = arena.insert(|id| (MyComponent { /* ... */ }, id));
assert_eq!(arena.min_capacity(), 3);

pub fn reserve(&mut self, additional: usize)[src]

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.

pub fn reserve_exact(&mut self, additional: usize)[src]

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.

pub fn shrink_to(&mut self, min_capacity: usize)[src]

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.

pub fn shrink_to_fit(&mut self)[src]

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.

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>[src]

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.

pub fn try_reserve_exact(
    &mut self,
    additional: usize
) -> Result<(), TryReserveError>
[src]

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.

pub fn insert<T>(&mut self, component: impl FnOnce(Id<C>) -> (C, T)) -> T[src]

Place new component into the arena.

Examples

let mut arena = Arena::new(&mut MY_COMPONENT.lock().unwrap());
let new_component_id = arena.insert(|id| (MyComponent { /* ... */ }, id));

pub fn remove(&mut self, id: Id<C>) -> C[src]

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

impl<C: Debug + Component> Debug for Arena<C>[src]

impl<C: Component> Index<Id<C>> for Arena<C>[src]

type Output = C

The returned type after indexing.

impl<C: Component> IndexMut<Id<C>> for Arena<C>[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,