Struct dcc_lsystem::arena::Arena [−][src]
pub struct Arena<T> { /* fields omitted */ }
Expand description
A simple arena wrapping around a Vec
Examples
use dcc_lsystem::Arena; let mut arena = Arena::new(); let u = arena.push(1); let v = arena.push(2); assert_eq!(arena.len(), 2); assert_eq!(arena.get(u), Some(&1));
Implementations
impl<T> Arena<T>
[src]
impl<T> Arena<T>
[src]pub fn new() -> Self
[src]
pub fn new() -> Self
[src]Creates a new empty arena.
Example
use dcc_lsystem::Arena; let mut arena = Arena::new(); arena.push(1); arena.push(3);
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
[src]Returns the length of this arena.
Example
use dcc_lsystem::Arena; let mut arena = Arena::new(); for i in 0..420 { arena.push(i); } assert_eq!(arena.len(), 420);
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
[src]Returns true
if the arena contains no elements.
Example
use dcc_lsystem::Arena; let mut arena = Arena::new(); assert!(arena.is_empty()); arena.push(3); assert!(!arena.is_empty());
pub fn get(&self, id: ArenaId) -> Option<&T>
[src]
pub fn get(&self, id: ArenaId) -> Option<&T>
[src]Returns a reference to an entry of the arena, if the provided ArenaId is valid.
Example
use dcc_lsystem::Arena; let mut arena = Arena::new(); let x = arena.push("x"); let y = arena.push("y"); let z = arena.push("z"); assert_eq!(arena.get(y), Some(&"y"));
pub fn get_mut(&mut self, id: ArenaId) -> Option<&mut T>
[src]
pub fn get_mut(&mut self, id: ArenaId) -> Option<&mut T>
[src]Returns a mutable reference to the entry corresponding to the given index.
Example
use dcc_lsystem::Arena; let mut arena = Arena::new(); let x = arena.push("x"); if let Some(entry) = arena.get_mut(x) { *entry = "y"; } assert_eq!(arena.get(x), Some(&"y"));
pub fn iter(&self) -> Iter<'_, T>
[src]
pub fn iter(&self) -> Iter<'_, T>
[src]Returns an iterator over this arena.
Example
use dcc_lsystem::Arena; let mut arena = Arena::new(); let x = arena.push(3); let y = arena.push(5); let mut iterator = arena.iter(); assert_eq!(iterator.next(), Some(&3)); assert_eq!(iterator.next(), Some(&5)); assert_eq!(iterator.next(), None)
pub fn iter_mut(&mut self) -> IterMut<'_, T>
[src]
pub fn iter_mut(&mut self) -> IterMut<'_, T>
[src]Returns an iterator that allows modifying each value.
Example
use dcc_lsystem::Arena; let mut arena = Arena::new(); let x = arena.push(3); let y = arena.push(-4); for entry in arena.iter_mut() { *entry = *entry * *entry; } let mut iterator = arena.iter(); assert_eq!(iterator.next(), Some(&9)); assert_eq!(iterator.next(), Some(&16));
pub fn is_valid(&self, id: ArenaId) -> bool
[src]
pub fn is_valid(&self, id: ArenaId) -> bool
[src]Returns true if the provided id corresponds to an element of this arena.
use dcc_lsystem::{Arena, ArenaId}; let mut arena = Arena::new(); let x = arena.push(17); let y = arena.push(21); assert!(arena.is_valid(x)); assert!(arena.is_valid(y)); assert!(!arena.is_valid(ArenaId(2)));
pub fn is_valid_slice(&self, slice: &[ArenaId]) -> bool
[src]
pub fn is_valid_slice(&self, slice: &[ArenaId]) -> bool
[src]Returns true
if the every id in the provided slice is valid.
Example
use dcc_lsystem::{Arena, ArenaId}; let mut arena = Arena::new(); let x = arena.push(1); let y = arena.push(3); let z = arena.push(7); assert!(arena.is_valid_slice(&[x,y])); assert!(arena.is_valid_slice(&[x,y,z])); assert!(!arena.is_valid_slice(&[x,y,ArenaId(3)]));
pub fn push(&mut self, value: T) -> ArenaId
[src]
pub fn push(&mut self, value: T) -> ArenaId
[src]Add a new value to our arena.
Returns an ArenaId which uniquely identifies this element of the arena.
Example
use dcc_lsystem::Arena;
let mut arena = Arena::new(); let x = arena.push(11); let y = arena.push(-3);
assert_eq!(x, ArenaId(0)); assert_eq!(y, ArenaId(1));
pub fn enumerate(&self) -> EnumerableArena<'_, T>ⓘNotable traits for EnumerableArena<'a, T>
impl<'a, T> Iterator for EnumerableArena<'a, T> type Item = (ArenaId, &'a T);
[src]
pub fn enumerate(&self) -> EnumerableArena<'_, T>ⓘNotable traits for EnumerableArena<'a, T>
impl<'a, T> Iterator for EnumerableArena<'a, T> type Item = (ArenaId, &'a T);
[src]Returns an EnumerableArena.
Example
use dcc_lsystem::Arena; let mut arena = Arena::new(); let x = arena.push(3); let y = arena.push(5); let z = arena.push(-7); for (id, entry) in arena.enumerate() { /* do some work here */ }
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Arena<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Arena<T> where
T: Send,
T: Send,
impl<T> Sync for Arena<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Arena<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Arena<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
Scheme: ApproxScheme,
type Err = NoError
type Err = NoError
The error type produced by a failed conversion.
pub fn approx_from(
src: Src
) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
pub fn approx_from(
src: Src
) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
Convert the given value into an approximately equivalent representation.
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
The error type produced by a failed conversion.
pub fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
pub fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Convert the subject into an approximately equivalent representation.
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ConvUtil for T
impl<T> ConvUtil for T
fn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
Approximate the subject to a given type with the default scheme.
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
Approximate the subject to a given type with a specific scheme.
impl<T> Pointable for T
impl<T> Pointable for T
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<Src> ValueFrom<Src> for Src
impl<Src> ValueFrom<Src> for Src
type Err = NoError
type Err = NoError
The error type produced by a failed conversion.
pub fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>
pub fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>
Convert the given value into an exactly equivalent representation.
impl<Src, Dst> ValueInto<Dst> for Src where
Dst: ValueFrom<Src>,
impl<Src, Dst> ValueInto<Dst> for Src where
Dst: ValueFrom<Src>,
type Err = <Dst as ValueFrom<Src>>::Err
type Err = <Dst as ValueFrom<Src>>::Err
The error type produced by a failed conversion.
pub fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>
pub fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>
Convert the subject into an exactly equivalent representation.