Arena

Struct Arena 

Source
pub struct Arena<I: ArenaIndex, T: 'static, A: Allocator = Global> { /* private fields */ }
Expand description

Unordered container with random access.

Implementations§

Source§

impl<I: ArenaIndex, T, A: Allocator> Arena<I, T, A>

Source

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

Creates an arena instance.

Source

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

Creates an arena instance with the specified initial capacity.

Source

pub const fn new_in(alloc: A) -> Self

Creates an arena instance.

Source

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

Creates an arena instance with the specified initial capacity.

Source

pub fn into_items(self) -> ArenaItems<I, T, A>

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<I, T, A>

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<I, T, A>

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 required capacity overflows maximum index value + 1.

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 required capacity overflows maximum index value + 1.

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<R>(&mut self, item: impl FnOnce(I) -> (T, R)) -> R

Place new item into the arena.

§Examples
let mut arena: Arena<usize, Data> = Arena::new();
let new_item_index = arena.insert(|index| (Data { /* ... */ }, index));
Source

pub fn remove(&mut self, index: I) -> T

Removes item with provided index.

Panics if index is not occupied.

Trait Implementations§

Source§

impl<I: Debug + ArenaIndex, T: Debug + 'static, A: Debug + Allocator> Debug for Arena<I, T, A>

Source§

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

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

impl<I: ArenaIndex, T, A> Default for Arena<I, T, A>

Source§

fn default() -> Self

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

impl<I: ArenaIndex, T, A: Allocator> Index<I> for Arena<I, T, A>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: I) -> &T

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

impl<I: ArenaIndex, T, A: Allocator> IndexMut<I> for Arena<I, T, A>

Source§

fn index_mut(&mut self, index: I) -> &mut T

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

Auto Trait Implementations§

§

impl<I, T, A> Freeze for Arena<I, T, A>
where <I as ArenaIndex>::Optional: Freeze, A: Freeze,

§

impl<I, T, A> RefUnwindSafe for Arena<I, T, A>

§

impl<I, T, A> Send for Arena<I, T, A>
where <I as ArenaIndex>::Optional: Send, A: Send, T: Send,

§

impl<I, T, A> Sync for Arena<I, T, A>
where <I as ArenaIndex>::Optional: Sync, A: Sync, T: Sync,

§

impl<I, T, A> Unpin for Arena<I, T, A>
where <I as ArenaIndex>::Optional: Unpin, A: Unpin, T: Unpin,

§

impl<I, T, A> UnwindSafe for Arena<I, T, A>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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.
§

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

Performs the conversion.