Struct id_arena::Arena

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

An arena of objects of type T.

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

let a = arena.alloc("Albert");
assert_eq!(arena[a], "Albert");

arena[a] = "Alice";
assert_eq!(arena[a], "Alice");

Implementations

Construct a new, empty Arena.

let mut arena = id_arena::Arena::new();
arena.alloc(42);

Allocate item within this arena and return its id.

let mut arena = id_arena::Arena::new();
arena.alloc(42);

Get a shared reference to the object associated with the given id if it exists.

If there is no object associated with id (for example, it might reference an object allocated within a different arena) then return None.

let mut arena = id_arena::Arena::new();
let id = arena.alloc(42);
assert!(arena.get(id).is_some());

let other_arena = id_arena::Arena::new();
assert!(other_arena.get(id).is_none());

Get an exclusive reference to the object associated with the given id if it exists.

If there is no object associated with id (for example, it might reference an object allocated within a different arena) then return None.

let mut arena = id_arena::Arena::new();
let id = arena.alloc(42);
assert!(arena.get_mut(id).is_some());

let mut other_arena = id_arena::Arena::new();
assert!(other_arena.get_mut(id).is_none());

Iterate over this arena’s items and their ids.

let mut arena = id_arena::Arena::new();
arena.alloc("hello");
arena.alloc("hi");
arena.alloc("yo");

for (id, s) in arena.iter() {
    assert_eq!(arena.get(id).unwrap(), s);
    println!("{:?} -> {}", id, s);
}

Get the number of objects allocated in this arena.

let mut arena = id_arena::Arena::new();
arena.alloc("hello");
arena.alloc("hi");

assert_eq!(arena.len(), 2);

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more

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