Struct components_arena::Arena
source · [−]pub struct Arena<C: Component + 'static> { /* private fields */ }
Expand description
Unordered container with random access.
Implementations
sourceimpl<C: Component> Arena<C>
impl<C: Component> Arena<C>
sourcepub fn with_capacity_in(capacity: usize, alloc: C::Alloc) -> Self
pub fn with_capacity_in(capacity: usize, alloc: C::Alloc) -> 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 read-only) special container. While arena itself is unique (i.e. non-clonable) object, this special container could be cloned.
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,
<C as Component>::Alloc: RefUnwindSafe,
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
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