[−][src]Struct souper_ir::ast::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");
Implementations
impl<T, A> Arena<T, A> where
A: ArenaBehavior,
[src]
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 as ArenaBehavior>::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 alloc_with_id(
&mut self,
f: impl FnOnce(<A as ArenaBehavior>::Id) -> T
) -> <A as ArenaBehavior>::Id
[src]
&mut self,
f: impl FnOnce(<A as ArenaBehavior>::Id) -> T
) -> <A as ArenaBehavior>::Id
Allocate an item with the id that it will be assigned.
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 kitty = arena.alloc_with_id(|id| Cat { id }); assert_eq!(arena[kitty].id, kitty);
pub fn next_id(&self) -> <A as ArenaBehavior>::Id
[src]
Get the id that will be used for the next item allocated into this arena.
If you are allocating a struct
that wants to have its id as a member
of itself, prefer the less error-prone Arena::alloc_with_id
method.
pub fn get(&self, id: <A as ArenaBehavior>::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 as ArenaBehavior>::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());
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); }
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, A> Clone for Arena<T, A> where
A: Clone,
T: Clone,
[src]
A: Clone,
T: Clone,
impl<T, A> Debug for Arena<T, A> where
A: Debug,
T: Debug,
[src]
A: Debug,
T: Debug,
impl<T, A> Default for Arena<T, A> where
A: ArenaBehavior,
[src]
A: ArenaBehavior,
impl<T, A> Eq for Arena<T, A> where
A: Eq,
T: Eq,
[src]
A: Eq,
T: Eq,
impl<T, A> Index<<A as ArenaBehavior>::Id> for Arena<T, A> where
A: ArenaBehavior,
[src]
A: ArenaBehavior,
type Output = T
The returned type after indexing.
fn index(&self, id: <A as ArenaBehavior>::Id) -> &T
[src]
impl<T, A> IndexMut<<A as ArenaBehavior>::Id> for Arena<T, A> where
A: ArenaBehavior,
[src]
A: ArenaBehavior,
fn index_mut(&mut self, id: <A as ArenaBehavior>::Id) -> &mut T
[src]
impl<T, A> IntoIterator for Arena<T, A> where
A: ArenaBehavior,
[src]
A: ArenaBehavior,
type Item = (<A as ArenaBehavior>::Id, T)
The type of the elements being iterated over.
type IntoIter = IntoIter<T, A>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IntoIter<T, A>
[src]
impl<'a, T, A> IntoIterator for &'a Arena<T, A> where
A: ArenaBehavior,
[src]
A: ArenaBehavior,
type Item = (<A as ArenaBehavior>::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?
fn into_iter(self) -> Iter<'a, T, A>
[src]
impl<'a, T, A> IntoIterator for &'a mut Arena<T, A> where
A: ArenaBehavior,
[src]
A: ArenaBehavior,
type Item = (<A as ArenaBehavior>::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?
fn into_iter(self) -> IterMut<'a, T, A>
[src]
impl<T, A> PartialEq<Arena<T, A>> for Arena<T, A> where
A: PartialEq<A>,
T: PartialEq<T>,
[src]
A: PartialEq<A>,
T: PartialEq<T>,
impl<T, A> StructuralEq for Arena<T, A>
[src]
impl<T, A> StructuralPartialEq for Arena<T, A>
[src]
Auto Trait Implementations
impl<T, A> RefUnwindSafe for Arena<T, A> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, A> Send for Arena<T, A> where
T: Send,
T: Send,
impl<T, A> Sync for Arena<T, A> where
T: Sync,
T: Sync,
impl<T, A> Unpin for Arena<T, A> where
T: Unpin,
T: Unpin,
impl<T, A> UnwindSafe for Arena<T, A> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
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>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,