Struct ra_ap_la_arena::Arena

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

Yet another index-based arena.

Implementations§

Creates a new empty arena.

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

Create a new empty arena with specific capacity.

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

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());

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);

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());

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);

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)));

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);

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));

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);

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

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Creates a value from an iterator. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.