[−][src]Struct id_arena::Arena
An arena of objects of type T
.
use id_arena::Arena; let mut arena = Arena::<&str>::new(); let a = arena.alloc("Albert"); assert_eq!(arena[a], "Albert"); arena[a] = "Alice"; assert_eq!(arena[a], "Alice");
Methods
impl<T, A> Arena<T, A> where
A: ArenaBehavior,
[src]
impl<T, A> Arena<T, A> where
A: ArenaBehavior,
pub fn par_iter(&self) -> ParIter<T, A> where | [src] |
Returns an iterator of shared references which can be used to iterate
over this arena in parallel with the rayon
crate.
Features
This API requires the rayon
feature of this crate to be enabled.
pub fn par_iter_mut(&mut self) -> ParIterMut<T, A> where | [src] |
Returns an iterator of mutable references which can be used to iterate
over this arena in parallel with the rayon
crate.
Features
This API requires the rayon
feature of this crate to be enabled.
impl<T, A> Arena<T, A> where
A: ArenaBehavior,
[src]
impl<T, A> Arena<T, A> where
A: ArenaBehavior,
pub fn new() -> Arena<T, A> | [src] |
Construct a new, empty Arena
.
use id_arena::Arena; let mut arena = Arena::<usize>::new(); arena.alloc(42);
pub fn with_capacity(capacity: usize) -> Arena<T, A> | [src] |
Construct a new, empty Arena
with capacity for the given number of
elements.
use id_arena::Arena; let mut arena = Arena::<usize>::with_capacity(100); for x in 0..100 { arena.alloc(x * x); }
pub fn alloc(&mut self, item: T) -> A::Id | [src] |
Allocate item
within this arena and return its id.
use id_arena::Arena; let mut arena = Arena::<usize>::new(); let _id = arena.alloc(42);
Panics
Panics if the number of elements in the arena overflows a usize
or
Id
's index storage representation.
pub fn next_id(&mut self) -> A::Id | [src] |
Get the id that will be used for the next item allocated into this arena.
This is useful for structures that want to store their id as their own member.
use id_arena::{Arena, Id}; struct Cat { id: Id<Cat>, } let mut arena = Arena::<Cat>::new(); let id = arena.next_id(); assert!(arena.get(id).is_none()); let id2 = arena.alloc(Cat { id }); assert_eq!(id, id2); assert!(arena.get(id).is_some());
pub fn get(&self, id: A::Id) -> Option<&T> | [src] |
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
.
use id_arena::Arena; let mut arena = Arena::<usize>::new(); let id = arena.alloc(42); assert!(arena.get(id).is_some()); let other_arena = Arena::<usize>::new(); assert!(other_arena.get(id).is_none());
pub fn get_mut(&mut self, id: A::Id) -> Option<&mut T> | [src] |
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
.
use id_arena::Arena; let mut arena = Arena::<usize>::new(); let id = arena.alloc(42); assert!(arena.get_mut(id).is_some()); let mut other_arena = Arena::<usize>::new(); assert!(other_arena.get_mut(id).is_none());
ⓘImportant traits for Iter<'a, T, A>
pub fn iter(&self) -> Iter<T, A> | [src] |
Iterate over this arena's items and their ids.
use id_arena::Arena; let mut arena = Arena::<&str>::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); }
ⓘImportant traits for IterMut<'a, T, A>
pub fn iter_mut(&mut self) -> IterMut<T, A> | [src] |
Iterate over this arena's items and their ids, allowing mutation of each item.
pub fn len(&self) -> usize | [src] |
Get the number of objects allocated in this arena.
use id_arena::Arena; let mut arena = Arena::<&str>::new(); arena.alloc("hello"); arena.alloc("hi"); assert_eq!(arena.len(), 2);
Trait Implementations
impl<T: Debug, A: Debug> Debug for Arena<T, A>
[src]
impl<T: Debug, A: Debug> Debug for Arena<T, A>
impl<T: PartialEq, A: PartialEq> PartialEq<Arena<T, A>> for Arena<T, A>
[src]
impl<T: PartialEq, A: PartialEq> PartialEq<Arena<T, A>> for Arena<T, A>
impl<T: Eq, A: Eq> Eq for Arena<T, A>
[src]
impl<T: Eq, A: Eq> Eq for Arena<T, A>
impl<T, A> Index<<A as ArenaBehavior>::Id> for Arena<T, A> where
A: ArenaBehavior,
[src]
impl<T, A> Index<<A as ArenaBehavior>::Id> for Arena<T, A> where
A: ArenaBehavior,
impl<T, A> IndexMut<<A as ArenaBehavior>::Id> for Arena<T, A> where
A: ArenaBehavior,
[src]
impl<T, A> IndexMut<<A as ArenaBehavior>::Id> for Arena<T, A> where
A: ArenaBehavior,
impl<'a, T, A> IntoIterator for &'a Arena<T, A> where
A: ArenaBehavior,
[src]
impl<'a, T, A> IntoIterator for &'a Arena<T, A> where
A: ArenaBehavior,
type Item = (A::Id, &'a T)
The type of the elements being iterated over.
type IntoIter = Iter<'a, T, A>
Which kind of iterator are we turning this into?
ⓘImportant traits for Iter<'a, T, A>
fn into_iter(self) -> Iter<'a, T, A> | [src] |
impl<'a, T, A> IntoIterator for &'a mut Arena<T, A> where
A: ArenaBehavior,
[src]
impl<'a, T, A> IntoIterator for &'a mut Arena<T, A> where
A: ArenaBehavior,
type Item = (A::Id, &'a mut T)
The type of the elements being iterated over.
type IntoIter = IterMut<'a, T, A>
Which kind of iterator are we turning this into?
ⓘImportant traits for IterMut<'a, T, A>
fn into_iter(self) -> IterMut<'a, T, A> | [src] |
impl<T, A> IntoIterator for Arena<T, A> where
A: ArenaBehavior,
[src]
impl<T, A> IntoIterator for Arena<T, A> where
A: ArenaBehavior,
type Item = (A::Id, T)
The type of the elements being iterated over.
type IntoIter = IntoIter<T, A>
Which kind of iterator are we turning this into?
ⓘImportant traits for IntoIter<T, A>
fn into_iter(self) -> IntoIter<T, A> | [src] |
impl<T: Clone, A: Clone> Clone for Arena<T, A>
[src]
impl<T: Clone, A: Clone> Clone for Arena<T, A>
fn clone(&self) -> Arena<T, A> | [src] |
fn clone_from(&mut self, source: &Self) | 1.0.0 [src] |
Performs copy-assignment from source
. Read more
impl<T, A> Default for Arena<T, A> where
A: ArenaBehavior,
[src]
impl<T, A> Default for Arena<T, A> where
A: ArenaBehavior,
impl<'data, T, A> IntoParallelIterator for &'data Arena<T, A> where
A: ArenaBehavior,
A::Id: Send,
T: Sync,
[src]
impl<'data, T, A> IntoParallelIterator for &'data Arena<T, A> where
A: ArenaBehavior,
A::Id: Send,
T: Sync,
type Item = (A::Id, &'data T)
The type of item that the parallel iterator will produce.
type Iter = ParIter<'data, T, A>
The parallel iterator type that will be created.
fn into_par_iter(self) -> Self::Iter | [src] |
impl<'data, T, A> IntoParallelIterator for &'data mut Arena<T, A> where
A: ArenaBehavior,
A::Id: Send,
T: Send + Sync,
[src]
impl<'data, T, A> IntoParallelIterator for &'data mut Arena<T, A> where
A: ArenaBehavior,
A::Id: Send,
T: Send + Sync,
type Item = (A::Id, &'data mut T)
The type of item that the parallel iterator will produce.
type Iter = ParIterMut<'data, T, A>
The parallel iterator type that will be created.
fn into_par_iter(self) -> Self::Iter | [src] |
impl<T, A> IntoParallelIterator for Arena<T, A> where
A: ArenaBehavior,
A::Id: Send,
T: Send,
[src]
impl<T, A> IntoParallelIterator for Arena<T, A> where
A: ArenaBehavior,
A::Id: Send,
T: Send,
Auto Trait Implementations
Blanket Implementations
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> | [src] |
impl<T> From for T
[src]
impl<T> From for T
impl<I> IntoIterator for I where
I: Iterator,
[src]
impl<I> IntoIterator for I where
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I | [src] |
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error> | [src] |
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T | [src] |
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId | [src] |
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
impl<'data, I> IntoParallelRefMutIterator for I where
I: 'data + ?Sized,
&'data mut I: IntoParallelIterator,
[src]
impl<'data, I> IntoParallelRefMutIterator for I where
I: 'data + ?Sized,
&'data mut I: IntoParallelIterator,
type Iter = <&'data mut I as IntoParallelIterator>::Iter
The type of iterator that will be created.
type Item = <&'data mut I as IntoParallelIterator>::Item
The type of item that will be produced; this is typically an &'data mut T
reference. Read more
fn par_iter_mut( | [src] |
impl<'data, I> IntoParallelRefIterator for I where
I: 'data + ?Sized,
&'data I: IntoParallelIterator,
[src]
impl<'data, I> IntoParallelRefIterator for I where
I: 'data + ?Sized,
&'data I: IntoParallelIterator,
type Iter = <&'data I as IntoParallelIterator>::Iter
The type of the parallel iterator that will be returned.
type Item = <&'data I as IntoParallelIterator>::Item
The type of item that the parallel iterator will produce. This will typically be an &'data T
reference type. Read more
fn par_iter(&'data self) -> <I as IntoParallelRefIterator<'data>>::Iter | [src] |
impl<T> IntoParallelIterator for T where
T: ParallelIterator,
[src]
impl<T> IntoParallelIterator for T where
T: ParallelIterator,
type Iter = T
The parallel iterator type that will be created.
type Item = <T as ParallelIterator>::Item
The type of item that the parallel iterator will produce.
fn into_par_iter(self) -> T | [src] |