Struct la_arena::Arena

source ·
pub struct Arena<T> { /* private fields */ }
Expand description

Yet another index-based arena.

Implementations§

source§

impl<T> Arena<T>

source

pub const fn new() -> Arena<T>

Creates a new empty arena.

let arena: la_arena::Arena<i32> = la_arena::Arena::new();
assert!(arena.is_empty());
source

pub fn with_capacity(capacity: usize) -> Arena<T>

Create a new empty arena with specific capacity.

let arena: la_arena::Arena<i32> = la_arena::Arena::with_capacity(42);
assert!(arena.is_empty());
source

pub fn clear(&mut self)

Empties the arena, removing all contained values.

let mut arena = la_arena::Arena::new();

arena.alloc(1);
arena.alloc(2);
arena.alloc(3);
assert_eq!(arena.len(), 3);

arena.clear();
assert!(arena.is_empty());
source

pub fn len(&self) -> usize

Returns the length of the arena.

let mut arena = la_arena::Arena::new();
assert_eq!(arena.len(), 0);

arena.alloc("foo");
assert_eq!(arena.len(), 1);

arena.alloc("bar");
assert_eq!(arena.len(), 2);

arena.alloc("baz");
assert_eq!(arena.len(), 3);
source

pub fn is_empty(&self) -> bool

Returns whether the arena contains no elements.

let mut arena = la_arena::Arena::new();
assert!(arena.is_empty());

arena.alloc(0.5);
assert!(!arena.is_empty());
source

pub fn alloc(&mut self, value: T) -> Idx<T>

Allocates a new value on the arena, returning the value’s index.

let mut arena = la_arena::Arena::new();
let idx = arena.alloc(50);

assert_eq!(arena[idx], 50);
source

pub fn alloc_many<II: IntoIterator<Item = T>>( &mut self, iter: II ) -> IdxRange<T>

Densely allocates multiple values, returning the values’ index range.

let mut arena = la_arena::Arena::new();
let range = arena.alloc_many(0..4);

assert_eq!(arena[range], [0, 1, 2, 3]);
source

pub fn iter( &self ) -> impl Iterator<Item = (Idx<T>, &T)> + ExactSizeIterator + DoubleEndedIterator + Clone

Returns an iterator over the arena’s elements.

let mut arena = la_arena::Arena::new();
let idx1 = arena.alloc(20);
let idx2 = arena.alloc(40);
let idx3 = arena.alloc(60);

let mut iterator = arena.iter();
assert_eq!(iterator.next(), Some((idx1, &20)));
assert_eq!(iterator.next(), Some((idx2, &40)));
assert_eq!(iterator.next(), Some((idx3, &60)));
source

pub fn iter_mut( &mut self ) -> impl Iterator<Item = (Idx<T>, &mut T)> + ExactSizeIterator + DoubleEndedIterator

Returns an iterator over the arena’s mutable elements.

let mut arena = la_arena::Arena::new();
let idx1 = arena.alloc(20);

assert_eq!(arena[idx1], 20);

let mut iterator = arena.iter_mut();
*iterator.next().unwrap().1 = 10;
drop(iterator);

assert_eq!(arena[idx1], 10);
source

pub fn values( &self ) -> impl Iterator<Item = &T> + ExactSizeIterator + DoubleEndedIterator

Returns an iterator over the arena’s values.

let mut arena = la_arena::Arena::new();
let idx1 = arena.alloc(20);
let idx2 = arena.alloc(40);
let idx3 = arena.alloc(60);

let mut iterator = arena.values();
assert_eq!(iterator.next(), Some(&20));
assert_eq!(iterator.next(), Some(&40));
assert_eq!(iterator.next(), Some(&60));
source

pub fn values_mut( &mut self ) -> impl Iterator<Item = &mut T> + ExactSizeIterator + DoubleEndedIterator

Returns an iterator over the arena’s mutable values.

let mut arena = la_arena::Arena::new();
let idx1 = arena.alloc(20);

assert_eq!(arena[idx1], 20);

let mut iterator = arena.values_mut();
*iterator.next().unwrap() = 10;
drop(iterator);

assert_eq!(arena[idx1], 10);
source

pub fn shrink_to_fit(&mut self)

Reallocates the arena to make it take up as little space as possible.

Trait Implementations§

source§

impl<T> AsMut<[T]> for Arena<T>

source§

fn as_mut(&mut self) -> &mut [T]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<T: Clone> Clone for Arena<T>

source§

fn clone(&self) -> Arena<T>

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<T: Debug> Debug for Arena<T>

source§

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

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

impl<T> Default for Arena<T>

source§

fn default() -> Arena<T>

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

impl<T> Extend<T> for Arena<T>

source§

fn extend<II: IntoIterator<Item = T>>(&mut self, iter: II)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T> FromIterator<T> for Arena<T>

source§

fn from_iter<I>(iter: I) -> Selfwhere I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
source§

impl<T: Hash> Hash for Arena<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T> Index<Idx<T>> for Arena<T>

§

type Output = T

The returned type after indexing.
source§

fn index(&self, idx: Idx<T>) -> &T

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

impl<T> Index<IdxRange<T>> for Arena<T>

§

type Output = [T]

The returned type after indexing.
source§

fn index(&self, range: IdxRange<T>) -> &[T]

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

impl<T> IndexMut<Idx<T>> for Arena<T>

source§

fn index_mut(&mut self, idx: Idx<T>) -> &mut T

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

impl<T> IntoIterator for Arena<T>

§

type Item = (Idx<T>, T)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

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<T: PartialEq> PartialEq<Arena<T>> for Arena<T>

source§

fn eq(&self, other: &Arena<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Eq> Eq for Arena<T>

source§

impl<T> StructuralEq for Arena<T>

source§

impl<T> StructuralPartialEq for Arena<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Arena<T>where T: RefUnwindSafe,

§

impl<T> Send for Arena<T>where T: Send,

§

impl<T> Sync for Arena<T>where T: Sync,

§

impl<T> Unpin for Arena<T>where T: Unpin,

§

impl<T> UnwindSafe for Arena<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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.