[][src]Struct dcc_lsystem::arena::Arena

pub struct Arena<T> { /* fields omitted */ }

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

Methods

impl<T> Arena<T>[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]

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]

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]

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]

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]

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]

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]

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]

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]

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

Important traits for EnumerableArena<'a, T>
pub fn enumerate(&self) -> EnumerableArena<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 */
}

impl Arena<Token>[src]

pub fn render(&self, tokens: &[ArenaId]) -> String[src]

Returns a string representation of the given slice of ArenaId's in terms of the contents of this arena.

Trait Implementations

impl<T: Clone> Clone for Arena<T>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<T> Default for Arena<T>[src]

impl<T: Debug> Debug for Arena<T>[src]

Auto Trait Implementations

impl<T> Unpin for Arena<T> where
    T: Unpin

impl<T> Sync for Arena<T> where
    T: Sync

impl<T> Send for Arena<T> where
    T: Send

impl<T> UnwindSafe for Arena<T> where
    T: UnwindSafe

impl<T> RefUnwindSafe for Arena<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> SetParameter for T

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 

Sets value as a parameter of self.

impl<Src, Dst> ValueInto<Dst> for Src where
    Dst: ValueFrom<Src>, 

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.

impl<Src> ValueFrom<Src> for Src

type Err = NoError

The error type produced by a failed conversion.

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
    Dst: ApproxFrom<Src, Scheme>,
    Scheme: ApproxScheme, 

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.

impl<T, Dst> ConvAsUtil<Dst> for T

fn approx(self) -> Result<Dst, Self::Err> where
    Self: ApproxInto<Dst, DefaultApprox>, 

Approximate the subject with the default scheme.

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err> where
    Scheme: ApproxScheme,
    Self: ApproxInto<Dst, Scheme>, 

Approximate the subject with a specific scheme.

impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
    Scheme: ApproxScheme, 

type Err = NoError

The error type produced by a failed conversion.

impl<T> ConvUtil for T

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
    Scheme: ApproxScheme,
    Self: ApproxInto<Dst, Scheme>, 

Approximate the subject to a given type with a specific scheme.

fn into_as<Dst>(self) -> Dst where
    Self: Into<Dst>, 

Convert the subject to a given type.

fn try_as<Dst>(self) -> Result<Dst, Self::Err> where
    Self: TryInto<Dst>, 

Attempt to convert the subject to a given type.

fn value_as<Dst>(self) -> Result<Dst, Self::Err> where
    Self: ValueInto<Dst>, 

Attempt a value conversion of the subject to a given type.

impl<Src> TryFrom<Src> for Src

type Err = NoError

The error type produced by a failed conversion.

impl<Src, Dst> TryInto<Dst> for Src where
    Dst: TryFrom<Src>, 

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.