Struct components_arena::Arena

source ·
pub struct Arena<C: Component + 'static> { /* private fields */ }
Expand description

Unordered container with random access.

Implementations§

§

impl<C: Component> Arena<C>

pub const fn new() -> Self
where C::Alloc: ConstDefault,

Creates an arena instance.

pub fn with_capacity(capacity: usize) -> Self
where C::Alloc: ConstDefault,

Creates an arena instance with the specified initial capacity.

source§

impl<C: Component> Arena<C>

source

pub const fn new_in(alloc: C::Alloc) -> Self

Creates an arena instance.

source

pub fn with_capacity_in(capacity: usize, alloc: C::Alloc) -> Self

Creates an arena instance with the specified initial capacity.

source

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.

source

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.

source

pub fn items_mut(&mut self) -> &mut ArenaItems<C>

Returns mutable reference to contained items packed in a (mostly read-only) special container. While arena itself is unique (i.e. non-clonable) object, this special container could be cloned.

source

pub fn reserve(&mut self)

Reserves capacity for at least one more element. The collection may reserve more space to avoid frequent reallocations. After calling reserve, capacity will be greater than or equal to self.items().len() + 1. Does nothing if capacity is already sufficient.

§Panics

Panics if the new capacity overflows usize.

source

pub fn reserve_exact(&mut self)

Reserves the minimum capacity for exactly one more element. After calling reserve_exact, capacity will be greater than or equal to self.items().len() + 1. 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 try_reserve(&mut self) -> Result<(), TryReserveError>

Tries to reserve capacity for at least one more element. The collection may reserve more space to avoid frequent reallocations. After calling try_reserve, capacity will be greater than or equal to self.items().len() + 1. 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) -> Result<(), TryReserveError>

Tries to reserve capacity for exactly one more element. The collection may reserve more space to avoid frequent reallocations. After calling try_reserve_exact, capacity will be greater than or equal to self.items().len() + 1. 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 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));
source

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§

source§

impl<C> Debug for Arena<C>
where C: Debug + Component + 'static, C::Alloc: Debug,

source§

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

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

impl<C: Component> Default for Arena<C>
where C::Alloc: ConstDefault,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<C: Component> Index<Id<C>> for Arena<C>

§

type Output = C

The returned type after indexing.
source§

fn index(&self, id: Id<C>) -> &C

Performs the indexing (container[index]) operation. Read more
source§

impl<C: Component> IndexMut<Id<C>> for Arena<C>

source§

fn index_mut(&mut self, id: Id<C>) -> &mut C

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<C> RefUnwindSafe for Arena<C>

§

impl<C> Send for Arena<C>
where C: Send, <C as Component>::Alloc: Send,

§

impl<C> Sync for Arena<C>
where C: Sync, <C as Component>::Alloc: Sync,

§

impl<C> Unpin for Arena<C>
where C: Unpin, <C as Component>::Alloc: Unpin,

§

impl<C> UnwindSafe for Arena<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, 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.